Last active
November 17, 2015 15:15
-
-
Save pablisco/8afae34b853248513801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Command { | |
void do(); | |
// getters | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class CommandImpl implements Command { | |
public CommandImpl(Object value1, Object value2) { | |
// save values to object | |
} | |
// getters | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Commands { | |
public static final int VALUE1 = 0; | |
public static final int VALUE2 = 1; | |
public static final int VALUE3 = 2; | |
@Retention(SOURCE) | |
@IntDef({VALUE1, VALUE2, VALUE3}) | |
public @interface CommandValue {} | |
private static final SparseArray map = new SparseArray(); | |
static { | |
map.put(VALUE1, new CommandImpl("something", "Other") { | |
public void do() { | |
// do something | |
} | |
}); | |
// etc for values | |
} | |
public static Command commandFor(@CommandValue int valueRef) { | |
return map.get(valueRef); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment