Home | History | Annotate | Download | only in testing
      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 /**
     20  * An unhashable object to be used in testing as values in our collections.
     21  *
     22  * <p>This class is GWT compatible.
     23  *
     24  * @author Regina O'Dell
     25  */
     26 public class UnhashableObject implements Comparable<UnhashableObject> {
     27   private final int value;
     28 
     29   public UnhashableObject(int value) {
     30     this.value = value;
     31   }
     32 
     33   @Override public boolean equals(Object object) {
     34     if (object instanceof UnhashableObject) {
     35       UnhashableObject that = (UnhashableObject) object;
     36       return this.value == that.value;
     37     }
     38     return false;
     39   }
     40 
     41   @Override public int hashCode() {
     42     throw new UnsupportedOperationException();
     43   }
     44 
     45   // needed because otherwise Object.toString() calls hashCode()
     46   @Override public String toString() {
     47     return "DontHashMe" + value;
     48   }
     49 
     50   @Override
     51   public int compareTo(UnhashableObject o) {
     52     return (this.value < o.value) ? -1 : (this.value > o.value) ? 1 : 0;
     53   }
     54 }
     55