Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7401713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:32:45+00:00 2026-05-29T04:32:45+00:00

Now this might sound simple, but I’m a bit mixed up. I am trying

  • 0

Now this might sound simple, but I’m a bit mixed up. I am trying to create a menu in my application. Depending on certain conditions, some options of the menu will be enabled/disabled. Since it is console-based, I also want to specify for each “state” of the menu which commands are available to the user.

Example :

EMPTY_STATE has ADD_COMMAND, REMOVE_COMMAND, QUIT_COMMAND
FULL_STATE has ADD_COMMAND, VIEW_COMMAND, REMOVE_COMMAND, QUIT_COMMAND

I’d like my application to be as flexible as possible meaning that I can easily add more states and customize the commands that can be used. That means I would like to avoid doing columns of if’s to know that is the action taken.

Since each state has different commands, I thought of creating an ENUM named State which countains those different states. I also created an ENUM called Commands which contains all of the possible commands the user could do while using my application.

My basic idea was simply :

EMPTY_STATE(Commands.ADD_COMMAND,Commands.REMOVE_COMMAND,Commands.QUIT_COMMAND)

Thus, State countains Commands, and Commands countains their label, which is a string of the command prefix (“-add”)

But then, States can countain many commands and that is the problem. Since I can’t and do not want to do a constructor for each case in the ENUM, I thought about using an ArrayList that would countain all the commands, making it :

EMPTY_STATE(Arraylist array = commands) <-- Just the idea

And that is where my question goes in. As the documentation say, an arraylist can take a collection in parameter to assign its intern content.

Could I have some suggestion of how I should structure this to make it clean and easy to manage ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:32:46+00:00Added an answer on May 29, 2026 at 4:32 am

    What’s wrong with storing the available commands for each state?
    After all, you will have to define this somewhere.

    You can pass an EnumSet of the available commands to the constructor for each State enum like this:

    SOME_STATE( EnumSet.of(Command.A, Command.B)),
    OTHER_STATE( EnumSet.of(Command.A, Command.C))
    ...
    

    As an alternative, you could specify for each command in which state it will be available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, this might sound stupid and noob but right now in my js, I
this question might sound a little bit weired... But I will try to explain:
Okay this might sound simple but there's a catch. I'll try and explain the
I might sound incredible what I'm experiencing right now but I have this code
This might sound minor, but it's been driving me nuts. Since releasing an application
This might sound a bit confusing at first. But I have a table with
This might sound a little stupid but I am still curious about what the
HI, this might sound like a silly question but.. i've created several types in
Um, this might sound a bit weird. We were having some problems with a
I know this might sound silly but I have no idea how to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.