1 /* 2 * Copyright (C) 2009 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.collect.testing; 18 19 import com.google.common.annotations.GwtCompatible; 20 21 /** 22 * An unhashable object to be used in testing as values in our collections. 23 * 24 * @author Regina O'Dell 25 */ 26 @GwtCompatible 27 public class UnhashableObject implements Comparable<UnhashableObject> { 28 private final int value; 29 UnhashableObject(int value)30 public UnhashableObject(int value) { 31 this.value = value; 32 } 33 34 @Override equals(Object object)35 public boolean equals(Object object) { 36 if (object instanceof UnhashableObject) { 37 UnhashableObject that = (UnhashableObject) object; 38 return this.value == that.value; 39 } 40 return false; 41 } 42 43 @Override hashCode()44 public int hashCode() { 45 throw new UnsupportedOperationException(); 46 } 47 48 // needed because otherwise Object.toString() calls hashCode() 49 @Override toString()50 public String toString() { 51 return "DontHashMe" + value; 52 } 53 54 @Override compareTo(UnhashableObject o)55 public int compareTo(UnhashableObject o) { 56 return (this.value < o.value) ? -1 : (this.value > o.value) ? 1 : 0; 57 } 58 } 59