Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 116   Methods: 16
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
UnionRelation.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.util.Iterator;
 38    import java.io.Serializable;
 39    import edu.rice.cs.plt.iter.ImmutableIterator;
 40    import edu.rice.cs.plt.iter.ComposedIterator;
 41    import edu.rice.cs.plt.iter.IterUtil;
 42    import edu.rice.cs.plt.tuple.Pair;
 43    import edu.rice.cs.plt.object.Composite;
 44    import edu.rice.cs.plt.object.ObjectUtil;
 45   
 46    /**
 47    * The union of two relations, lazily constructed and updated dynamically.
 48    */
 49    public class UnionRelation<T1, T2> extends AbstractRelation<T1, T2> implements Composite, Serializable {
 50    private final Relation<T1, T2> _rel1;
 51    private final Relation<T1, T2> _rel2;
 52    private final Relation<T1, T2> _rel2Extras;
 53   
 54    /**
 55    * For best performance of {@link #size}, {@code rel2} should be the smaller of the two
 56    * relations (this is not handled automatically because calculating sizes may be expensive).
 57    */
 58  0 public UnionRelation(Relation<T1, T2> rel1, Relation<T1, T2> rel2) {
 59  0 _rel1 = rel1;
 60  0 _rel2 = rel2;
 61  0 _rel2Extras = new ComplementRelation<T1, T2>(rel2, rel1);
 62    }
 63   
 64  0 public int compositeHeight() { return ObjectUtil.compositeHeight(_rel1, _rel2) + 1; }
 65  0 public int compositeSize() { return ObjectUtil.compositeSize(_rel1, _rel2) + 1; }
 66   
 67  0 public boolean contains(T1 first, T2 second) {
 68  0 return _rel1.contains(first, second) || _rel2.contains(first, second);
 69    }
 70   
 71  0 public boolean contains(Object o) {
 72  0 return _rel1.contains(o) || _rel2.contains(o);
 73    }
 74   
 75  0 public Iterator<Pair<T1, T2>> iterator() {
 76  0 return ImmutableIterator.make(ComposedIterator.make(_rel1.iterator(), _rel2Extras.iterator()));
 77    }
 78   
 79  0 public PredicateSet<T1> firstSet() {
 80  0 return new UnionSet<T1>(_rel1.firstSet(), _rel2.firstSet());
 81    }
 82   
 83  0 public PredicateSet<T2> matchFirst(T1 first) {
 84  0 return new UnionSet<T2>(_rel1.matchFirst(first), _rel2.matchFirst(first));
 85    }
 86   
 87  0 public PredicateSet<T2> secondSet() {
 88  0 return new UnionSet<T2>(_rel1.secondSet(), _rel2.secondSet());
 89    }
 90   
 91  0 public PredicateSet<T1> matchSecond(T2 second) {
 92  0 return new UnionSet<T1>(_rel1.matchSecond(second), _rel2.matchSecond(second));
 93    }
 94   
 95  0 public boolean isInfinite() { return IterUtil.isInfinite(_rel1) || IterUtil.isInfinite(_rel2); }
 96  0 public boolean hasFixedSize() { return IterUtil.hasFixedSize(_rel1) && IterUtil.hasFixedSize(_rel2); }
 97  0 public boolean isStatic() { return IterUtil.isStatic(_rel1) && IterUtil.isStatic(_rel2); }
 98   
 99   
 100    /** Linear in the size of {@code rel2}. */
 101  0 @Override public int size() {
 102  0 return _rel1.size() + _rel2Extras.size();
 103    }
 104   
 105  0 @Override public int size(int bound) {
 106  0 int size1 = IterUtil.sizeOf(_rel1, bound);
 107  0 int bound2 = bound - size1;
 108  0 int size2 = (bound2 > 0) ? IterUtil.sizeOf(_rel2Extras, bound) : 0;
 109  0 return size1 + size2;
 110    }
 111   
 112  0 @Override public boolean isEmpty() {
 113  0 return _rel1.isEmpty() && _rel2.isEmpty();
 114    }
 115   
 116    }