< T extends Validatable > void validateCollection ( final Collection < T > collection , final String name ) { Iterator < T > iterator = collection . iterator ( ) ; int i = 0 ; while ( iterator . hasNext ( ) ) { try { iterator . next ( ) . validate ( ) ; } catch ( final IllegalArgumentException e ) { throw new IllegalArgumentException ( "Invalid " + name + " at index " + i , e ) ; } i ++ ; } }
Iterate through a field that is a collection of POJOs and validate each of them . Inherit member POJO s error message .