File Source: ActionCondition.java

         /* 
    P/P   *  Method: com.dmdirc.actions.ActionCondition__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.actions.interfaces.ActionComponent;
    27  
    28  /**
    29   * An action condition represents one condition within an action.
    30   * @author chris
    31   */
    32  public class ActionCondition {
    33      
    34      /** The argument number that this action condition applies to. */
    35      private int arg;
    36      
    37      /** The component that this action condition applies to. */
    38      private ActionComponent component;
    39      
    40      /** The comparison that should be used for this condition. */
    41      private ActionComparison comparison;
    42      
    43      /** The target of the comparison for this condition. */
    44      private String target = "";
    45      
    46      /** The source target for this comparison. */
    47      private String starget = "";
    48      
    49      /**
    50       * Creates a new instance of ActionCondition that compares the output of
    51       * a component to a string.
    52       * 
    53       * @param arg The argument number to be tested
    54       * @param component The component to be tested
    55       * @param comparison The comparison to be used
    56       * @param target The target of the comparison
    57       */
    58      public ActionCondition(final int arg, final ActionComponent component,
    59              final ActionComparison comparison, final String target) {
                 /* 
    P/P           *  Method: void com.dmdirc.actions.ActionCondition(int, ActionComponent, ActionComparison, String)
                  * 
                  *  Postconditions:
                  *    this.arg == arg
                  *    init'ed(this.arg)
                  *    this.comparison == comparison
                  *    init'ed(this.comparison)
                  *    this.component == component
                  *    init'ed(this.component)
                  *    this.starget == &""
                  *    this.target == target
                  *    init'ed(this.target)
                  */
    60          super();
    61          
    62          this.arg = arg;
    63          this.component = component;
    64          this.comparison = comparison;
    65          this.target = target;
    66      }
    67      
    68      /**
    69       * Creates a new instance of ActionCondition that compares two strings.
    70       * 
    71       * @param starget The first target for comparison.
    72       * @param comparison The comparison to be used
    73       * @param target The second target for the comparison
    74       */
    75      public ActionCondition(final String starget, final ActionComparison comparison,
    76              final String target) {
                 /* 
    P/P           *  Method: void com.dmdirc.actions.ActionCondition(String, ActionComparison, String)
                  * 
                  *  Postconditions:
                  *    this.arg == -1
                  *    this.comparison == comparison
                  *    init'ed(this.comparison)
                  *    this.starget == starget
                  *    init'ed(this.starget)
                  *    this.target == target
                  *    init'ed(this.target)
                  */
    77          super();
    78          
    79          this.arg = -1;
    80          this.starget = starget;
    81          this.comparison = comparison;
    82          this.target = target;
    83      }
    84      
    85      /**
    86       * Tests to see if this condition holds.
    87       * 
    88       * @param sub The substitutor to use for this
    89       * @param args The event arguments to be tested
    90       * @return True if the condition holds, false otherwise
    91       */
    92      public boolean test(final ActionSubstitutor sub, final Object ... args) {
                 /* 
    P/P           *  Method: bool test(ActionSubstitutor, Object[])
                  * 
                  *  Preconditions:
                  *    args != null
                  *    sub != null
                  *    sub.type != null
                  *    this.arg >= -1
                  *    this.comparison != null
                  *    init'ed(this.target)
                  *    (soft) this.arg < args.length
                  *    (soft) init'ed(args[0])
                  *    (soft) init'ed(args[1])
                  *    (soft) args[1].length in {1..232-1}
                  *    ...
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    this.arg: {0..232-1}, {-1}
                  */
    93          final String thisTarget = sub.doSubstitution(getTarget(), args);
    94          
    95          if (arg == -1) { 
    96              final String thisStarget = sub.doSubstitution(starget, args);
    97              return getComparison().test(thisStarget, thisTarget);
    98          } else {
    99              return getComparison().test(getComponent().get(args[getArg()]), thisTarget);
   100          }
   101      }
   102      
   103      /**
   104       * Returns the argument number this condition applies to.
   105       *
   106       * @return Argument number
   107       */
   108      public int getArg() {
                 /* 
    P/P           *  Method: int getArg()
                  * 
                  *  Preconditions:
                  *    init'ed(this.arg)
                  * 
                  *  Postconditions:
                  *    return_value == this.arg
                  *    init'ed(return_value)
                  */
   109          return arg;
   110      }
   111      
   112      /**
   113       * Returns the component this condition applies to.
   114       *
   115       * @return Component to apply condition to
   116       */
   117      public ActionComponent getComponent() {
                 /* 
    P/P           *  Method: ActionComponent getComponent()
                  * 
                  *  Preconditions:
                  *    init'ed(this.component)
                  * 
                  *  Postconditions:
                  *    return_value == this.component
                  *    init'ed(return_value)
                  */
   118          return component;
   119      }
   120      
   121      /**
   122       * Returns the comparison this condition applies to.
   123       *
   124       * @return Comparison to be used
   125       */
   126      public ActionComparison getComparison() {
                 /* 
    P/P           *  Method: ActionComparison getComparison()
                  * 
                  *  Preconditions:
                  *    init'ed(this.comparison)
                  * 
                  *  Postconditions:
                  *    return_value == this.comparison
                  *    init'ed(return_value)
                  */
   127          return comparison;
   128      }
   129      
   130      /**
   131       * Returns the target of the comparison for this condition.
   132       *
   133       * @return Target for comparison
   134       */
   135      public String getTarget() {
                 /* 
    P/P           *  Method: String getTarget()
                  * 
                  *  Preconditions:
                  *    init'ed(this.target)
                  * 
                  *  Postconditions:
                  *    return_value == this.target
                  *    init'ed(return_value)
                  */
   136          return target;
   137      }
   138      
   139      /**
   140       * Sets the argument number this condition applies to.
   141       *
   142       * @param arg Argument number
   143       */
   144      public void setArg(final int arg) {
                 /* 
    P/P           *  Method: void setArg(int)
                  * 
                  *  Postconditions:
                  *    this.arg == arg
                  *    init'ed(this.arg)
                  */
   145          this.arg = arg;
   146      }
   147      
   148      /**
   149       * Sets the component this condition applies to.
   150       *
   151       * @param component Component to apply condition to
   152       */
   153      public void setComponent(final ActionComponent component) {
                 /* 
    P/P           *  Method: void setComponent(ActionComponent)
                  * 
                  *  Postconditions:
                  *    this.component == component
                  *    init'ed(this.component)
                  */
   154          this.component = component;
   155      }
   156      
   157      /**
   158       * Sets the comparison this condition applies to.
   159       *
   160       * @param comparison Comparison to be used
   161       */
   162      public void setComparison(final ActionComparison comparison) {
                 /* 
    P/P           *  Method: void setComparison(ActionComparison)
                  * 
                  *  Postconditions:
                  *    this.comparison == comparison
                  *    init'ed(this.comparison)
                  */
   163          this.comparison = comparison;
   164      }
   165      
   166      /**
   167       * Sets the target of the comparison for this condition.
   168       * @param target Target for comparison
   169       */
   170      public void setTarget(final String target) {
                 /* 
    P/P           *  Method: void setTarget(String)
                  * 
                  *  Postconditions:
                  *    this.target == target
                  *    init'ed(this.target)
                  */
   171          this.target = target;
   172      }
   173  
   174      /**
   175       * Retrieves the starget of this condition.
   176       * 
   177       * @return This condition's starget, or null if none was set.
   178       */
   179      public String getStarget() {
                 /* 
    P/P           *  Method: String getStarget()
                  * 
                  *  Preconditions:
                  *    init'ed(this.starget)
                  * 
                  *  Postconditions:
                  *    return_value == this.starget
                  *    init'ed(return_value)
                  */
   180          return starget;
   181      }
   182  
   183      /**
   184       * Sets the starget for this condition.
   185       * 
   186       * @param starget The new starget for this condition.
   187       */
   188      public void setStarget(final String starget) {
                 /* 
    P/P           *  Method: void setStarget(String)
                  * 
                  *  Postconditions:
                  *    this.starget == starget
                  *    init'ed(this.starget)
                  */
   189          this.starget = starget;
   190      }
   191      
   192      /** {@inheritDoc} */
   193      @Override
   194      public String toString() {
                 /* 
    P/P           *  Method: String toString()
                  * 
                  *  Preconditions:
                  *    init'ed(this.arg)
                  *    init'ed(this.comparison)
                  *    init'ed(this.component)
                  *    init'ed(this.starget)
                  *    init'ed(this.target)
                  * 
                  *  Postconditions:
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &amp;java.lang.StringBuilder:toString(...)
                  */
   195          return "[ arg=" + arg + ", component=" + component + ", comparison=" 
   196                  + comparison + ", target=" + target + ", starget=" + starget + " ]";
   197      }
   198  
   199      /** {@inheritDoc} */
   200      @Override
   201      public boolean equals(final Object obj) {
                 /* 
    P/P           *  Method: bool equals(Object)
                  * 
                  *  Preconditions:
                  *    (soft) init'ed(obj.arg)
                  *    (soft) init'ed(obj.comparison)
                  *    (soft) init'ed(obj.component)
                  *    (soft) init'ed(obj.starget)
                  *    (soft) init'ed(obj.target)
                  *    (soft) init'ed(this.arg)
                  *    (soft) init'ed(this.comparison)
                  *    (soft) init'ed(this.component)
                  *    (soft) this.starget != null
                  *    (soft) this.target != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   202          if (!(obj instanceof ActionCondition)) {
   203              return false;
   204          }
   205          
   206          final ActionCondition o = (ActionCondition) obj;
   207          
   208          return arg == o.getArg() && component == o.getComponent()
   209                  && comparison == o.getComparison() && target.equals(o.getTarget())
   210                  && starget.equals(o.getStarget());
   211      }
   212      
   213      /** {@inheritDoc} */
   214      @Override
   215      public int hashCode() {
                 /* 
    P/P           *  Method: int hashCode()
                  * 
                  *  Preconditions:
                  *    init'ed(this.arg)
                  *    this.comparison != null
                  *    this.target != null
                  *    (soft) this.component != null
                  *    (soft) this.starget != null
                  * 
                  *  Presumptions:
                  *    java.lang.String:hashCode(...)@216 in {-433_856_121..216_960_272}
                  *    this.arg + java.lang.String:hashCode(...)*100 + java.lang.Object:hashCode(...)@216*10_000 + java.lang.String:hashCode(...)@216*100_000 in {-231..232-1}
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    this.arg: {-231..-2, 0..232-1}, {-1}
                  */
   216          return arg + 100 * (arg == -1 ? starget.hashCode() : component.hashCode())
   217                  + 10000 * comparison.hashCode() + 100000 * target.hashCode();
   218      }
   219      
   220  }








SofCheck Inspector Build Version : 2.17854
ActionCondition.java 2009-Jun-25 01:54:24
ActionCondition.class 2009-Sep-02 17:04:13