// process first single groups. For these we can optimise object traversal by first running all validations on the current bean
// before traversing the object.
Iterator<Group> groupIterator = groupChain.getGroupIterator();
while ( groupIterator.hasNext() ) {
Group group = groupIterator.next();
valueContext.setCurrentGroup( group.getGroup() );
validateConstraintsForCurrentGroup( context, valueContext );
if ( context.shouldFailFast() ) {
return context.getFailingConstraints();
}
}
groupIterator = groupChain.getGroupIterator();
while ( groupIterator.hasNext() ) {
Group group = groupIterator.next();
valueContext.setCurrentGroup( group.getGroup() );
validateCascadedConstraints( context, valueContext );
if ( context.shouldFailFast() ) {
return context.getFailingConstraints();
}
}
// now we process sequences. For sequences I have to traverse the object graph since I have to stop processing when an error occurs.
Iterator<List<Group>> sequenceIterator = groupChain.getSequenceIterator();
while ( sequenceIterator.hasNext() ) {
List<Group> sequence = sequenceIterator.next();
for ( Group group : sequence ) {
int numberOfViolations = context.getFailingConstraints().size();
valueContext.setCurrentGroup( group.getGroup() );
validateConstraintsForCurrentGroup( context, valueContext );
if ( context.shouldFailFast() ) {
return context.getFailingConstraints();
}