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