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