Iterate through a field that is a collection of POJOs and validate each of them. Inherit member POJO's error message. @param collection the validatable POJO collection @param name name of the field
(final Collection<T> collection,
final String name)
| 30 | * @param name name of the field |
| 31 | */ |
| 32 | <T extends Validatable> void validateCollection(final Collection<T> collection, |
| 33 | final String name) { |
| 34 | Iterator<T> iterator = collection.iterator(); |
| 35 | int i = 0; |
| 36 | while (iterator.hasNext()) { |
| 37 | try { |
| 38 | iterator.next().validate(); |
| 39 | } catch (final IllegalArgumentException e) { |
| 40 | throw new IllegalArgumentException("Invalid " + name + |
| 41 | " at index " + i, e); |
| 42 | } |
| 43 | i++; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Validate a single POJO validate |