daily pastebin goal
80%
SHARE
TWEET

Untitled

a guest May 17th, 2018 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2.  
  3. class Commands {
  4.   public static final Map<String,Runnable> lookup = Collections.unmodifiableMap(new HashMap<String,Runnable>(){{
  5.    put("quit", new Runnable() { @Override public void run() { quit(); } });
  6.    put("calc", new Runnable() { @Override public void run() { calc(); } });
  7.    put("foo",  new Runnable() { @Override public void run() { foo();  } });
  8.   }});
  9. }
  10.  
  11. //Usage
  12.  
  13. final Commands c = new Commands();
  14. final Runnable cmd = c.lookup(argument);
  15. if(cmd != null) cmd.run();
  16. else sendMessageToUserThatArgumentDoesntExist
RAW Paste Data
Top