Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* 
  * Copyright (C) 2012 FoxLabs
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.foxlabs.validation.constraint;
This class provides ConstraintAggregation implementation that is disjunction of the encapsulated constraints. In other words this class represents logical OR operator.

public final class ConstraintDisjunction<V> extends ConstraintAggregation<V> {
    
    
Constructs a new ConstraintDisjunction with the specified value type and array of constraints.

Parameters:
type The type of value to be validated.
constraints Array of constraints to be used for validation of a value.
Throws:
java.lang.IllegalArgumentException if the specified type is null or the specified array of constraints is null or empty or contains null elements.
    ConstraintDisjunction(Class<?> type, Constraint<? super V>[] constraints) {
        super(typeconstraints);
    }
    
    
Checks whether the specified value conforms at least one of the encapsulated constraints.

Parameters:
value Value to be validated.
context Validation context.
Returns:
Possibly modified value if the specified value conforms to one of the encapsulated constraint and that constraint can modify value.
Throws:
ConstraintViolationException if the specified value not conforms to all of the encapsulated constraints.
    @Override
    @SuppressWarnings("unchecked")
    public <T> V validate(V valueValidationContext<T> context) {
        for (Constraint<? super V> constraint : ) {
            try {
                return (V) constraint.validate(valuecontext);
            } catch (ConstraintViolationException e) {}
        }
        throw new ConstraintViolationException(thiscontextvalue);
    }
    
New to GrepCode? Check out our FAQ X