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 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 
     30   public UnhashableObject(int value) {
     31     this.value = value;
     32   }
     33 
     34   @Override public boolean equals(Object object) {
     35     if (object instanceof UnhashableObject) {
     36       UnhashableObject that = (UnhashableObject) object;
     37       return this.value == that.value;
     38     }
     39     return false;
     40   }
     41 
     42   @Override public int hashCode() {
     43     throw new UnsupportedOperationException();
     44   }
     45 
     46   // needed because otherwise Object.toString() calls hashCode()
     47   @Override public String toString() {
     48     return "DontHashMe" + value;
     49   }
     50 
     51   @Override
     52   public int compareTo(UnhashableObject o) {
     53     return (this.value < o.value) ? -1 : (this.value > o.value) ? 1 : 0;
     54   }
     55 }
     56