View Javadoc

1   /** 2007, Digitalis Informatica. All rights reserved.
2    *
3    * Distribuicao e Gestao de Informatica, Lda.
4    * Estrada de Paco de Arcos num.9 - Piso -1
5    * 2780-666 Paco de Arcos
6    * Telefone: (351) 21 4408990
7    * Fax: (351) 21 4408999
8    * http://www.digitalis.pt
9    */
10  package pt.digitalis.dif.dem.objects.parameters.errors;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  import pt.digitalis.dif.dem.objects.parameters.IParameter;
16  import pt.digitalis.dif.utils.ObjectFormatter;
17  
18  /**
19   * A list of parameter errors for a given parameter
20   *
21   * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a>
22   */
23  public class ParameterErrorList {
24  
25      /** The parameter to witch the errors refer to */
26      private IParameter<?> parameter;
27  
28      /** The value that was attempted to pass to the parameter */
29      private Object attemptedValue;
30  
31      /**
32       * The list of errors for the given parameter
33       */
34      private List<ParameterError> errorList = new ArrayList<ParameterError>();
35  
36      /**
37       * Default constructor
38       *
39       * @param parameter
40       *            the parameter that caused the error
41       * @param attemptedValue
42       *            the value that was attempted to pass to the parameter
43       */
44      public ParameterErrorList(IParameter<?> parameter, Object attemptedValue) {
45          this.parameter = parameter;
46          this.attemptedValue = attemptedValue;
47      }
48  
49      /**
50       * @return the errorList
51       */
52      public List<ParameterError> getErrorList() {
53          return errorList;
54      }
55  
56      /**
57       * @param errorList
58       *            the errorList to set
59       */
60      public void setErrorList(List<ParameterError> errorList) {
61          this.errorList = errorList;
62      }
63  
64      /**
65       * @param errorList
66       *            the errorList to add
67       */
68      public void addErrorList(List<ParameterError> errorList) {
69          this.errorList.addAll(errorList);
70      }
71  
72      /**
73       * Adds an error to the list
74       *
75       * @param error
76       *            the error to add
77       */
78      public void addError(ParameterError error) {
79          this.errorList.add(error);
80      }
81  
82      /**
83       * @return the parameter
84       */
85      public IParameter<?> getParameter() {
86          return parameter;
87      }
88  
89      /**
90       * @return the attemptedValue
91       */
92      public Object getAttemptedValue() {
93          return attemptedValue;
94      }
95  
96      /**
97       * @see java.lang.Object#toString()
98       */
99      @Override
100     public String toString() {
101         ObjectFormatter formatter = new ObjectFormatter();
102         formatter.addItem("Parameter", parameter);
103         formatter.addItem("Attempted Value", attemptedValue);
104         formatter.addItem("Error List", errorList);
105 
106         return formatter.getFormatedObject();
107     }
108 }