Menu

#2 Make "Command" class comparable

open
nobody
5
2011-12-07
2011-12-07
No

As I wanted my commands to be sorted when printed with the "HelpCommand" I made the Command class comperable.

public class Command implements Comparable<Command> {
@Override
public int compareTo(Command cmd) {
return getSyntax().getDefinition().compareTo(cmd.getSyntax().getDefinition());
}
}

After that you can put your commands into a TreeSet which is sorted by default.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB