File Source: ConditionTreeFactory.java

         /* 
    P/P   *  Method: com.dmdirc.actions.ConditionTreeFactory__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  /**
    26   * Provides methods to automatically generated condition tree for a specified
    27   * number of arguments.
    28   * 
    29   * @since 0.6
    30   * @author chris
    31   */
         /* 
    P/P   *  Method: void com.dmdirc.actions.ConditionTreeFactory()
          */
    32  public abstract class ConditionTreeFactory {
    33          
    34      /**
    35       * Retrieves a condition tree for the specified number of arguments.
    36       * 
    37       * @param args The number of arguments in the {@link Action}
    38       * @return A ConditionTree for the specified number of args
    39       */
    40      public abstract ConditionTree getConditionTree(final int args);
    41      
    42      /**
    43       * Retrieves the type this of factory.
    44       * 
    45       * @return This factory's type
    46       */
    47      public abstract ConditionTreeFactoryType getType();
    48      
    49      /**
    50       * The possible types of ConditionTreeFactories
    51       */
             /* 
    P/P       *  Method: void com.dmdirc.actions.ConditionTreeFactory$ConditionTreeFactoryType(String, int)
              */
    52      public static enum ConditionTreeFactoryType {
    53          /** Factories that produce disjunction (OR) trees. */
                 /* 
    P/P           *  Method: com.dmdirc.actions.ConditionTreeFactory$ConditionTreeFactoryType__static_init
                  * 
                  *  Postconditions:
                  *    $VALUES == &new ConditionTreeFactory$ConditionTreeFactoryType[](ConditionTreeFactory$ConditionTreeFactoryType__static_init#4)
                  *    CONJUNCTION == &new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#2)
                  *    $VALUES[1] == &new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#2)
                  *    CUSTOM == &new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#3)
                  *    $VALUES[2] == &new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#3)
                  *    DISJUNCTION == &new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#1)
                  *    $VALUES[0] == &new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#1)
                  *    new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#1) num objects == 1
                  *    new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#2) num objects == 1
                  *    new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#3) num objects == 1
                  *    ...
                  */
    54          DISJUNCTION,
    55          /** Factories that produce conjunction (AND) trees. */
    56          CONJUNCTION,
    57          /** Factories that produce custom trees. */
    58          CUSTOM,
    59      }
    60      
    61      /**
    62       * Creates condition trees where the arguments are conjoined together.
    63       */
             /* 
    P/P       *  Method: void com.dmdirc.actions.ConditionTreeFactory$ConjunctionFactory()
              */
    64      public static class ConjunctionFactory extends ConditionTreeFactory {
    65  
    66          /** {@inheritDoc} */
    67          @Override
    68          public ConditionTree getConditionTree(final int args) {
                     /* 
    P/P               *  Method: ConditionTree getConditionTree(int)
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      *    new ConditionTree(parseStack#3) num objects <= 1
                      *    new ConditionTree(parseStack#3).argument == -1
                      *    new ConditionTree(parseStack#3).leftArg == null
                      *    new ConditionTree(parseStack#3).op == &amp;com.dmdirc.actions.ConditionTree$OPERATION__static_init.new ConditionTree$OPERATION(ConditionTree$OPERATION__static_init#5)
                      *    new ConditionTree(parseStack#3).rightArg == null
                      *    init'ed(new ConditionTree(readTerm#1) num objects)
                      *    new ConditionTree(readTerm#1).argument == 0, if init'ed
                      *    new ConditionTree(readTerm#1).leftArg == null
                      *    new ConditionTree(readTerm#1).op == null
                      *    ...
                      */
    69              return ConditionTree.createConjunction(args);
    70          }
    71  
    72          /** {@inheritDoc} */
    73          @Override
    74          public ConditionTreeFactoryType getType() {
                     /* 
    P/P               *  Method: ConditionTreeFactory$ConditionTreeFactoryType getType()
                      * 
                      *  Postconditions:
                      *    return_value == &amp;com.dmdirc.actions.ConditionTreeFactory$ConditionTreeFactoryType__static_init.new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#2)
                      */
    75              return ConditionTreeFactoryType.CONJUNCTION;
    76          }
    77          
    78      }
    79  
    80      /**
    81       * Creates condition trees where the arguments are disjoined together.
    82       */
             /* 
    P/P       *  Method: void com.dmdirc.actions.ConditionTreeFactory$DisjunctionFactory()
              */
    83      public static class DisjunctionFactory extends ConditionTreeFactory {
    84  
    85          /** {@inheritDoc} */
    86          @Override
    87          public ConditionTree getConditionTree(final int args) {
                     /* 
    P/P               *  Method: ConditionTree getConditionTree(int)
                      * 
                      *  Postconditions:
                      *    init'ed(return_value)
                      *    new ConditionTree(parseStack#3) num objects <= 1
                      *    new ConditionTree(parseStack#3).argument == -1
                      *    new ConditionTree(parseStack#3).leftArg == null
                      *    new ConditionTree(parseStack#3).op == &amp;com.dmdirc.actions.ConditionTree$OPERATION__static_init.new ConditionTree$OPERATION(ConditionTree$OPERATION__static_init#5)
                      *    new ConditionTree(parseStack#3).rightArg == null
                      *    init'ed(new ConditionTree(readTerm#1) num objects)
                      *    new ConditionTree(readTerm#1).argument == 0, if init'ed
                      *    new ConditionTree(readTerm#1).leftArg == null
                      *    new ConditionTree(readTerm#1).op == null
                      *    ...
                      */
    88              return ConditionTree.createDisjunction(args);
    89          }
    90          
    91          /** {@inheritDoc} */
    92          @Override
    93          public ConditionTreeFactoryType getType() {
                     /* 
    P/P               *  Method: ConditionTreeFactory$ConditionTreeFactoryType getType()
                      * 
                      *  Postconditions:
                      *    return_value == &amp;com.dmdirc.actions.ConditionTreeFactory$ConditionTreeFactoryType__static_init.new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#1)
                      */
    94              return ConditionTreeFactoryType.DISJUNCTION;
    95          }
    96          
    97      }
    98      
    99      /**
   100       * Creates condition trees with a custom structure.
   101       */
   102      public static class CustomFactory extends ConditionTreeFactory {
   103          
   104          /** The condition tree to use. */
   105          protected final ConditionTree tree;
   106  
   107          /**
   108           * Creates a new CustomFactory for the specified tree.
   109           * 
   110           * @param tree The tree to use
   111           */
                 /* 
    P/P           *  Method: void com.dmdirc.actions.ConditionTreeFactory$CustomFactory(ConditionTree)
                  * 
                  *  Postconditions:
                  *    this.tree == tree
                  *    init'ed(this.tree)
                  */
   112          public CustomFactory(final ConditionTree tree) {
   113              this.tree = tree;
   114          }
   115  
   116          /** {@inheritDoc} */
   117          @Override
   118          public ConditionTree getConditionTree(final int args) {
                     /* 
    P/P               *  Method: ConditionTree getConditionTree(int)
                      * 
                      *  Postconditions:
                      *    return_value == this.tree
                      *    init'ed(return_value)
                      */
   119              return tree;
   120          }
   121          
   122          /** {@inheritDoc} */
   123          @Override
   124          public ConditionTreeFactoryType getType() {
                     /* 
    P/P               *  Method: ConditionTreeFactory$ConditionTreeFactoryType getType()
                      * 
                      *  Postconditions:
                      *    return_value == &amp;com.dmdirc.actions.ConditionTreeFactory$ConditionTreeFactoryType__static_init.new ConditionTreeFactory$ConditionTreeFactoryType(ConditionTreeFactory$ConditionTreeFactoryType__static_init#3)
                      */
   125              return ConditionTreeFactoryType.CUSTOM;
   126          }
   127          
   128      }
   129      
   130      /**
   131       * Retrieves a factory that will extrapolate the specified
   132       * {@link ConditionTree} for different number of arguments, if applicable.
   133       * 
   134       * @param tree The {@link ConditionTree} that's in use
   135       * @param args The number of conditions currently in use
   136       * @return A {@link ConditionTreeFactory} that will create relevant
   137       * {@link ConditionTree}s
   138       */
   139      public static ConditionTreeFactory getFactory(final ConditionTree tree, final int args) {
                 /* 
    P/P           *  Method: ConditionTreeFactory getFactory(ConditionTree, int)
                  * 
                  *  Preconditions:
                  *    tree != null
                  *    (soft) init'ed(com.dmdirc.actions.ConditionTree$1__static_init.new int[](ConditionTree$1__static_init#1)[...])
                  *    (soft) init'ed(tree.argument)
                  *    (soft) init'ed(tree.leftArg)
                  *    (soft) tree.op != null
                  *    (soft) init'ed(tree.rightArg)
                  * 
                  *  Presumptions:
                  *    createConjunction(...).op != null
                  *    createDisjunction(...).op != null
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{&amp;new ConditionTreeFactory$CustomFactory(getFactory#3),&amp;new ConditionTreeFactory$DisjunctionFactory(getFactory#2),&amp;new ConditionTreeFactory$ConjunctionFactory(getFactory#1)}
                  *    new ConditionTreeFactory$ConjunctionFactory(getFactory#1) num objects <= 1
                  *    new ConditionTreeFactory$CustomFactory(getFactory#3) num objects <= 1
                  *    new ConditionTreeFactory$CustomFactory(getFactory#3).tree == tree
                  *    new ConditionTreeFactory$CustomFactory(getFactory#3).tree != null
                  *    new ConditionTreeFactory$DisjunctionFactory(getFactory#2) num objects <= 1
                  */
   140          if (tree.equals(ConditionTree.createConjunction(args))) {
   141              return new ConjunctionFactory();
   142          } else if (tree.equals(ConditionTree.createDisjunction(args))) {
   143              return new DisjunctionFactory();
   144          } else {
   145              return new CustomFactory(tree);
   146          }
   147      }
   148  
   149  }








SofCheck Inspector Build Version : 2.17854
ConditionTreeFactory.java 2009-Jun-25 01:54:24
ConditionTreeFactory.class 2009-Sep-02 17:04:13
ConditionTreeFactory$ConditionTreeFactoryType.class 2009-Sep-02 17:04:13
ConditionTreeFactory$ConjunctionFactory.class 2009-Sep-02 17:04:13
ConditionTreeFactory$CustomFactory.class 2009-Sep-02 17:04:13
ConditionTreeFactory$DisjunctionFactory.class 2009-Sep-02 17:04:13