Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * 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.hibernate.validator.internal.engine.groups;
 
 import java.util.List;
 import java.util.Map;
 
 
 import static org.hibernate.validator.internal.util.CollectionHelper.newArrayList;
 import static org.hibernate.validator.internal.util.CollectionHelper.newHashMap;

An instance of ValidationOrder defines the group order during one validation call.

Author(s):
Hardy Ferentschik
 
 public final class DefaultValidationOrder implements ValidationOrder {
 	private static final Log log = LoggerFactory.make();

The list of single groups to be used this validation.
 
 	private List<GroupgroupList = newArrayList();

The different sequences for this validation. The map contains the sequences mapped to their sequence name.
 
 	private Map<Class<?>, SequencesequenceMap = newHashMap();
 
 		return .iterator();
 	}
 
 		return .values().iterator();
 	}
 
 	public void insertGroup(Group group) {
 		if ( !.containsgroup ) ) {
 			.addgroup );
 		}
 	}
 
 	public void insertSequence(Sequence sequence) {
 		if ( sequence == null ) {
 			return;
 		}
 
 		if ( !.containsKeysequence.getDefiningClass() ) ) {
 			.putsequence.getDefiningClass(), sequence );
 		}
 	}
 
 	public String toString() {
 		return "ValidationOrder{" +
 				"groupList=" +  +
 				", sequenceMap=" +  +
 				'}';
 	}

Asserts that the default group sequence of the validated bean can be expanded into the sequences which needs to be validated.

Parameters:
defaultGroupSequence the default group sequence of the bean currently validated
Throws:
javax.validation.GroupDefinitionException in case defaultGroupSequence cannot be expanded into one of the group sequences which need to be validated
 
 	public void assertDefaultGroupSequenceIsExpandable(List<Class<?>> defaultGroupSequence)
 		for ( Map.Entry<Class<?>, Sequenceentry : .entrySet() ) {
 			List<GroupsequenceGroups = entry.getValue().getComposingGroups();
 			int defaultGroupIndex = sequenceGroups.indexOf. );
 			if ( defaultGroupIndex != -1 ) {
 				List<GroupdefaultGroupList = buildTempGroupListdefaultGroupSequence );
 				ensureDefaultGroupSequenceIsExpandablesequenceGroupsdefaultGroupListdefaultGroupIndex );
 			}
		}
	}
	private void ensureDefaultGroupSequenceIsExpandable(List<GroupgroupListList<GroupdefaultGroupListint defaultGroupIndex) {
		for ( int i = 0; i < defaultGroupList.size(); i++ ) {
			Group group = defaultGroupList.geti );
			if ( ..equalsgroup ) ) {
				continue// we don't have to consider the default group since it is the one we want to replace
			}
			int index = groupList.indexOfgroup ); // check whether the sequence contains group of the default group sequence
			if ( index == -1 ) {
				continue// if the group is not in the sequence we can continue
			}
			if ( ( i == 0 && index == defaultGroupIndex - 1 ) || ( i == defaultGroupList.size() - 1 && index == defaultGroupIndex + 1 ) ) {
				// if we are at the beginning or end of he defaultGroupSequence and the matches are either directly before resp after we can continue as well,
				// since we basically have two groups
				continue;
			}
			throw .getUnableToExpandDefaultGroupListExceptiondefaultGroupListgroupList );
		}
	}
	private List<GroupbuildTempGroupList(List<Class<?>> defaultGroupSequence) {
		List<Groupgroups = new ArrayList<Group>();
		for ( Class<?> clazz : defaultGroupSequence ) {
			Group g = new Groupclazz );
			groups.addg );
		}
		return groups;
	}
New to GrepCode? Check out our FAQ X