Thread: Commands as an enum

Page 1 of 7 123 ... LastLast
Results 1 to 10 of 64
  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. #2  
    Registered Member
    Thrallix's Avatar
    Join Date
    Nov 2014
    Posts
    613
    Thanks given
    180
    Thanks received
    154
    Rep Power
    143
    Looks better than PI
    Reply With Quote  
     

  3. #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  
     

  4. #4  
    Registered Member
    Thrallix's Avatar
    Join Date
    Nov 2014
    Posts
    613
    Thanks given
    180
    Thanks received
    154
    Rep Power
    143
    Quote Originally Posted by CodeForScape View Post
    I’ve never been a fan of the big ‘if else’ command.startsWith trees!
    Switch
    Reply With Quote  
     

  5. #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  
     

  6. #6  
    Registered Member
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    997
    Thanks given
    161
    Thanks received
    446
    Rep Power
    718
    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  
     


  7. #7  
    Registered Member
    Thrallix's Avatar
    Join Date
    Nov 2014
    Posts
    613
    Thanks given
    180
    Thanks received
    154
    Rep Power
    143
    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
    Reply With Quote  
     

  8. #8  
    Registered Member
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    997
    Thanks given
    161
    Thanks received
    446
    Rep Power
    718
    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  
     


  9. #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  
     

  10. #10  
    Forum Moderator


    Join Date
    Jan 2009
    Posts
    5,626
    Thanks given
    1,059
    Thanks received
    3,328
    Rep Power
    5000
    this is misuse of enums at its best
    Reply With Quote  
     


Page 1 of 7 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
  •