Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 157   Methods: 32
NCLOC: 69   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
AbstractRelation.java 0% 45.7% 50% 46.4%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK*
 2   
 3    PLT Utilities BSD License
 4   
 5    Copyright (c) 2007-2010 JavaPLT group at Rice University
 6    All rights reserved.
 7   
 8    Developed by: Java Programming Languages Team
 9    Rice University
 10    http://www.cs.rice.edu/~javaplt/
 11   
 12    Redistribution and use in source and binary forms, with or without modification, are permitted
 13    provided that the following conditions are met:
 14   
 15    - Redistributions of source code must retain the above copyright notice, this list of conditions
 16    and the following disclaimer.
 17    - Redistributions in binary form must reproduce the above copyright notice, this list of
 18    conditions and the following disclaimer in the documentation and/or other materials provided
 19    with the distribution.
 20    - Neither the name of the JavaPLT group, Rice University, nor the names of the library's
 21    contributors may be used to endorse or promote products derived from this software without
 22    specific prior written permission.
 23   
 24    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 25    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 26    FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND
 27    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 28    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 29    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 30    IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 31    OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32   
 33    *END_COPYRIGHT_BLOCK*/
 34   
 35    package edu.rice.cs.plt.collect;
 36   
 37    import java.util.Iterator;
 38    import java.io.Serializable;
 39    import edu.rice.cs.plt.tuple.Pair;
 40    import edu.rice.cs.plt.tuple.Option;
 41    import edu.rice.cs.plt.iter.MappedIterator;
 42   
 43    /**
 44    * An abstract parent class for implementations of Relation. Subclasses must provide
 45    * the size methods {@link #isInfinite}, {@link #hasFixedSize}, and {@link #isStatic},
 46    * and the query methods {@link #contains(Object, Object)}, {@link #contains(Object)},
 47    * {@link #iterator}, {@link #firstSet}, {@link #matchFirst}, {@link #secondSet},
 48    * and {@link #matchSecond}. To support mutation, they must also override
 49    * {@link #add(Object, Object)} and {@link #remove(Object, Object)}. For best performance,
 50    * they may also override {@link #isEmpty}, {@link #size(int)} and {@link #clear}.
 51    */
 52    public abstract class AbstractRelation<T1, T2> extends AbstractPredicateSet<Pair<T1, T2>>
 53    implements Relation<T1, T2> {
 54   
 55    public abstract boolean isInfinite();
 56    public abstract boolean hasFixedSize();
 57    public abstract boolean isStatic();
 58   
 59    /**
 60    * Tests whether the given objects appear as a pair in this relation. Not guaranteed
 61    * to have types {@code T1} and {@code T2} because the {@link java.util.Collection#contains}
 62    * method allows arbitrary objects.
 63    */
 64    public abstract boolean contains(T1 first, T2 second);
 65    public abstract boolean contains(Object obj);
 66    public abstract Iterator<Pair<T1, T2>> iterator();
 67    public abstract PredicateSet<T1> firstSet();
 68    public abstract PredicateSet<T2> matchFirst(T1 first);
 69    public abstract PredicateSet<T2> secondSet();
 70    public abstract PredicateSet<T1> matchSecond(T2 second);
 71   
 72  0 public boolean add(T1 first, T2 second) { throw new UnsupportedOperationException(); }
 73  0 public boolean remove(T1 first, T2 second) { throw new UnsupportedOperationException(); }
 74   
 75    /** Invokes {@link #add(Object, Object)}. */
 76  0 public boolean add(Pair<T1, T2> p) { return add(p.first(), p.second()); }
 77   
 78    /** Invokes {@link #remove(Object, Object)} if {@code contains(o)} is {@code true}. */
 79  0 public boolean remove(Object o) {
 80  0 Option<Pair<T1, T2>> cast = CollectUtil.castIfContains(this, o);
 81  0 if (cast.isSome()) { return remove(cast.unwrap().first(), cast.unwrap().second()); }
 82  0 else { return false; }
 83    }
 84   
 85    /** Returns an {@link InverseRelation}. */
 86  3 public Relation<T2, T1> inverse() { return new InverseRelation(); }
 87   
 88    /** Returns {@code firstSet().contains(first)}. */
 89  36 public boolean containsFirst(T1 first) { return firstSet().contains(first); }
 90   
 91    /** Returns {@code secondSet()}. */
 92  30 public PredicateSet<T2> excludeFirsts() { return secondSet(); }
 93   
 94    /** Returns {@code secondSet().contains(second)}. */
 95  66 public boolean containsSecond(T2 second) { return secondSet().contains(second); }
 96   
 97    /** Returns {@code firstSet()}. */
 98  30 public PredicateSet<T1> excludeSeconds() { return firstSet(); }
 99   
 100    /**
 101    * An inverse of the enclosing relation, defined in terms of {@link Pair#inverse}. Mutation is
 102    * supported, with changes reflected in the enclosing relation. Inherits the AbstractSet implementations
 103    * of {@link java.util.AbstractSet#toArray()}, {@link java.util.AbstractSet#toArray(Object[])},
 104    * {@link java.util.AbstractSet#containsAll}, {@link java.util.AbstractSet#addAll},
 105    * {@link java.util.AbstractSet#retainAll}, {@link java.util.AbstractSet#removeAll},
 106    * {@code java.util.AbstractSet#toString()}, {@code equals(Object)}, and {@code hashCode()}. All other
 107    * methods delegate to their corresponding methods in the enclosing AbstractRelation (inverting pairs
 108    * as necessary).
 109    */
 110    protected class InverseRelation extends AbstractPredicateSet<Pair<T2, T1>>
 111    implements Relation<T2, T1>, Serializable {
 112   
 113  24 public int size() { return AbstractRelation.this.size(); }
 114  0 public int size(int bound) { return AbstractRelation.this.size(bound); }
 115  6 @Override public boolean isEmpty() { return AbstractRelation.this.isEmpty(); }
 116  0 public boolean isInfinite() { return AbstractRelation.this.isInfinite(); }
 117  0 public boolean hasFixedSize() { return AbstractRelation.this.hasFixedSize(); }
 118  0 public boolean isStatic() { return AbstractRelation.this.isStatic(); }
 119   
 120  0 @Override public boolean contains(Object o) {
 121  0 return (o instanceof Pair<?, ?>) &&
 122    AbstractRelation.this.contains(((Pair<?, ?>) o).inverse());
 123    }
 124   
 125  9 public Iterator<Pair<T2, T1>> iterator() {
 126  9 return new MappedIterator<Pair<T1, T2>, Pair<T2, T1>>(AbstractRelation.this.iterator(),
 127    Pair.<T1, T2>inverter());
 128    }
 129   
 130  0 @Override public boolean add(Pair<T2, T1> pair) {
 131  0 return AbstractRelation.this.add(pair.inverse());
 132    }
 133   
 134  0 @Override public boolean remove(Object o) {
 135  0 return (o instanceof Pair<?, ?>) &&
 136    AbstractRelation.this.remove(((Pair<?, ?>) o).inverse());
 137    }
 138   
 139  0 @Override public void clear() { AbstractRelation.this.clear(); }
 140   
 141  0 public boolean contains(T2 f, T1 s) { return AbstractRelation.this.contains(s, f); }
 142  0 public boolean add(T2 f, T1 s) { return AbstractRelation.this.add(s, f); }
 143  0 public boolean remove(T2 f, T1 s) { return AbstractRelation.this.remove(s, f); }
 144  0 public Relation<T1, T2> inverse() { return AbstractRelation.this; }
 145   
 146  15 public PredicateSet<T2> firstSet() { return AbstractRelation.this.secondSet(); }
 147  33 public boolean containsFirst(T2 f) { return AbstractRelation.this.containsSecond(f); }
 148  33 public PredicateSet<T1> matchFirst(T2 f) { return AbstractRelation.this.matchSecond(f); }
 149  15 public PredicateSet<T1> excludeFirsts() { return AbstractRelation.this.excludeSeconds(); }
 150   
 151  15 public PredicateSet<T1> secondSet() { return AbstractRelation.this.firstSet(); }
 152  18 public boolean containsSecond(T1 s) { return AbstractRelation.this.containsFirst(s); }
 153  18 public PredicateSet<T2> matchSecond(T1 s) { return AbstractRelation.this.matchFirst(s); }
 154  15 public PredicateSet<T2> excludeSeconds() { return AbstractRelation.this.excludeFirsts(); }
 155    }
 156   
 157    }