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