For instance, for the example defined below, only what you need to do in your code is -> if (operation.isCount()) {...} instead of if (operations.equals(Operation.COUNTA)) {...}
Check this post on Medium.com -> Use enum utility methods in Java ! Avoid equals at all costs!
import org.apache.commons.lang3.EnumUtils; public enum Operation { COUNTA, SUM,
NA; public static Operation parse(String input) { Operation operation = EnumUtils.getEnum(Operation.class, input); if (operation == null) { return NA; } return operation; } public boolean isCount() { return this == COUNTA; } public boolean isSum() { return this == SUM; } public boolean isCountOrSum() { return this == COUNTA || this == SUM; } }
No comments:
Post a Comment