1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.qedeq.kernel.se.common;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.qedeq.base.utility.EqualsUtility;
22
23
24
25
26
27
28
29 public class SourceFileExceptionList extends Exception {
30
31
32 private final List exceptions = new ArrayList();
33
34
35
36
37 public SourceFileExceptionList() {
38 }
39
40
41
42
43
44
45 public SourceFileExceptionList(final SourceFileException e) {
46 if (e != null) {
47 add(e);
48 }
49 }
50
51
52
53
54
55
56 public SourceFileExceptionList(final SourceFileExceptionList e) {
57 if (e != null) {
58 for (int i = 0; i < e.size(); i++) {
59 add(e.get(i));
60 }
61 }
62 }
63
64
65
66
67 public void clear() {
68 exceptions.clear();
69 }
70
71
72
73
74
75
76 public void add(final SourceFileException e) {
77 if (e == null) {
78 return;
79 }
80 if (size() == 0) {
81 initCause(e);
82 }
83 if (!exceptions.contains(e)) {
84 exceptions.add(e);
85 }
86 }
87
88
89
90
91
92
93 public void add(final SourceFileExceptionList e) {
94 if (e == null) {
95 return;
96 }
97 for (int i = 0; i < e.size(); i++) {
98 if (size() == 0) {
99 initCause(e.get(i));
100 }
101 if (!exceptions.contains(e.get(i))) {
102 exceptions.add(e.get(i));
103 }
104 }
105 }
106
107
108
109
110
111
112 public final int size() {
113 return exceptions.size();
114 }
115
116
117
118
119
120
121
122 public final SourceFileException get(final int i) {
123 return (SourceFileException) exceptions.get(i);
124 }
125
126
127
128
129
130
131 public final SourceFileException[] toArray() {
132 return (SourceFileException[]) exceptions.toArray(
133 new SourceFileException[exceptions.size()]);
134 }
135
136 public int hashCode() {
137 int result = 71;
138 for (int i = 0; i < size(); i++) {
139 result = result ^ (get(i) != null ? get(i).hashCode() : 0);
140 }
141 return result;
142 }
143
144 public boolean equals(final Object object) {
145 if (!(object instanceof SourceFileExceptionList)) {
146 return false;
147 }
148 SourceFileExceptionList sfl = (SourceFileExceptionList) object;
149 if (size() != sfl.size()) {
150 return false;
151 }
152 for (int i = 0; i < size(); i++) {
153 if (!EqualsUtility.equals(get(i), sfl.get(i))) {
154 return false;
155 }
156 }
157 return true;
158 }
159
160 public String getMessage() {
161 final StringBuffer buffer = new StringBuffer();
162 for (int i = 0; i < size(); i++) {
163 if (i != 0) {
164 buffer.append("\n");
165 }
166 final SourceFileException e = get(i);
167 buffer.append(i).append(": ");
168 buffer.append(e.toString());
169 }
170 return buffer.toString();
171 }
172
173 public String toString() {
174 final StringBuffer buffer = new StringBuffer();
175 buffer.append(getClass().getName());
176 buffer.append("\n");
177 buffer.append(getMessage());
178 return buffer.toString();
179 }
180
181 }