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