File Source: CoreActionComparison.java

         /* 
    P/P   *  Method: com.dmdirc.actions.CoreActionComparison$1__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.actions;
    24  
    25  import com.dmdirc.actions.interfaces.ActionComparison;
    26  import com.dmdirc.ui.messages.ColourManager;
    27  
    28  import java.awt.Color;
    29  import java.util.regex.PatternSyntaxException;
    30  
    31  /**
    32   * A CoreActionComparison represents a possible comparison between two types of
    33   * data used in an action condition.
    34   * @author chris
    35   */
         /* 
    P/P   *  Method: void com.dmdirc.actions.CoreActionComparison(String, int, CoreActionComparison$1)
          */
    36  public enum CoreActionComparison implements ActionComparison {
    37      
    38      /** Compares a string to another using a regular expression. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$1(String, int)
              */
    39      STRING_REGEX {
    40          /** {@inheritDoc} */
    41          @Override
    42          public boolean test(final Object arg1, final Object arg2) {
    43              try {
                         /* 
    P/P                   *  Method: bool test(Object, Object)
                          * 
                          *  Preconditions:
                          *    (soft) arg1 != null
                          * 
                          *  Postconditions:
                          *    init'ed(return_value)
                          */
    44                  return ((String) arg1).matches((String) arg2);
    45              } catch (PatternSyntaxException pse) {
    46                  return false;
    47              }
    48          }
    49          /** {@inheritDoc} */
    50          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
    51          public Class appliesTo() { return String.class; }
    52          /** {@inheritDoc} */
    53          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"matches regex"
                  */
    54          public String getName() { return "matches regex"; }
    55      },
    56      
    57      /** Compares if two strings content are the same, case insensitive. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$2(String, int)
              */
    58      STRING_EQUALS {
    59          /** {@inheritDoc} */
    60          @Override
    61          public boolean test(final Object arg1, final Object arg2) {
                     /* 
    P/P               *  Method: bool test(Object, Object)
                      * 
                      *  Preconditions:
                      *    arg1 != null
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      */
    62              return ((String) arg1).equalsIgnoreCase((String) arg2);
    63          }
    64          /** {@inheritDoc} */
    65          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
    66          public Class appliesTo() { return String.class; }
    67          /** {@inheritDoc} */
    68          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"equals"
                  */
    69          public String getName() { return "equals"; }
    70      },
    71      
    72      /** Compares if two strings content aren't the same, case insensitive. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$3(String, int)
              */
    73      STRING_NEQUALS {
    74          /** {@inheritDoc} */
    75          @Override
    76          public boolean test(final Object arg1, final Object arg2) {
                     /* 
    P/P               *  Method: bool test(Object, Object)
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      */
    77              return !STRING_EQUALS.test(arg1, arg2);
    78          }
    79          /** {@inheritDoc} */
    80          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
    81          public Class appliesTo() { return String.class; }
    82          /** {@inheritDoc} */
    83          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"does not equal"
                  */
    84          public String getName() { return "does not equal"; }
    85      },
    86      
    87      /** Checks if the string starts with another strings. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$4(String, int)
              */
    88      STRING_STARTSWITH {
    89          /** {@inheritDoc} */
    90          @Override
    91          public boolean test(final Object arg1, final Object arg2) {
                     /* 
    P/P               *  Method: bool test(Object, Object)
                      * 
                      *  Preconditions:
                      *    arg1 != null
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      */
    92              return ((String) arg1).startsWith((String) arg2);
    93          }
    94          /** {@inheritDoc} */
    95          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
    96          public Class appliesTo() { return String.class; }
    97          /** {@inheritDoc} */
    98          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"starts with"
                  */
    99          public String getName() { return "starts with"; }
   100      },
   101      
   102      /** Checks if the string containts another string. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$5(String, int)
              */
   103      STRING_CONTAINS {
   104          /** {@inheritDoc} */
   105          @Override
   106          public boolean test(final Object arg1, final Object arg2) {
                     /* 
    P/P               *  Method: bool test(Object, Object)
                      * 
                      *  Preconditions:
                      *    arg1 != null
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      */
   107              return ((String) arg1).indexOf((String) arg2) != -1;
   108          }
   109          /** {@inheritDoc} */
   110          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
   111          public Class appliesTo() { return String.class; }
   112          /** {@inheritDoc} */
   113          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"contains"
                  */
   114          public String getName() { return "contains"; }
   115      },
   116  
   117      /** Checks if the string doesn't containt another string. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$6(String, int)
              */
   118      STRING_NCONTAINS {
   119          /** {@inheritDoc} */
   120          @Override
   121          public boolean test(final Object arg1, final Object arg2) {
                     /* 
    P/P               *  Method: bool test(Object, Object)
                      * 
                      *  Preconditions:
                      *    arg1 != null
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      */
   122              return ((String) arg1).indexOf((String) arg2) == -1;
   123          }
   124          /** {@inheritDoc} */
   125          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
   126          public Class appliesTo() { return String.class; }
   127          /** {@inheritDoc} */
   128          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"doesn't contain"
                  */
   129          public String getName() { return "doesn't contain"; }
   130      },
   131      
   132      /** Checks if two boolean values are equal. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$7(String, int)
              */
   133      BOOL_IS {
   134          /** {@inheritDoc} */
   135          @Override
   136          public boolean test(final Object arg1, final Object arg2) {
                     /* 
    P/P               *  Method: bool test(Object, Object)
                      * 
                      *  Preconditions:
                      *    arg1 != null
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      */
   137              return ((Boolean) arg1).equals(Boolean.valueOf((String) arg2));
   138          }
   139          /** {@inheritDoc} */
   140          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
   141          public Class appliesTo() { return Boolean.class; }
   142          /** {@inheritDoc} */
   143          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"is"
                  */
   144          public String getName() { return "is"; }
   145      },
   146      
   147      /** Checks if the colour is the same as another colour. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$8(String, int)
              */
   148      COLOUR_EQUALS {
   149          /** {@inheritDoc} */
   150          @Override
   151          public boolean test(final Object arg1, final Object arg2) {
                     /* 
    P/P               *  Method: bool test(Object, Object)
                      * 
                      *  Preconditions:
                      *    arg1 != null
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      */
   152              return ((Color) arg1).equals(ColourManager.parseColour((String) arg2));
   153          }
   154          /** {@inheritDoc} */
   155          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
   156          public Class appliesTo() { return Color.class; }
   157          /** {@inheritDoc} */
   158          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"equals"
                  */
   159          public String getName() { return "equals"; }
   160      },
   161      
   162      /** Checks if the colour is not the same as another colour. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$9(String, int)
              */
   163      COLOUR_NEQUALS {
   164          /** {@inheritDoc} */
   165          @Override
   166          public boolean test(final Object arg1, final Object arg2) {
                     /* 
    P/P               *  Method: bool test(Object, Object)
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      */
   167              return !COLOUR_EQUALS.test(arg1, arg2);
   168          }
   169          /** {@inheritDoc} */
   170          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
   171          public Class appliesTo() { return Color.class; }
   172          /** {@inheritDoc} */
   173          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"does not equal"
                  */
   174          public String getName() { return "does not equal"; }
   175      },
   176      
   177      /** Checks if the int is equals to another int. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$10(String, int)
              */
   178      INT_EQUALS {
   179          /** {@inheritDoc} */
   180          @Override
   181          public boolean test(final Object arg1, final Object arg2) {
   182              try {
                         /* 
    P/P                   *  Method: bool test(Object, Object)
                          * 
                          *  Preconditions:
                          *    (soft) arg1 != null
                          * 
                          *  Postconditions:
                          *    init'ed(return_value)
                          */
   183                  return 0 == ((Integer) arg1).compareTo(Integer.parseInt((String) arg2));
   184              } catch (NumberFormatException ex) {
   185                  return false;
   186              }
   187          }
   188          /** {@inheritDoc} */
   189          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
   190          public Class appliesTo() { return Integer.class; }
   191          /** {@inheritDoc} */
   192          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"equals"
                  */
   193          public String getName() { return "equals"; }
   194      },
   195      
   196      /** Checks if the int is larger than another int. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$11(String, int)
              */
   197      INT_GREATER {
   198          /** {@inheritDoc} */
   199          @Override
   200          public boolean test(final Object arg1, final Object arg2) {
   201              try {
                         /* 
    P/P                   *  Method: bool test(Object, Object)
                          * 
                          *  Preconditions:
                          *    (soft) arg1 != null
                          * 
                          *  Postconditions:
                          *    init'ed(return_value)
                          */
   202                  return 0 < ((Integer) arg1).compareTo(Integer.parseInt((String) arg2));
   203              } catch (NumberFormatException ex) {
   204                  return false;
   205              }
   206          }
   207          /** {@inheritDoc} */
   208          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
   209          public Class appliesTo() { return Integer.class; }
   210          /** {@inheritDoc} */
   211          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"is greater than"
                  */
   212          public String getName() { return "is greater than"; }
   213      },
   214      
   215      /** Checks if the int is smaller than another int. */
             /* 
    P/P       *  Method: void com.dmdirc.actions.CoreActionComparison$12(String, int)
              */
   216      INT_LESS {
   217          /** {@inheritDoc} */
   218          @Override
   219          public boolean test(final Object arg1, final Object arg2) {
   220              try {
                         /* 
    P/P                   *  Method: bool test(Object, Object)
                          * 
                          *  Preconditions:
                          *    (soft) arg1 != null
                          * 
                          *  Postconditions:
                          *    init'ed(return_value)
                          */
   221                  return 0 > ((Integer) arg1).compareTo(Integer.parseInt((String) arg2));
   222              } catch (NumberFormatException ex) {
   223                  return false;
   224              }
   225          }
   226          /** {@inheritDoc} */
   227          @Override
                 /* 
    P/P           *  Method: Class appliesTo()
                  */
   228          public Class appliesTo() { return Integer.class; }
   229          /** {@inheritDoc} */
   230          @Override
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"is less than"
                  */
   231          public String getName() { return "is less than"; }
   232      };
   233      
   234  }








SofCheck Inspector Build Version : 2.17854
CoreActionComparison.java 2009-Jun-25 01:54:24
CoreActionComparison.class 2009-Sep-02 17:04:13
CoreActionComparison$1.class 2009-Sep-02 17:04:13
CoreActionComparison$10.class 2009-Sep-02 17:04:13
CoreActionComparison$11.class 2009-Sep-02 17:04:13
CoreActionComparison$12.class 2009-Sep-02 17:04:13
CoreActionComparison$2.class 2009-Sep-02 17:04:13
CoreActionComparison$3.class 2009-Sep-02 17:04:13
CoreActionComparison$4.class 2009-Sep-02 17:04:13
CoreActionComparison$5.class 2009-Sep-02 17:04:13
CoreActionComparison$6.class 2009-Sep-02 17:04:13
CoreActionComparison$7.class 2009-Sep-02 17:04:13
CoreActionComparison$8.class 2009-Sep-02 17:04:13
CoreActionComparison$9.class 2009-Sep-02 17:04:13