java - enum value for given arguments -
is there esthetic way of retrieving enum value based on 2 other enum types? i'd state 2 enum arguments next example:
public enum state{ one_state, second_state; third_state; public static state getstate(direction dir, type type) { if (dir.equals(direction.left) && type.equals(type.big)) { homecoming one_state; } else if (dir.equals(direction.right) && type.equals(type.small)) { homecoming second_state; } else if (dir.equals(direction.up) && type.equals(type.small)) { homecoming first_state; } homecoming third_state; } }
of course of study word intention create clearer since number of such possibilities grow in time.
why not utilize lookup table ? array of rows - each row containing 2 inputs , 1 output.
left, big, one_state right, small, second_state
etc. , provide method , homecoming default if lookup fails.
failing that, investigate double dispatch
java enums
No comments:
Post a Comment