How about you make an abstract Command class and use a map to retrieve the correct command, for example:
abstract class Command<T>
{
public static final Map<String, Command> commands = new HashMap<>();
public Command(final String executeCommand)
{
commands.put(executeCommand, this);
}
public abstract T execute();
}
Then implemented with:
class LocationCommand extends Command<LocationValue>
{
public LocationCommand()
{
super("GET GPS LOCATION");
}
@Override
public LocationValue execute()
{
System.out.println("Getting GPS location");
return null;
}
}
Then you could retrieve them like so:
public static void main(String[] args)
{
new LocationCommand();
Command.commands.get("GET GPS LOCATION").execute(); //Output: Getting GPS location
}