001/*
002 * Copyright (C) 2009 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect.testing;
018
019import com.google.common.annotations.GwtCompatible;
020
021/**
022 * An unhashable object to be used in testing as values in our collections.
023 *
024 * @author Regina O'Dell
025 */
026@GwtCompatible
027public class UnhashableObject implements Comparable<UnhashableObject> {
028  private final int value;
029
030  public UnhashableObject(int value) {
031    this.value = value;
032  }
033
034  @Override
035  public boolean equals(Object object) {
036    if (object instanceof UnhashableObject) {
037      UnhashableObject that = (UnhashableObject) object;
038      return this.value == that.value;
039    }
040    return false;
041  }
042
043  @Override
044  public int hashCode() {
045    throw new UnsupportedOperationException();
046  }
047
048  // needed because otherwise Object.toString() calls hashCode()
049  @Override
050  public String toString() {
051    return "DontHashMe" + value;
052  }
053
054  @Override
055  public int compareTo(UnhashableObject o) {
056    return (this.value < o.value) ? -1 : (this.value > o.value) ? 1 : 0;
057  }
058}