Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tnbahia
Copy link

@tnbahia tnbahia commented Mar 20, 2019

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.

@jfstn jfstn requested a review from p-brighenti October 24, 2019 10:38
@ferrao ferrao requested review from audreylopes and removed request for p-brighenti February 22, 2021 18:53
@audreylopes
Copy link
Member

@tnbahia Sorry for the delayed review 😅
I think it's a nice feature to add to our prompt-view library. I'll leave some comments on your code.

@tnbahia
Copy link
Author

tnbahia commented Mar 12, 2021

Wow, completely forgot about this


public CustomMenuInputScanner(Map<Integer,String> optionMap) {
super(optionMap.keySet());
this.optionMap = new TreeMap<>(optionMap);
Copy link
Member

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.

Comment on lines +13 to +16
Map<Integer,String> options = new HashMap<>();
options.put(5,"Bahia");
options.put(30,"João");
options.put(2,"Tiago");
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants