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 6346169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:57:59+00:00 2026-05-24T20:57:59+00:00

Let’s say I created the following class: public enum Position { Dealer(1), //1 SB(2),

  • 0

Let’s say I created the following class:

public enum Position {

   Dealer(1), //1
   SB(2),     //2
   BB(3),     //3
   UTG(4),    //4
   UTG1(5),   //5
   UTG2(6),   //6
   UTG3(7),   //7
   HJ(8),     //8
   CO(9);     //9

   //Constructor
   int code;

   Position(int code) {
     this.code = code;
   }
}

How do I manipulate ENUM by using the numbers in parenthesis?
For example, in my Poker Table class, I initiate new players. Each player passes the parameter Position.
So initially,

player[1].getPosition() = Dealer  
player[2].getPosition() = SB  
player[3].getPosition() = BB   
etc etc etc 

After the hand is over, all the positions need to be shifted over by one.
So player[1] needs to have the CO(9) position.
player[2] needs to have the Dealer(1) position.
player[3] needs to have the SB(2) position.
etc etc

I understand that I can just make a for loop with a variable cycling through the numbers 1 through 9, but how do I access the position based on the integer inside the PositionENUM?


EDIT:
I already have the getters and setters.

    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }

However the getters and the setters do not provide me with the correctly change the Positions of the players each round.

After every betting round, I need to change the Position of each player, so I need to figure out how to shift the ENUM Position of each player after each betting round.

  • 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-24T20:57:59+00:00Added an answer on May 24, 2026 at 8:57 pm

    It’s possible to choose an enum instance based on the value of its code. You can use a static Map<Integer, Position> to do this. The only gotcha is that it has to be housed in a static inner class:

    public enum Position {
    
        ...
    
        Position(int code) {
            this.code = code;
            MapHolder.BY_CODE.put(code, this);
        }
    
        private static class MapHolder {
            private static final Map<Integer, Position> BY_CODE = new HashMap<Integer, Position>();
        }
    
        public static Position findByCode(int code) {
            return MapHolder.BY_CODE.get(code);
        }
    

    I’d also recommend delegating the logic of picking the next position to the enum itself. Just add this method to the Position enum:

    public Position nextPosition() {
         return findByCode((this.code + 1) % Position.values().length);
    }
    

    Then, your client code can simply go:

    for (Player player : players) {
        player.setPosition(player.getPosition().nextPosition());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say i have a mysql database table 'article' with the following fields: id
Let's imagine I have a Java class of the type: public class MyClass {
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let say I have the following desire, to simplify the IConvertible's to allow me
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a

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.