Skip to content

Instantly share code, notes, and snippets.

@suhtai
Last active November 17, 2015 15:15
Show Gist options
  • Select an option

  • Save suhtai/8afae34b853248513801 to your computer and use it in GitHub Desktop.

Select an option

Save suhtai/8afae34b853248513801 to your computer and use it in GitHub Desktop.
public interface Command {
void do();
// getters
}
abstract class CommandImpl implements Command {
public CommandImpl(Object value1, Object value2) {
// save values to object
}
// getters
}
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