Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart0.png 96% of files have more coverage
62   276   33   3.88
34   130   0.53   16
16     2.06  
1    
 
  EqualFormulaSet       Line # 33 62 33 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.logic.work;
17   
18    import java.util.Arrays;
19    import java.util.HashSet;
20    import java.util.Iterator;
21    import java.util.List;
22    import java.util.Set;
23   
24    import org.qedeq.kernel.se.base.list.Element;
25    import org.qedeq.kernel.se.base.list.ElementList;
26   
27   
28    /**
29    * This class represents a set of {@link Element}s.
30    *
31    * @version $Revision: 1.1 $
32    */
 
33    public class EqualFormulaSet {
34   
35    /** Here are the formulas stored. */
36    private final Set formulas;
37   
38    /** Error message: NullPointer as element is not allowed. */
39    private static final String NULLPOINTER_AS_WORD_IS_NOT_ALLOWED
40    = "NullPointer as element is not allowed";
41   
42    /** Error message: NullPointer as set is not allowed. */
43    private static final String NULLPOINTER_AS_SET_IS_NOT_ALLOWED
44    = "NullPointer as set is not allowed";
45   
46   
47    /**
48    * Constructs an empty element set.
49    *
50    */
 
51  0 toggle public EqualFormulaSet() {
52  0 this.formulas = new HashSet();
53    }
54   
55    /**
56    * Constructs an element set.
57    *
58    * @param formulas the elements to put into the set
59    * @throws IllegalArgumentException if <code>elements</code> was a
60    * NullPointer
61    */
 
62  0 toggle public EqualFormulaSet(final EqualFormula[] formulas) {
63  0 if (formulas == null) {
64  0 throw new IllegalArgumentException(
65    "NullPointer as element array is not allowed");
66    }
67  0 this.formulas = new HashSet(Arrays.asList(formulas));
68    }
69   
70    /**
71    * Constructs an equal formulas set.
72    *
73    * @param set Contains the elements to put into the set.
74    * @throws IllegalArgumentException <code>set</code> was a
75    * NullPointer.
76    */
 
77  0 toggle EqualFormulaSet(final EqualFormulaSet set) {
78  0 if (set == null) {
79  0 throw new IllegalArgumentException(
80    NULLPOINTER_AS_SET_IS_NOT_ALLOWED);
81    }
82  0 this.formulas = new HashSet(set.formulas);
83    }
84   
85    /**
86    * Constructs an element set from all operands of an element.
87    * The element must not be a symbol.
88    *
89    * @param element Contains the elements to put into the set
90    * (without the operator).
91    * @throws IllegalArgumentException <code>element</code> was a
92    * NullPointer or was an atom.
93    */
 
94  0 toggle public EqualFormulaSet(final ElementList element) {
95  0 if (element == null) {
96  0 throw new IllegalArgumentException(NULLPOINTER_AS_WORD_IS_NOT_ALLOWED);
97    }
98  0 if (element.isAtom()) {
99  0 throw new IllegalArgumentException(
100    "atom as element is not allowed");
101    }
102  0 List list = element.getElements();
103  0 this.formulas = new HashSet();
104  0 for (int i = 0; i < list.size(); i++) {
105  0 this.formulas.add(new EqualFormula((Element) list.get(i)));
106    }
107    }
108   
109    /**
110    * Is element in set?
111    *
112    * @param formula Element to check for.
113    * @return Is <code>formula</code> in this set?
114    * @throws IllegalArgumentException <code>element</code> was a
115    * NullPointer.
116    */
 
117  0 toggle public final boolean contains(final EqualFormula formula) {
118  0 if (formula == null) {
119  0 throw new IllegalArgumentException(NULLPOINTER_AS_WORD_IS_NOT_ALLOWED);
120    }
121  0 return this.formulas.contains(formula);
122    }
123   
124    /**
125    * Is set empty?
126    *
127    * @return Is this set empty?
128    */
 
129  0 toggle public final boolean isEmpty() {
130  0 return formulas.isEmpty();
131    }
132   
133    /**
134    * Is <code>set</code> a subset of this set?
135    *
136    * @param set set to check for.
137    * @return is <code>set</code> a subset of this set?
138    * @throws IllegalArgumentException <code>set</code> was a
139    * NullPointer
140    */
 
141  0 toggle public final boolean isSubset(final EqualFormulaSet set) {
142  0 if (set == null) {
143  0 throw new IllegalArgumentException(NULLPOINTER_AS_SET_IS_NOT_ALLOWED);
144    }
145  0 return this.formulas.containsAll(set.formulas);
146    }
147   
148    /**
149    * Add a formula to set. This object is after the method the
150    * union of this set with <code>element</code>
151    *
152    * @param formula FormulaOrTerm to put into the set.
153    * @return <code>this</code>.
154    * @throws IllegalArgumentException <code>formula</code> was a
155    * NullPointer.
156    */
 
157  0 toggle public final EqualFormulaSet add(final EqualFormula formula) {
158  0 if (formula == null) {
159  0 throw new IllegalArgumentException(NULLPOINTER_AS_WORD_IS_NOT_ALLOWED);
160    }
161  0 formulas.add(formula);
162  0 return this;
163    }
164   
165    /**
166    * After this method this object is the union of the two sets.
167    *
168    * @param set Add all formulas that are here in.
169    * @return <code>this</code>.
170    * @throws IllegalArgumentException <code>set</code> was a NullPointer.
171    */
 
172  0 toggle public final EqualFormulaSet union(final EqualFormulaSet set) {
173  0 if (set == null) {
174  0 throw new IllegalArgumentException(NULLPOINTER_AS_SET_IS_NOT_ALLOWED);
175    }
176  0 formulas.addAll(set.formulas);
177  0 return this;
178    }
179   
180    /**
181    * Remove an element from set.
182    *
183    * @param formula FormulaOrTerm to remove from the set
184    * @return <code>this</code>.
185    * @throws IllegalArgumentException <code>formula</code> was a NullPointer.
186    */
 
187  0 toggle public final EqualFormulaSet remove(final EqualFormula formula) {
188  0 if (formula == null) {
189  0 throw new IllegalArgumentException(NULLPOINTER_AS_WORD_IS_NOT_ALLOWED);
190    }
191  0 formulas.remove(formula);
192  0 return this;
193    }
194   
195    /**
196    * Remove elements from another {@link EqualFormulaSet} from this set.
197    * After this method this object is the asymmetric set difference of the
198    * two sets: <code>this</code> \ <code>set</code>.
199    *
200    * @param set Remove all elements that are in this set from
201    * <code>this</code>.
202    * @return Was <code>this</code> set changed?
203    * @throws IllegalArgumentException <code>set</code> was a
204    * NullPointer
205    */
 
206  0 toggle public final EqualFormulaSet minus(final EqualFormulaSet set) {
207  0 if (set == null) {
208  0 throw new IllegalArgumentException(NULLPOINTER_AS_SET_IS_NOT_ALLOWED);
209    }
210  0 this.formulas.removeAll(set.formulas);
211  0 return this;
212    }
213   
214    /**
215    * Build the intersection.
216    *
217    * @param set Check for these elements.
218    * @return Has <code>this</code> set changed?
219    * @throws IllegalArgumentException <code>set</code> was a
220    * NullPointer
221    */
 
222  0 toggle public final EqualFormulaSet intersection(final EqualFormulaSet set) {
223  0 if (set == null) {
224  0 throw new IllegalArgumentException(NULLPOINTER_AS_SET_IS_NOT_ALLOWED);
225    }
226  0 this.formulas.retainAll(set.formulas);
227  0 return this;
228    }
229   
230    /**
231    * Build a new intersection.
232    *
233    * @param set check for these elements
234    * @return was <code>this</code> set changed?
235    * @throws IllegalArgumentException if the set was a
236    * NullPointer
237    */
 
238  0 toggle public final EqualFormulaSet newIntersection(final EqualFormulaSet set) {
239  0 if (set == null) {
240  0 throw new IllegalArgumentException(
241    NULLPOINTER_AS_SET_IS_NOT_ALLOWED);
242    }
243  0 final EqualFormulaSet result = new EqualFormulaSet(this);
244  0 result.formulas.retainAll(set.formulas);
245  0 return result;
246    }
247   
 
248  0 toggle public final boolean equals(final Object obj) {
249  0 if (obj == null) {
250  0 return false;
251    }
252  0 if (obj.getClass() == EqualFormulaSet.class) {
253  0 return this.formulas.equals(((EqualFormulaSet) obj).formulas);
254    }
255  0 return false;
256    }
257   
 
258  0 toggle public final int hashCode() {
259  0 return formulas.hashCode();
260    }
261   
 
262  0 toggle public final String toString() {
263  0 final StringBuffer result = new StringBuffer();
264  0 result.append("{");
265  0 final Iterator iterator = formulas.iterator();
266  0 while (iterator.hasNext()) {
267  0 result.append(iterator.next());
268  0 if (iterator.hasNext()) {
269  0 result.append(", ");
270    }
271    }
272  0 result.append("}");
273  0 return result.toString();
274    }
275   
276    }