01: package org.vraptor.validator;
02:
03: import java.util.ArrayList;
04: import java.util.Iterator;
05: import java.util.List;
06:
07: import org.vraptor.i18n.ValidationMessage;
08:
09: /**
10: * A basic list implementation of validation errors.
11: *
12: * @author Guilherme Silveira
13: */
14: public class BasicValidationErrors implements ValidationErrors {
15:
16: private final List<ValidationMessage> errors;
17:
18: public BasicValidationErrors() {
19: this (new ArrayList<ValidationMessage>());
20: }
21:
22: public BasicValidationErrors(List<ValidationMessage> errors) {
23: this .errors = errors;
24: }
25:
26: /**
27: *
28: * @see org.vraptor.validator.ValidationErrors#add(org.vraptor.i18n.Message)
29: */
30: public void add(ValidationMessage error) {
31: errors.add(error);
32: }
33:
34: /**
35: *
36: * @see org.vraptor.validator.ValidationErrors#size()
37: */
38: public int size() {
39: return errors.size();
40: }
41:
42: public Iterator<ValidationMessage> getIterator() {
43: return errors.iterator();
44: }
45:
46: public Iterator<ValidationMessage> iterator() {
47: return errors.iterator();
48: }
49:
50: @Override
51: public String toString() {
52: return "[Errors: " + errors.toString() + "]";
53: }
54:
55: public boolean isEmptyFor(String path) {
56: if (path == null) {
57: return errors.isEmpty();
58: }
59: for (ValidationMessage msg : this .errors) {
60: if (msg.getPath().equals(path)) {
61: return false;
62: }
63: }
64: return true;
65: }
66:
67: }
|