Clover coverage report - PLT Utilities Test Coverage (plt-20130623-r5436)
Coverage timestamp: Sat Jun 22 2013 22:01:04 CDT
file stats: LOC: 192   Methods: 26
NCLOC: 115   Classes: 6
 
 Source file Conditionals Statements Methods TOTAL
Triple.java 40% 41.7% 42.3% 41.5%
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.tuple;
 36   
 37    import java.io.Serializable;
 38    import java.util.Comparator;
 39   
 40    import edu.rice.cs.plt.collect.CollectUtil;
 41    import edu.rice.cs.plt.collect.TotalOrder;
 42    import edu.rice.cs.plt.lambda.Lambda;
 43    import edu.rice.cs.plt.lambda.Lambda3;
 44    import edu.rice.cs.plt.object.ObjectUtil;
 45   
 46    /**
 47    * An arbitrary 3-tuple of objects; overrides {@link #toString()}, {@link #equals(Object)},
 48    * and {@link #hashCode()}.
 49    */
 50    public class Triple<T1, T2, T3> extends Tuple {
 51   
 52    protected final T1 _first;
 53    protected final T2 _second;
 54    protected final T3 _third;
 55   
 56  10 public Triple(T1 first, T2 second, T3 third) {
 57  10 _first = first;
 58  10 _second = second;
 59  10 _third = third;
 60    }
 61   
 62  2 public T1 first() { return _first; }
 63  2 public T2 second() { return _second; }
 64  2 public T3 third() { return _third; }
 65   
 66  6 public String toString() {
 67  6 return "(" + _first + ", " + _second + ", " + _third + ")";
 68    }
 69   
 70    /**
 71    * @return {@code true} iff {@code this} is of the same class as {@code o}, and each
 72    * corresponding element is equal (according to {@code equals})
 73    */
 74  5 public boolean equals(Object o) {
 75  0 if (this == o) { return true; }
 76  0 else if (o == null || !getClass().equals(o.getClass())) { return false; }
 77    else {
 78  5 Triple<?, ?, ?> cast = (Triple<?, ?, ?>) o;
 79  5 return
 80  5 (_first == null ? cast._first == null : _first.equals(cast._first)) &&
 81  4 (_second == null ? cast._second == null : _second.equals(cast._second)) &&
 82  3 (_third == null ? cast._third == null : _third.equals(cast._third));
 83    }
 84    }
 85   
 86  3 protected int generateHashCode() {
 87  3 return
 88  3 (_first == null ? 0 : _first.hashCode()) ^
 89  3 (_second == null ? 0 : _second.hashCode() << 1) ^
 90  3 (_third == null ? 0 : _third.hashCode() << 2) ^
 91    getClass().hashCode();
 92    }
 93   
 94    /** Call the constructor (allows the type arguments to be inferred) */
 95  4 public static <T1, T2, T3> Triple<T1, T2, T3> make(T1 first, T2 second, T3 third) {
 96  4 return new Triple<T1, T2, T3>(first, second, third);
 97    }
 98   
 99    /** Produce a lambda that invokes the constructor */
 100  1 @SuppressWarnings("unchecked") public static <T1, T2, T3> Lambda3<T1, T2, T3, Triple<T1, T2, T3>> factory() {
 101  1 return (Factory<T1, T2, T3>) Factory.INSTANCE;
 102    }
 103   
 104    private static final class Factory<T1, T2, T3> implements Lambda3<T1, T2, T3, Triple<T1, T2, T3>>, Serializable {
 105    public static final Factory<Object, Object, Object> INSTANCE = new Factory<Object, Object, Object>();
 106  1 private Factory() {}
 107  1 public Triple<T1, T2, T3> value(T1 first, T2 second, T3 third) {
 108  1 return new Triple<T1, T2, T3>(first, second, third);
 109    }
 110    }
 111   
 112    /** Produce a lambda that invokes {@link #first} on a provided triple. */
 113  0 @SuppressWarnings("unchecked") public static <T> Lambda<Triple<? extends T, ?, ?>, T> firstGetter() {
 114  0 return (GetFirst<T>) GetFirst.INSTANCE;
 115    }
 116   
 117    private static final class GetFirst<T> implements Lambda<Triple<? extends T, ?, ?>, T>, Serializable {
 118    public static final GetFirst<Void> INSTANCE = new GetFirst<Void>();
 119  0 private GetFirst() {}
 120  0 public T value(Triple<? extends T, ?, ?> arg) { return arg.first(); }
 121    }
 122   
 123    /** Produce a lambda that invokes {@link #second} on a provided triple. */
 124  0 @SuppressWarnings("unchecked") public static <T> Lambda<Triple<?, ? extends T, ?>, T> secondGetter() {
 125  0 return (GetSecond<T>) GetSecond.INSTANCE;
 126    }
 127   
 128    private static final class GetSecond<T> implements Lambda<Triple<?, ? extends T, ?>, T>, Serializable {
 129    public static final GetSecond<Void> INSTANCE = new GetSecond<Void>();
 130  0 private GetSecond() {}
 131  0 public T value(Triple<?, ? extends T, ?> arg) { return arg.second(); }
 132    }
 133   
 134    /** Produce a lambda that invokes {@link #third} on a provided triple. */
 135  0 @SuppressWarnings("unchecked") public static <T> Lambda<Triple<?, ?, ? extends T>, T> thirdGetter() {
 136  0 return (GetThird<T>) GetThird.INSTANCE;
 137    }
 138   
 139    private static final class GetThird<T> implements Lambda<Triple<?, ?, ? extends T>, T>, Serializable {
 140    public static final GetThird<Void> INSTANCE = new GetThird<Void>();
 141  0 private GetThird() {}
 142  0 public T value(Triple<?, ?, ? extends T> arg) { return arg.third(); }
 143    }
 144   
 145    /**
 146    * Produce a comparator for triples, ordered by the natural order of the elements (the leftmost
 147    * elements have the highest sort priority).
 148    */
 149  0 public static <T1 extends Comparable<? super T1>, T2 extends Comparable<? super T2>,
 150    T3 extends Comparable<? super T3>>
 151    TotalOrder<Triple<? extends T1, ? extends T2, ? extends T3>> comparator() {
 152  0 return new TripleComparator<T1, T2, T3>(CollectUtil.<T1>naturalOrder(), CollectUtil.<T2>naturalOrder(),
 153    CollectUtil.<T3>naturalOrder());
 154    }
 155   
 156    /**
 157    * Produce a comparator for triples, ordered by the given comparators (the leftmost
 158    * elements have the highest sort priority).
 159    */
 160  0 public static <T1, T2, T3> TotalOrder<Triple<? extends T1, ? extends T2, ? extends T3>>
 161    comparator(Comparator<? super T1> comp1, Comparator<? super T2> comp2, Comparator<? super T3> comp3) {
 162  0 return new TripleComparator<T1, T2, T3>(comp1, comp2, comp3);
 163    }
 164   
 165    private static final class TripleComparator<T1, T2, T3>
 166    extends TotalOrder<Triple<? extends T1, ? extends T2, ? extends T3>> {
 167    private final Comparator<? super T1> _comp1;
 168    private final Comparator<? super T2> _comp2;
 169    private final Comparator<? super T3> _comp3;
 170  0 public TripleComparator(Comparator<? super T1> comp1, Comparator<? super T2> comp2,
 171    Comparator<? super T3> comp3) {
 172  0 _comp1 = comp1;
 173  0 _comp2 = comp2;
 174  0 _comp3 = comp3;
 175    }
 176  0 public int compare(Triple<? extends T1, ? extends T2, ? extends T3> t1,
 177    Triple<? extends T1, ? extends T2, ? extends T3> t2) {
 178  0 return ObjectUtil.compare(_comp1, t1.first(), t2.first(), _comp2, t1.second(), t2.second(),
 179    _comp3, t1.third(), t2.third());
 180    }
 181  0 public boolean equals(Object o) {
 182  0 if (this == o) { return true; }
 183  0 else if (!(o instanceof TripleComparator<?,?,?>)) { return false; }
 184    else {
 185  0 TripleComparator<?,?,?> cast = (TripleComparator<?,?,?>) o;
 186  0 return _comp1.equals(cast._comp1) && _comp2.equals(cast._comp2) && _comp3.equals(cast._comp3);
 187    }
 188    }
 189  0 public int hashCode() { return ObjectUtil.hash(TripleComparator.class, _comp1, _comp2, _comp3); }
 190    }
 191   
 192    }