Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../img/srcFileCovDistChart0.png 96% of files have more coverage
67   290   36   3.53
34   139   0.54   19
19     1.89  
1    
 
  KernelQedeqBoSet       Line # 32 67 36 0% 0.0
 
No Tests
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.bo.module;
17   
18    import java.util.Arrays;
19    import java.util.HashSet;
20    import java.util.Iterator;
21    import java.util.Set;
22   
23    import org.qedeq.kernel.bo.common.QedeqBo;
24    import org.qedeq.kernel.bo.common.QedeqBoSet;
25   
26   
27    /**
28    * This class represents a set of {@link KernelQedeqBo}s.
29    *
30    * @author Michael Meyling
31    */
 
32    public class KernelQedeqBoSet implements QedeqBoSet {
33   
34   
35    /** Here are the elements stored. */
36    private final Set elements;
37   
38   
39    /**
40    * Constructs an empty element set.
41    */
 
42  0 toggle public KernelQedeqBoSet() {
43  0 this.elements = new HashSet();
44    }
45   
46   
47    /**
48    * Constructs an element set.
49    *
50    * @param elements the elements to put into the set
51    * @throws IllegalArgumentException if <code>elements</code> was a NullPointer
52    */
 
53  0 toggle public KernelQedeqBoSet(final KernelQedeqBo[] elements) {
54  0 if (elements == null) {
55  0 throw new IllegalArgumentException(
56    "NullPointer as element array is not allowed");
57    }
58  0 this.elements = new HashSet(Arrays.asList(elements));
59    }
60   
61    /**
62    * Constructs an element set.
63    *
64    * @param element Put this element into the set
65    * @throws IllegalArgumentException if <code>element</code> was a NullPointer
66    */
 
67  0 toggle public KernelQedeqBoSet(final KernelQedeqBo element) {
68  0 if (element == null) {
69  0 throw new IllegalArgumentException(
70    "NullPointer as element array is not allowed");
71    }
72  0 this.elements = new HashSet();
73  0 elements.add(element);
74    }
75   
76    /**
77    * Constructs an element set.
78    *
79    * @param set contains the elements to put into the set
80    * @throws IllegalArgumentException if <code>set</code> was a
81    * NullPointer
82    */
 
83  0 toggle public KernelQedeqBoSet(final KernelQedeqBoSet set) {
84  0 if (set == null) {
85  0 throw new IllegalArgumentException(
86    "NullPointer as set is not allowed");
87    }
88  0 this.elements = new HashSet(set.elements);
89    }
90   
91   
92    /**
93    * Is element in set?
94    *
95    * @param element KernelQedeqBo to check for.
96    * @return Is <code>element</code> in this set?
97    * @throws IllegalArgumentException if the element was a
98    * NullPointer
99    */
 
100  0 toggle public final boolean contains(final KernelQedeqBo element) {
101  0 if (element == null) {
102  0 throw new IllegalArgumentException("NullPointer as element is not allowed");
103    }
104  0 return this.elements.contains(element);
105    }
106   
 
107  0 toggle public boolean contains(final QedeqBo element) {
108  0 if (element == null) {
109  0 throw new IllegalArgumentException("NullPointer as element is not allowed");
110    }
111  0 return this.elements.contains(element);
112    }
113   
114    /**
115    * Is this set empty?
116    *
117    * @return Is this set empty?
118    */
 
119  0 toggle public final boolean isEmpty() {
120  0 return elements.isEmpty();
121    }
122   
123   
124    /**
125    * Add an element to set. This object is after the method the
126    * union of this set with {<code>element</code>}
127    *
128    * @param element element to put into the set
129    * @return Possibly changed <code>this</code>.
130    * @throws IllegalArgumentException if the element was a
131    * NullPointer
132    */
 
133  0 toggle public final KernelQedeqBoSet add(final KernelQedeqBo element) {
134  0 if (element == null) {
135  0 throw new IllegalArgumentException("NullPointer as element is not allowed");
136    }
137  0 elements.add(element);
138  0 return this;
139    }
140   
141   
142    /**
143    * Add elements from another {@link KernelQedeqBoSet} to this set.
144    * After this method this object is the union of the two sets.
145    *
146    * @param set add all elements that are here
147    * @return Possibly changed <code>this</code>.
148    * @throws IllegalArgumentException if the set was a
149    * NullPointer
150    */
 
151  0 toggle public final KernelQedeqBoSet add(final KernelQedeqBoSet set) {
152  0 if (set == null) {
153  0 throw new IllegalArgumentException(
154    "NullPointer as set is not allowed");
155    }
156  0 elements.addAll(set.elements);
157  0 return this;
158    }
159   
160   
161    /**
162    * Remove an element from this set.
163    *
164    * @param element KernelQedeqBo to remove from the set. Must not be <code>null</code>.
165    * @return Possibly changed <code>this</code>.
166    * @throws IllegalArgumentException if the element was a
167    * NullPointer
168    */
 
169  0 toggle public final KernelQedeqBoSet remove(final KernelQedeqBo element) {
170  0 if (element == null) {
171  0 throw new IllegalArgumentException(
172    "NullPointer as element is not allowed");
173    }
174  0 elements.remove(element);
175  0 return this;
176    }
177   
178   
179    /**
180    * Remove elements from another {@link KernelQedeqBoSet} from this set.
181    * After this method this object is the asymmetric set difference of the
182    * two sets: <code>this</code> \ <code>set</code>.
183    *
184    * @param set Remove all elements that are in this set from
185    * <code>this</code>.
186    * @return Possibly changed <code>this</code>.
187    * @throws IllegalArgumentException if the set was a
188    * NullPointer
189    */
 
190  0 toggle public final KernelQedeqBoSet remove(final KernelQedeqBoSet set) {
191  0 if (set == null) {
192  0 throw new IllegalArgumentException(
193    "NullPointer as set is not allowed");
194    }
195  0 this.elements.removeAll(set.elements);
196  0 return this;
197    }
198   
199   
200    /**
201    * Build the intersection.
202    *
203    * @param set Check for these elements.
204    * @return Possibly changed <code>this</code>.
205    * @throws IllegalArgumentException if the set was a
206    * NullPointer
207    */
 
208  0 toggle public final KernelQedeqBoSet intersection(final KernelQedeqBoSet set) {
209  0 if (set == null) {
210  0 throw new IllegalArgumentException(
211    "NullPointer as set is not allowed");
212    }
213  0 this.elements.retainAll(set.elements);
214  0 return this;
215    }
216   
217   
218    /**
219    * Get number of elements.
220    *
221    * @return Number of elements in this set.
222    */
 
223  0 toggle public final int size() {
224  0 return this.elements.size();
225    }
226   
227    /**
228    * Returns an iterator over the elements in this set. The elements are
229    * returned in no particular order (unless this set is an instance of some
230    * class that provides a guarantee).
231    *
232    * @return Iterator over the elements in this set.
233    */
 
234  0 toggle public Iterator iterator() {
235  0 return this.elements.iterator();
236    }
237   
 
238  0 toggle public final boolean equals(final Object obj) {
239  0 if (obj instanceof KernelQedeqBoSet) {
240  0 return this.elements.equals(((KernelQedeqBoSet) obj).elements);
241    }
242  0 return false;
243    }
244   
 
245  0 toggle public final int hashCode() {
246  0 return elements.hashCode();
247    }
248   
 
249  0 toggle public final String toString() {
250  0 final StringBuffer result = new StringBuffer();
251  0 result.append("{");
252  0 final Iterator iterator = elements.iterator();
253  0 while (iterator.hasNext()) {
254  0 result.append(iterator.next());
255  0 if (iterator.hasNext()) {
256  0 result.append(", ");
257    }
258    }
259  0 result.append("}");
260  0 return result.toString();
261    }
262   
263   
 
264  0 toggle public String asLongList() {
265  0 final StringBuffer result = new StringBuffer();
266  0 final Iterator iterator = elements.iterator();
267  0 while (iterator.hasNext()) {
268  0 result.append(((QedeqBo) iterator.next()).getUrl());
269  0 if (iterator.hasNext()) {
270  0 result.append(", ");
271    }
272    }
273  0 return result.toString();
274    }
275   
276   
 
277  0 toggle public String asShortList() {
278  0 final StringBuffer result = new StringBuffer();
279  0 final Iterator iterator = elements.iterator();
280  0 while (iterator.hasNext()) {
281  0 result.append(((QedeqBo) iterator.next()).getName());
282  0 if (iterator.hasNext()) {
283  0 result.append(", ");
284    }
285    }
286  0 return result.toString();
287    }
288   
289   
290    }