1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.util;
17
18
19 import org.apache.commons.lang.ArrayUtils;
20 import org.apache.commons.lang.StringUtils;
21
22 import java.io.Serializable;
23 import java.util.Arrays;
24
25
26
27
28
29
30
31 public class ErrorMessage implements Serializable {
32 private String errorKey;
33 private String[] messageParameters;
34
35
36
37
38 public ErrorMessage() {
39 }
40
41
42
43
44
45
46
47 public ErrorMessage(String errorKey, String... messageParameters) {
48 if (StringUtils.isBlank(errorKey)) {
49 throw new IllegalArgumentException("invalid (blank) errorKey");
50 }
51
52 setErrorKey(errorKey);
53 setMessageParameters((String[]) ArrayUtils.clone(messageParameters));
54 }
55
56
57 public void setErrorKey(String errorKey) {
58 if (StringUtils.isBlank(errorKey)) {
59 throw new IllegalArgumentException("invalid (blank) errorKey");
60 }
61
62 this.errorKey = errorKey;
63 }
64
65 public String getErrorKey() {
66 return errorKey;
67 }
68
69
70 public void setMessageParameters(String[] messageParameters) {
71 this.messageParameters = messageParameters;
72 }
73
74 public String[] getMessageParameters() {
75 return messageParameters;
76 }
77
78
79
80
81
82 @Override
83 public String toString() {
84 StringBuffer s = new StringBuffer(getErrorKey());
85
86 String[] params = getMessageParameters();
87 if (params != null) {
88 s.append("(");
89 for (int i = 0; i < params.length; ++i) {
90 if (i > 0) {
91 s.append(", ");
92 }
93 s.append(params[i]);
94 }
95 s.append(")");
96 }
97 return s.toString();
98 }
99
100
101
102
103
104
105 @Override
106 public boolean equals(Object obj) {
107 boolean equals = false;
108
109 if (this == obj) {
110 equals = true;
111 }
112 else if (obj instanceof ErrorMessage) {
113 ErrorMessage other = (ErrorMessage) obj;
114
115 if (StringUtils.equals(getErrorKey(), other.getErrorKey())) {
116 equals = Arrays.equals(getMessageParameters(), other.getMessageParameters());
117 }
118 }
119
120 return equals;
121 }
122
123
124
125
126
127
128 @Override
129 public int hashCode() {
130 int hashCode = 5011966;
131
132 if (getErrorKey() != null) {
133 hashCode = getErrorKey().hashCode();
134 }
135
136 return hashCode;
137 }
138 }