Thread: Commands as an enum

Page 1 of 5 123 ... LastLast
Results 1 to 10 of 50
  1. #1 Commands as an enum 
    Registered Member
    Join Date
    Apr 2018
    Posts
    82
    Thanks given
    27
    Thanks received
    9
    Rep Power
    46
    DISCLAIMER: I capitalise my methods. I know. I’m sorry.

    I converted my commands into an enum



    I suppose the only real benefits are it looks quite nice and I can query my commands, so I could return a list of donator commands to display etc
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Registered Member
    Thrallix's Avatar
    Join Date
    Nov 2014
    Posts
    606
    Thanks given
    174
    Thanks received
    152
    Rep Power
    142
    Looks better than PI
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #3  
    Registered Member
    Join Date
    Apr 2018
    Posts
    82
    Thanks given
    27
    Thanks received
    9
    Rep Power
    46
    Quote Originally Posted by Thrallix View Post
    Looks better than PI
    I’ve never been a fan of the big ‘if else’ command.startsWith trees!
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #4  
    Registered Member
    Thrallix's Avatar
    Join Date
    Nov 2014
    Posts
    606
    Thanks given
    174
    Thanks received
    152
    Rep Power
    142
    Quote Originally Posted by CodeForScape View Post
    I’ve never been a fan of the big ‘if else’ command.startsWith trees!
    Switch
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #5  
    Registered Member
    Join Date
    Apr 2018
    Posts
    82
    Thanks given
    27
    Thanks received
    9
    Rep Power
    46
    Quote Originally Posted by Thrallix View Post
    Switch
    Using OSRS PK source, I did convert the big if else trees to switch, but decided an enum would be nice :-).
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #6  
    Registered Member
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    918
    Thanks given
    148
    Thanks received
    341
    Rep Power
    638
    All hail the might regex

    Code:
    Pattern pattern = Pattern.compile("^(?:tele|tp)\s(\d+)(?:,|\s|,\s|\s,)(\d+)(?:(?:,|\s|,\s|\s,)(\d+))?$");
    Accepts all tele formats:

    ::tele 3200 3200
    ::tp 3200, 3200,1
    Reply With Quote  
     


  8. #7  
    Registered Member
    Thrallix's Avatar
    Join Date
    Nov 2014
    Posts
    606
    Thanks given
    174
    Thanks received
    152
    Rep Power
    142
    Quote Originally Posted by Greg View Post
    All hail the might regex

    Code:
    Pattern pattern = Pattern.compile("^(?:tele|tp)\s(\d+)(?:,|\s|,\s|\s,)(\d+)(?:(?:,|\s|,\s|\s,)(\d+))?$");
    Accepts all tele formats:

    ::tele 3200 3200
    ::tp 3200, 3200,1
    I dont think i will ever understand regex
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  9. #8  
    Registered Member
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    918
    Thanks given
    148
    Thanks received
    341
    Rep Power
    638
    Quote Originally Posted by Thrallix View Post
    I dont think i will ever understand regex
    ^ start
    (?: ) non-capturing brackets aka group
    | or
    \s space
    \d digit
    \d+ multiple digits aka number
    ? optional
    $ end

    Code:
    ^(?:tele|tp)
    is essentially

    Code:
    if(string.startsWith("tele") || string.startsWith("tp"))
    Code:
    (\d+)
    Captures the first number aka x cord

    Code:
    (?:,|\s|,\s|\s,)
    matches a comma or a space, or a comma and space, or a space and a comma

    Code:
    (\d+)
    capture the y cordinate

    Code:
    (?:(?:,|\s|,\s|\s,)(\d+))?
    Then the last one is same again but wrapped in (?: )? which is an optional group so z cord

    $
    end of line

    Definitely worth an hour or two to learn and making them is easy with [Only registered and activated users can see links. ]
    Reply With Quote  
     


  10. #9  
    Registered Member
    Join Date
    Apr 2018
    Posts
    82
    Thanks given
    27
    Thanks received
    9
    Rep Power
    46
    Quote Originally Posted by Greg View Post
    All hail the might regex

    Code:
    Pattern pattern = Pattern.compile("^(?:tele|tp)\s(\d+)(?:,|\s|,\s|\s,)(\d+)(?:(?:,|\s|,\s|\s,)(\d+))?$");
    Accepts all tele formats:

    ::tele 3200 3200
    ::tp 3200, 3200,1
    Quote Originally Posted by Greg View Post
    ^ start
    (?: ) non-capturing brackets aka group
    | or
    \s space
    \d digit
    \d+ multiple digits aka number
    ? optional
    $ end

    Code:
    ^(?:tele|tp)
    is essentially

    Code:
    if(string.startsWith("tele") || string.startsWith("tp"))
    Code:
    (\d+)
    Captures the first number aka x cord

    Code:
    (?:,|\s|,\s|\s,)
    matches a comma or a space, or a comma and space, or a space and a comma

    Code:
    (\d+)
    capture the y cordinate

    Code:
    (?:(?:,|\s|,\s|\s,)(\d+))?
    Then the last one is same again but wrapped in (?: )? which is an optional group so z cord

    $
    end of line

    Definitely worth an hour or two to learn and making them is easy with [Only registered and activated users can see links. ]
    Do you use regex a lot? Could you give some examples of common use cases? I’ve only ever used regex for things like validating a postcode etc
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  11. #10  
    Forum Moderator


    Join Date
    Jan 2009
    Posts
    5,607
    Thanks given
    1,057
    Thanks received
    3,317
    Rep Power
    5000
    this is misuse of enums at its best
    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)

Similar Threads

  1. Replies: 6
    Last Post: 08-12-2011, 03:41 AM
  2. Replies: 1
    Last Post: 01-15-2011, 01:05 AM
  3. Replies: 12
    Last Post: 10-31-2010, 10:22 PM
  4. Replies: 1
    Last Post: 04-27-2010, 01:34 AM
  5. Replies: 10
    Last Post: 05-31-2009, 01:42 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •