-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Menu Input Scanner #5
base: master
Are you sure you want to change the base?
Conversation
@tnbahia Sorry for the delayed review 😅 |
Wow, completely forgot about this |
|
||
public CustomMenuInputScanner(Map<Integer,String> optionMap) { | ||
super(optionMap.keySet()); | ||
this.optionMap = new TreeMap<>(optionMap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fully customizable, I think it would be nice to let the user also decide the order by which the menuOptions are shown. By using a TreeMap
you are forcing the options to appear by ascending order. If you use a LinkedHashMap
for instance, you could let the presentation order to be decided when the optionMap is actually created, and assure that the order is maintained.
Map<Integer,String> options = new HashMap<>(); | ||
options.put(5,"Bahia"); | ||
options.put(30,"João"); | ||
options.put(2,"Tiago"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the previous comment, if you wanted to assure that the menu would show the options with ascending order, you could use a TreeMap
here. If you wanted to keep the order you're adding the options, you could use a LinkedHashMap
. Either way would work with this implementation.
Created a new Custom Menu Input Scanner. This scanner is different from the MenuInputScanner in the sense that you can now choose what numbers appear as options.
This came from the need to have a menu that would display the options not as the standard 1 to n, but as a set of pre-determined numbers. For example, to ask a customer to which of his accounts he wants to perform an action. The account numbers will probably be some numbers that are not sequencial.