Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 112   Methods: 20
NCLOC: 59   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SingletonRelation.java 0% 0% 0% 0%
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.io.Serializable;
 38    import java.util.Iterator;
 39    import edu.rice.cs.plt.tuple.Pair;
 40    import edu.rice.cs.plt.iter.SingletonIterator;
 41    import edu.rice.cs.plt.object.ObjectUtil;
 42   
 43    /** An immutable {@code Relation} containing a single pair. */
 44    public class SingletonRelation<T1, T2> extends AbstractOneToOneRelation<T1, T2> implements Serializable {
 45   
 46    private final T1 _first;
 47    private final T2 _second;
 48   
 49  0 public SingletonRelation(T1 first, T2 second) { _first = first; _second = second; }
 50   
 51  0 public SingletonRelation(Pair<? extends T1, ? extends T2> pair) {
 52  0 _first = pair.first();
 53  0 _second = pair.second();
 54    }
 55   
 56  0 @Override public boolean isEmpty() { return false; }
 57  0 @Override public int size() { return 1; }
 58  0 @Override public int size(int bound) { return (bound < 1) ? bound : 1; }
 59  0 public boolean isInfinite() { return false; }
 60  0 public boolean hasFixedSize() { return true; }
 61  0 public boolean isStatic() { return true; }
 62   
 63  0 public boolean contains(T1 candidate1, T2 candidate2) {
 64  0 return ObjectUtil.equal(candidate1, _first) && ObjectUtil.equal(candidate2, _second);
 65    }
 66   
 67  0 public boolean contains(Object obj) {
 68  0 if (obj instanceof Pair<?, ?>) {
 69  0 Pair<?, ?> p = (Pair<?, ?>) obj;
 70  0 return ObjectUtil.equal(p.first(), _first) && ObjectUtil.equal(p.second(), _second);
 71    }
 72  0 else { return false; }
 73    }
 74   
 75  0 @Override public Iterator<Pair<T1, T2>> iterator() {
 76  0 return new SingletonIterator<Pair<T1, T2>>(Pair.make(_first, _second));
 77    }
 78   
 79  0 public LambdaMap<T1, T2> functionMap() { return new SingletonMap<T1, T2>(_first, _second); }
 80  0 public LambdaMap<T2, T1> injectionMap() { return new SingletonMap<T2, T1>(_second, _first); }
 81   
 82  0 @Override public PredicateSet<T1> firstSet() { return new SingletonSet<T1>(_first); }
 83  0 @Override public PredicateSet<T2> matchFirst(T1 match) {
 84  0 if ((_first == null) ? (match == null) : _first.equals(match)) {
 85  0 return new SingletonSet<T2>(_second);
 86    }
 87  0 else { return EmptySet.make(); }
 88    }
 89   
 90  0 @Override public PredicateSet<T2> secondSet() { return new SingletonSet<T2>(_second); }
 91  0 @Override public PredicateSet<T1> matchSecond(T2 match) {
 92  0 if ((_second == null) ? (match == null) : _second.equals(match)) {
 93  0 return new SingletonSet<T1>(_first);
 94    }
 95  0 else { return EmptySet.make(); }
 96    }
 97   
 98  0 @Override public OneToOneRelation<T2, T1> inverse() {
 99  0 return new SingletonRelation<T2, T1>(_second, _first);
 100    }
 101   
 102    /** Call the constructor (allows type arguments to be inferred) */
 103  0 public static <T1, T2> SingletonRelation<T1, T2> make(T1 first, T2 second) {
 104  0 return new SingletonRelation<T1, T2>(first, second);
 105    }
 106   
 107    /** Call the constructor (allows type arguments to be inferred) */
 108  0 public static <T1, T2> SingletonRelation<T1, T2> make(Pair<? extends T1, ? extends T2> pair) {
 109  0 return new SingletonRelation<T1, T2>(pair);
 110    }
 111   
 112    }