Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 66   Methods: 20
NCLOC: 40   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
UnindexedRelation.java - 55% 55% 55%
coverage coverage
 1    package edu.rice.cs.plt.collect;
 2   
 3    import java.util.Iterator;
 4    import java.util.Set;
 5   
 6    import edu.rice.cs.plt.iter.IterUtil;
 7    import edu.rice.cs.plt.lambda.Thunk;
 8    import edu.rice.cs.plt.tuple.Pair;
 9   
 10    /**
 11    * A mutable relation implemented by wrapping a set of pairs. The iteration order and performance
 12    * characteristics of the relation match that of the underlying set. Lookup operations like
 13    * {@link #matchFirst()} are not optimized with an index, and thus have poor performance. This class
 14    * is useful when the relation is expected to be small, or when low allocation cost, a small memory
 15    * footprint, and iteration order are more important than performance of index-related operations.
 16    */
 17    public class UnindexedRelation<T1, T2> extends AbstractRelation<T1, T2> {
 18   
 19    private final Set<Pair<T1, T2>> _pairs;
 20   
 21    /** Create an UnindexedRelation wrapping a HashSet. */
 22  1 public UnindexedRelation() { this(CollectUtil.<Pair<T1, T2>>hashSetFactory()); }
 23   
 24    /** Create an UnindexedRelation wrapping an instance of the provided set. */
 25  1 public UnindexedRelation(Thunk<Set<Pair<T1, T2>>> setFactory) { _pairs = setFactory.value(); }
 26   
 27  4 @Override public boolean isEmpty() { return _pairs.isEmpty(); }
 28  16 @Override public int size() { return _pairs.size(); }
 29  0 public boolean hasFixedSize() { return false; }
 30  0 public boolean isInfinite() { return false; }
 31  0 public boolean isStatic() { return false; }
 32   
 33  0 public boolean contains(T1 first, T2 second) { return _pairs.contains(new Pair<T1, T2>(first, second)); }
 34  0 public boolean contains(Object obj) { return _pairs.contains(obj); }
 35  6 public Iterator<Pair<T1, T2>> iterator() { return _pairs.iterator(); }
 36   
 37  5 @Override public boolean add(T1 first, T2 second) { return _pairs.add(new Pair<T1, T2>(first, second)); }
 38  0 @Override public boolean remove(T1 first, T2 second) { return _pairs.remove(new Pair<T1, T2>(first, second)); }
 39  1 @Override public void clear() { _pairs.clear(); }
 40   
 41  32 public PredicateSet<T1> firstSet() { return new LazyRelationIndex<T1, T2>(_pairs).keys(); }
 42  12 public PredicateSet<T2> matchFirst(T1 first) { return new LazyRelationIndex<T1, T2>(_pairs).match(first); }
 43  42 public PredicateSet<T2> secondSet() {
 44  42 return new LazyRelationIndex<T2, T1>(IterUtil.map(_pairs, Pair.<T1, T2>inverter())).keys();
 45    }
 46  22 public PredicateSet<T1> matchSecond(T2 second) {
 47  22 return new LazyRelationIndex<T2, T1>(IterUtil.map(_pairs, Pair.<T1, T2>inverter())).match(second);
 48    }
 49   
 50    /** Make an UnindexedRelation wrapping a {@link java.util.HashSet}. */
 51  0 public static <T1, T2> UnindexedRelation<T1, T2> makeHashBased() {
 52  0 return new UnindexedRelation<T1, T2>(CollectUtil.<Pair<T1, T2>>hashSetFactory());
 53    }
 54   
 55    /** Make an UnindexedRelation wrapping a {@link java.util.LinkedHashSet}. */
 56  0 public static <T1, T2> UnindexedRelation<T1, T2> makeLinkedHashBased() {
 57  0 return new UnindexedRelation<T1, T2>(CollectUtil.<Pair<T1, T2>>linkedHashSetFactory());
 58    }
 59   
 60    /** Make an UnindexedRelation wrapping a {@link java.util.TreeSet}. */
 61  0 public static <T1 extends Comparable<? super T1>, T2 extends Comparable<? super T2>>
 62    UnindexedRelation<T1, T2> makeTreeBased() {
 63  0 return new UnindexedRelation<T1, T2>(CollectUtil.<Pair<T1, T2>>treeSetFactory(Pair.<T1, T2>comparator()));
 64    }
 65   
 66    }