|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| IdentityQuad.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 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 edu.rice.cs.plt.lambda.Lambda4; | |
| 39 | ||
| 40 | /** | |
| 41 | * A quad that defines {@link #equals} and {@link #hashCode} in terms of its elements' | |
| 42 | * identity ({@code ==}) instead of equality (@code equals}) | |
| 43 | */ | |
| 44 | public class IdentityQuad<T1, T2, T3, T4> extends Quad<T1, T2, T3, T4> { | |
| 45 | ||
| 46 | 0 | public IdentityQuad(T1 first, T2 second, T3 third, T4 fourth) { |
| 47 | 0 | super(first, second, third, fourth); |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * @return {@code true} iff {@code this} is of the same class as {@code o}, and each | |
| 52 | * corresponding element is identical (according to {@code ==}) | |
| 53 | */ | |
| 54 | 0 | public boolean equals(Object o) { |
| 55 | 0 | if (this == o) { return true; } |
| 56 | 0 | else if (o == null || !getClass().equals(o.getClass())) { return false; } |
| 57 | else { | |
| 58 | 0 | Quad<?, ?, ?, ?> cast = (Quad<?, ?, ?, ?>) o; |
| 59 | 0 | return |
| 60 | _first == cast._first && | |
| 61 | _second == cast._second && | |
| 62 | _third == cast._third && | |
| 63 | _fourth == cast._fourth; | |
| 64 | } | |
| 65 | } | |
| 66 | ||
| 67 | 0 | protected int generateHashCode() { |
| 68 | 0 | return |
| 69 | System.identityHashCode(_first) ^ | |
| 70 | (System.identityHashCode(_second) << 1) ^ | |
| 71 | (System.identityHashCode(_third) << 2) ^ | |
| 72 | (System.identityHashCode(_fourth) << 3) ^ | |
| 73 | getClass().hashCode(); | |
| 74 | } | |
| 75 | ||
| 76 | /** Call the constructor (allows the type arguments to be inferred) */ | |
| 77 | 0 | public static <T1, T2, T3, T4> IdentityQuad<T1, T2, T3, T4> make(T1 first, T2 second, T3 third, |
| 78 | T4 fourth) { | |
| 79 | 0 | return new IdentityQuad<T1, T2, T3, T4>(first, second, third, fourth); |
| 80 | } | |
| 81 | ||
| 82 | /** Produce a lambda that invokes the constructor */ | |
| 83 | 0 | @SuppressWarnings("unchecked") public static |
| 84 | <T1, T2, T3, T4> Lambda4<T1, T2, T3, T4, Quad<T1, T2, T3, T4>> factory() { | |
| 85 | 0 | return (Factory<T1, T2, T3, T4>) Factory.INSTANCE; |
| 86 | } | |
| 87 | ||
| 88 | ||
| 89 | private static final class Factory<T1, T2, T3, T4> | |
| 90 | implements Lambda4<T1, T2, T3, T4, Quad<T1, T2, T3, T4>>, Serializable { | |
| 91 | public static final Factory<Object, Object, Object, Object> INSTANCE = | |
| 92 | new Factory<Object, Object, Object, Object>(); | |
| 93 | 0 | private Factory() {} |
| 94 | 0 | public Quad<T1, T2, T3, T4> value(T1 first, T2 second, T3 third, T4 fourth) { |
| 95 | 0 | return new IdentityQuad<T1, T2, T3, T4>(first, second, third, fourth); |
| 96 | } | |
| 97 | } | |
| 98 | ||
| 99 | } |
|
||||||||||