File Source: ValidatorChain.java

         /* 
    P/P   *  Method: com.dmdirc.config.prefs.validator.ValidatorChain__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.config.prefs.validator;
    24  
    25  import java.util.ArrayList;
    26  import java.util.List;
    27  
    28  /**
    29   * Allows multiple validators to be chained together.
    30   * 
    31   * @param A The type of class that this chain validates
    32   * @author chris
    33   */
    34  public class ValidatorChain<A> implements Validator<A> {
    35      
    36      /** A list of validators to use. */
    37      private final List<Validator<A>> validatorList
    38              = new ArrayList<Validator<A>>();
    39  
    40      /**
    41       * Creates a new validator chain containing the specified validators.
    42       * 
    43       * @param validators The validators to be used in this chain.
    44       */
             /* 
    P/P       *  Method: void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])
              * 
              *  Preconditions:
              *    validators != null
              *    validators.length <= 232-1
              *    (soft) init'ed(validators[...])
              * 
              *  Postconditions:
              *    this.validatorList == &amp;new ArrayList(ValidatorChain#1)
              *    new ArrayList(ValidatorChain#1) num objects == 1
              */
    45      public ValidatorChain(final Validator<A> ... validators) {
    46          for (Validator<A> validator : validators) {
    47              validatorList.add(validator);
    48          }
    49      }
    50  
    51      /** {@inheritDoc} */
    52      @Override
    53      public ValidationResponse validate(final A object) {
                 /* 
    P/P           *  Method: ValidationResponse validate(Object)
                  * 
                  *  Preconditions:
                  *    this.validatorList != null
                  * 
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@54 != null
                  *    validate(...)@55 != null
                  * 
                  *  Postconditions:
                  *    return_value != null
                  *    new ValidationResponse(validate#1) num objects <= 1
                  *    new ValidationResponse(validate#1).failure == null
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@54: {0}, {1}
                  */
    54          for (Validator<A> validator : validatorList) {
    55              final ValidationResponse res = validator.validate(object);
    56              
    57              if (res.isFailure()) {
    58                  return res;
    59              }
    60          }
    61          
    62          return new ValidationResponse();
    63      }
    64  
    65  }








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