| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| EquivalenceTester |
|
| 0.0;0 | ||||
| EquivalenceTester$1 |
|
| 0.0;0 | ||||
| EquivalenceTester$2 |
|
| 0.0;0 |
| 1 | /* | |
| 2 | Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. | |
| 3 | Licensed under the Academic Free License version 3.0 | |
| 4 | */ | |
| 5 | ||
| 6 | package jaggregate.internal; | |
| 7 | ||
| 8 | import static java.lang.System.*; | |
| 9 | ||
| 10 | import jaggregate.Objects; | |
| 11 | import static jaggregate.Objects.*; | |
| 12 | ||
| 13 | /** | |
| 14 | * Describes a strategy for deciding whether two objects are equivalent. | |
| 15 | * | |
| 16 | * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a> | |
| 17 | * @version $Id: EquivalenceTester.java,v 1.1 2008/03/26 18:01:00 pholser Exp $ | |
| 18 | */ | |
| 19 | 8 | public enum EquivalenceTester { |
| 20 | /** | |
| 21 | * An equivalence tester that decides based on {@link Object#equals(Object) equals}. | |
| 22 | */ | |
| 23 | 1 | OBJECT_ATTRIBUTES { |
| 24 | /** | |
| 25 | * {@inheritDoc} | |
| 26 | */ | |
| 27 | @Override | |
| 28 | public boolean areEqual( Object first, Object second ) { | |
| 29 | 6161 | return Objects.areEqual( first, second ); |
| 30 | } | |
| 31 | ||
| 32 | /** | |
| 33 | * {@inheritDoc} | |
| 34 | */ | |
| 35 | @Override | |
| 36 | 1 | public int hashCode( Object target ) { |
| 37 | 9729 | return nullSafeHashCode( target ); |
| 38 | } | |
| 39 | }, | |
| 40 | ||
| 41 | /** | |
| 42 | * An equivalence tester that decides based on {@code ==}. | |
| 43 | */ | |
| 44 | 1 | OBJECT_IDENTITIES { |
| 45 | /** | |
| 46 | * {@inheritDoc} | |
| 47 | */ | |
| 48 | @Override | |
| 49 | public boolean areEqual( Object first, Object second ) { | |
| 50 | 6825 | return first == second; |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * {@inheritDoc} | |
| 55 | */ | |
| 56 | @Override | |
| 57 | 1 | public int hashCode( Object target ) { |
| 58 | 10224 | return identityHashCode( target ); |
| 59 | } | |
| 60 | }; | |
| 61 | ||
| 62 | /** | |
| 63 | * Tells whether the two given objects are considered equivalent. | |
| 64 | * | |
| 65 | * @param first first comparand | |
| 66 | * @param second second comparand | |
| 67 | * @return whether {@code first} and {@code second} are considered equivalent | |
| 68 | */ | |
| 69 | public abstract boolean areEqual( Object first, Object second ); | |
| 70 | ||
| 71 | /** | |
| 72 | * Computes a hash code for the given object. | |
| 73 | * | |
| 74 | * @param target object to compute a hash for | |
| 75 | * @return the computed hash | |
| 76 | */ | |
| 77 | public abstract int hashCode( Object target ); | |
| 78 | } |