Helper Functions #2: "has"

Discussion in 'Resources' started by pzxc, Jul 18, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    pzxc

    In the spirit of trying to make everyone (including myself) a better programmer, I'm gonna post some helper functions that I find myself using over and over to save time, screen space, and complexity.

    Here's the second one: has

    Code:
    private boolean has(String[] args, int index, String s) { if (args.length >= index + 1) return args[index].equalsIgnoreCase(s); return false; }
    With this you don't have to worry about the length of your args. You can just check it.
    For example:
    if (has(args, 0, "test")) player.sendMessage("Parameter one was 'test'!");
    if (has(args, 1, "delete")) player.sendMessage("Parameter two was 'delete'!");
     
  2. wrong topic, post it at the resource section
     
  3. Offline

    TnT

    Moved to the correct forum.
     
Thread Status:
Not open for further replies.

Share This Page