Created
October 3, 2015 03:16
-
-
Save Deathnerd/77f407bacf7bd4ca8d2a 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
@Override | |
public void run() { | |
while (true) { | |
ArrayList<String> menu_choices = new ArrayList<String>() {{ | |
add("Read"); | |
add("Generate"); | |
add("Print"); | |
add("Sort"); | |
add("Search"); | |
}}; | |
// Get the numeric choice, -1 if exit | |
int choice = menu_choices.indexOf(Menu.displayS(menu_choices)); | |
if (choice >= 0) { | |
try { | |
// because I'm lazy and don't feel like cluttering my code. We'll | |
// dynamically call the method | |
Object ret = this.getClass().getMethod(menu_choices.get(choice).toLowerCase()).invoke(this); | |
} catch (NoSuchMethodException e) { | |
System.out.println("I'm afraid I can't do that, Dave... Check the logs"); | |
log.log(Level.FINE, "Attempted to call an undefined method of " + choice, e.toString()); | |
} catch (InvocationTargetException e) { | |
System.out.println("I'm afraid I can't do that, Dave... Check the logs"); | |
log.log(Level.FINE, "Invocation target exception. Failed to invoke method " + choice, e.toString()); | |
} catch (IllegalAccessException e) { | |
System.out.println("I'm afraid I can't do that, Dave... Check the logs"); | |
log.log(Level.FINE, "Illegal access exception. Failed to access method " + choice, e.toString()); | |
} | |
} else { | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment