Thread: Enum ranks

Page 1 of 5 123 ... LastLast
Results 1 to 10 of 46
  1. #1 Enum ranks 
    Super Donator

    StanDev's Avatar
    Join Date
    Apr 2014
    Posts
    660
    Thanks given
    82
    Thanks received
    255
    Rep Power
    592
    Code:
    public class main {
     
      public static void main(String[] args){// MAIN METHOD, to test the code 
       for (ranks Ranks : ranks.values()) // ENHANCED FOR LOOP, loops through the enum values
         System.out.printf("%s\n	%d	%b\n", Ranks, Ranks.getRights(), Ranks.getDonator()); // Prints out a string (%s), int (%d), boolean(%b)
      }
    }
    
    enum ranks {
      //NAME RANK, PLAYERRIGHTS, ISDONATOR
      player(0, false),
      moderator(1, false),
      administrator(2, false),
      owner(3, true),
      donator(4, true);
      
      private int playerRights;
      private boolean isDonator;
      
      private ranks (int rights, boolean isDon){
        rights = playerRights;
        isDon = isDonator;
      }
      
      public int getRights(){
        return playerRights;// RETURNS value of playerRights
      }
      
      public boolean getDonator(){
        return isDonator;// RETURNS value of isDonator
      }
    }
    I was pretty bored on my vacation so I quickly wrote this for someone who might need it , the main class is just for testing purposes and to see how to call the enum values etc...
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Apr 2009
    Posts
    1,727
    Thanks given
    403
    Thanks received
    210
    Rep Power
    390
    Having a boolean that denotes donator is rather redundant it seems.

    Code:
    public boolean isDonator(Rank rank) {
    return rank == Rank.DONATOR;
    }
    Also following conventions, constants should be all caps as well as classes should be capitalized and singular(so ranks would be Rank).
    Reply With Quote  
     

  3. #3  
    Super Donator

    StanDev's Avatar
    Join Date
    Apr 2014
    Posts
    660
    Thanks given
    82
    Thanks received
    255
    Rep Power
    592
    Quote Originally Posted by Phat 4 u View Post
    Having a boolean that denotes donator is rather redundant it seems.

    Code:
    public boolean isDonator(Rank rank) {
    return rank == Rank.DONATOR;
    }
    Also following conventions, constants should be all caps as well as classes should be capitalized and singular(so ranks would be Rank).
    Didn't follow the conventions iknow shame on me but about the isdonator part, I wrote this based on pi and thought this would be more ordening but you would run into problems when you have multipile donator ranks doing it this way. Could you elaborate a bit more on what you did?

    Edit: nvm I see now but that would also result in trouble when you have multipile donator ranks.
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Apr 2009
    Posts
    1,727
    Thanks given
    403
    Thanks received
    210
    Rep Power
    390
    Quote Originally Posted by icebrick View Post
    Didn't follow the conventions iknow shame on me but about the isdonator part, I wrote this based on pi and thought this would be more ordening but you would run into problems when you have multipile donator ranks doing it this way. Could you elaborate a bit more on what you did?

    Edit: nvm I see now but that would also result in trouble when you have multipile donator ranks.
    You could just add more returns for each rank that is a donator. Personally I would do it this way to keep the Enum clearer and more readable. I am sure there are better ways to do it however.

    Code:
    public boolean isDonator(Rank rank) {
    return rank == Rank.DONATOR || rank == Rank.SUPER_DONATOR;
    }
    Reply With Quote  
     

  5. #5  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by Phat 4 u View Post
    You could just add more returns for each rank that is a donator. Personally I would do it this way to keep the Enum clearer and more readable. I am sure there are better ways to do it however.

    Code:
    public boolean isDonator(Rank rank) {
    return rank == Rank.DONATOR || rank == Rank.SUPER_DONATOR;
    }
    Even more redundant, why not just;

    Code:
    public boolean isDonator() {
        return this == Rank.DONATOR;
    }
    Reply With Quote  
     

  6. #6  
    Registered Member

    Join Date
    Apr 2009
    Posts
    1,727
    Thanks given
    403
    Thanks received
    210
    Rep Power
    390
    Quote Originally Posted by Jason View Post
    Even more redundant, why not just;

    Code:
    public boolean isDonator() {
        return this == Rank.DONATOR;
    }
    Yeah your right haha, for some reason I forgot that this method is inside the enum.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Dec 2013
    Posts
    85
    Thanks given
    0
    Thanks received
    36
    Rep Power
    59
    this is just fucking awful. bad naming conventions, completely retarded enum - why in the ever loving fuck does donator have higher rights than an owner? pointless isDonor boolean field. just completely illogical. also impossible to have more than one rank with this piece of shit. i will say this very kindly: rewrite this NOW.
    Reply With Quote  
     

  8. #8  
    Enum ranks



    Scu11's Avatar
    Join Date
    Aug 2007
    Age
    30
    Posts
    16,307
    Thanks given
    7,215
    Thanks received
    12,308
    Rep Power
    5000
    Please learn to follow simple Java conventions

    Attached image
    Reply With Quote  
     

  9. Thankful users:


  10. #9  
    Super Donator

    StanDev's Avatar
    Join Date
    Apr 2014
    Posts
    660
    Thanks given
    82
    Thanks received
    255
    Rep Power
    592
    Quote Originally Posted by FullyCharged View Post
    this is just fucking awful. bad naming conventions, completely retarded enum - why in the ever loving fuck does donator have higher rights than an owner? pointless isDonor boolean field. just completely illogical. also impossible to have more than one rank with this piece of shit. i will say this very kindly: rewrite this NOW.
    Wow dude no need to take it so hard, you could've said this in like tons of different ways but some people in this community have to be such immature childs acting like a dick whenever they get the chance and I know this is bad lol but it was written for someone who uses pi and he needed the ranks in an enum quickly and I decided maybe someone could save some time by using this as like something to quickly refer to. And if you know pi then you'll know that donator have higher rights than admins and idk why the fuck that is and isdonator is also used in pi. So no need to act like that man like what's your problem

    - - - Updated - - -

    Quote Originally Posted by Scu11 View Post
    Please learn to follow simple Java conventions
    Iknow... Wrote this on my ipad very quickly will do in future works released, like in the polymorphism thing
    Reply With Quote  
     

  11. Thankful user:


  12. #10  
    Registered Member

    Join Date
    Nov 2014
    Posts
    253
    Thanks given
    39
    Thanks received
    146
    Rep Power
    248
    This would be a brilliant way to do it if you like making your life more difficult..... You don't even include the ability to have more than one rank (I mean you could even have a list of ranks, optimally you'd flip bits to change ranks

    then for isDonator just: Rank#hasAbility(Rank.DONATOR)
    Reply With Quote  
     

Page 1 of 5 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Yell Colo/Rank. Enums.
    By Poolside Queer in forum Snippets
    Replies: 2
    Last Post: 07-10-2013, 05:42 PM
  2. ~Halo 3 Ranks~
    By Codyxx in forum Console
    Replies: 40
    Last Post: 04-17-2008, 06:54 PM
  3. Can I Have a GFX Rank?
    By Winterworks in forum General
    Replies: 8
    Last Post: 01-13-2008, 08:02 PM
  4. Fixing crown for Rank 3 users
    By Gander in forum Tutorials
    Replies: 5
    Last Post: 10-06-2007, 10:59 AM
  5. How to give ranks- the command
    By booher in forum Tutorials
    Replies: 12
    Last Post: 08-17-2007, 01:35 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •