//# 0 errors, 81 messages
//#
/*
    //#ValidatorChain.java:1:1: class: com.dmdirc.config.prefs.validator.ValidatorChain
    //#ValidatorChain.java:1:1: method: com.dmdirc.config.prefs.validator.ValidatorChain.com.dmdirc.config.prefs.validator.ValidatorChain__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.config.prefs.validator;

import java.util.ArrayList;
import java.util.List;

/**
 * Allows multiple validators to be chained together.
 * 
 * @param A The type of class that this chain validates
 * @author chris
 */
public class ValidatorChain<A> implements Validator<A> {
    
    /** A list of validators to use. */
    private final List<Validator<A>> validatorList
            = new ArrayList<Validator<A>>();

    /**
     * Creates a new validator chain containing the specified validators.
     * 
     * @param validators The validators to be used in this chain.
     */
    public ValidatorChain(final Validator<A> ... validators) {
    //#ValidatorChain.java:45: method: void com.dmdirc.config.prefs.validator.ValidatorChain.com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])
    //#input(void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): this
    //#input(void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): validators
    //#input(void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): validators.length
    //#input(void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): validators[0..4_294_967_295]
    //#output(void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): new ArrayList(ValidatorChain#1) num objects
    //#output(void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): this.validatorList
    //#new obj(void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): new ArrayList(ValidatorChain#1)
    //#pre[2] (void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): validators != null
    //#pre[3] (void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): validators.length <= 4_294_967_295
    //#pre[4] (void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): (soft) init'ed(validators[0..4_294_967_295])
    //#post(void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): this.validatorList == &new ArrayList(ValidatorChain#1)
    //#post(void com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])): new ArrayList(ValidatorChain#1) num objects == 1
        for (Validator<A> validator : validators) {
            validatorList.add(validator);
        }
    }
    //#ValidatorChain.java:49: end of method: void com.dmdirc.config.prefs.validator.ValidatorChain.com.dmdirc.config.prefs.validator.ValidatorChain(Validator[])

    /** {@inheritDoc} */
    @Override
    public ValidationResponse validate(final A object) {
        for (Validator<A> validator : validatorList) {
    //#ValidatorChain.java:54: method: ValidationResponse com.dmdirc.config.prefs.validator.ValidatorChain.validate(Object)
    //#input(ValidationResponse validate(Object)): __Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/ActionGroupValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/CommandNameValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/ConditionRuleValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/FileNameValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/IdentValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/NicknameValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/NotEmptyValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/NumericalValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/PermissiveValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/PortValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/RegexStringValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/RegexValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/StringLengthValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/URLProtocolValidator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/ValidationResponse.__Descendant_Table[com/dmdirc/config/prefs/validator/ValidationResponse]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/ValidationResponse.__Descendant_Table[others]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/ValidationResponse.__Dispatch_Table.isFailure()Z
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/ActionGroupValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/CommandNameValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/ConditionRuleValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/FileNameValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/IdentValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/NicknameValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/NotEmptyValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/NumericalValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/PermissiveValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/PortValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/RegexStringValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/RegexValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/StringLengthValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/URLProtocolValidator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/ValidatorChain]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/Validator]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[others]
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/Validator.__Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): object
    //#input(ValidationResponse validate(Object)): this
    //#input(ValidationResponse validate(Object)): this.validatorList
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#1) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#1).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#1).failure
    //#output(ValidationResponse validate(Object)): return_value
    //#new obj(ValidationResponse validate(Object)): new ValidationResponse(validate#1)
    //#pre[3] (ValidationResponse validate(Object)): this.validatorList != null
    //#presumption(ValidationResponse validate(Object)): java.util.Iterator:next(...).__Tag@54 in {com/dmdirc/config/prefs/validator/ActionGroupValidator, com/dmdirc/config/prefs/validator/CommandNameValidator, com/dmdirc/config/prefs/validator/ConditionRuleValidator, com/dmdirc/config/prefs/validator/FileNameValidator, com/dmdirc/config/prefs/validator/IdentValidator, com/dmdirc/config/prefs/validator/NicknameValidator, com/dmdirc/config/prefs/validator/NotEmptyValidator, com/dmdirc/config/prefs/validator/NumericalValidator, com/dmdirc/config/prefs/validator/PermissiveValidator, com/dmdirc/config/prefs/validator/PortValidator, com/dmdirc/config/prefs/validator/RegexStringValidator, com/dmdirc/config/prefs/validator/RegexValidator, com/dmdirc/config/prefs/validator/StringLengthValidator, com/dmdirc/config/prefs/validator/URLProtocolValidator, com/dmdirc/config/prefs/validator/Validator, com/dmdirc/config/prefs/validator/ValidatorChain}
    //#presumption(ValidationResponse validate(Object)): java.util.Iterator:next(...)@54 != null
    //#presumption(ValidationResponse validate(Object)): res.__Tag@55 == com/dmdirc/config/prefs/validator/ValidationResponse
    //#presumption(ValidationResponse validate(Object)): validate(...)@55 != null
    //#post(ValidationResponse validate(Object)): return_value != null
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#1) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#1).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#1).failure == null
    //#test_vector(ValidationResponse validate(Object)): java.util.Iterator:hasNext(...)@54: {0}, {1}
            final ValidationResponse res = validator.validate(object);
    //#ValidatorChain.java:55: Warning: call too complex - analysis skipped
    //#    call on ValidationResponse validate(Object)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.config.prefs.validator.ValidatorChain
    //#    method: ValidationResponse validate(Object)
    //#    unanalyzed callee: ValidationResponse validate(Object)
            
            if (res.isFailure()) {
                return res;
            }
        }
        
        return new ValidationResponse();
    //#ValidatorChain.java:62: end of method: ValidationResponse com.dmdirc.config.prefs.validator.ValidatorChain.validate(Object)
    }

}
    //#output(com.dmdirc.config.prefs.validator.ValidatorChain__static_init): __Descendant_Table[com/dmdirc/config/prefs/validator/ValidatorChain]
    //#output(com.dmdirc.config.prefs.validator.ValidatorChain__static_init): __Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#output(com.dmdirc.config.prefs.validator.ValidatorChain__static_init): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/ValidatorChain]
    //#post(com.dmdirc.config.prefs.validator.ValidatorChain__static_init): __Descendant_Table[com/dmdirc/config/prefs/validator/ValidatorChain] == &__Dispatch_Table
    //#post(com.dmdirc.config.prefs.validator.ValidatorChain__static_init): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/ValidatorChain] == &__Dispatch_Table
    //#post(com.dmdirc.config.prefs.validator.ValidatorChain__static_init): __Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse; == &validate
    //#ValidatorChain.java:: end of method: com.dmdirc.config.prefs.validator.ValidatorChain.com.dmdirc.config.prefs.validator.ValidatorChain__static_init
    //#ValidatorChain.java:: end of class: com.dmdirc.config.prefs.validator.ValidatorChain
