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; 18 19 import com.google.common.annotations.GwtCompatible; 20 import java.io.Serializable; 21 import java.util.Arrays; 22 23 /** 24 * A class that implements {@code Comparable} without generics, such as those found in libraries 25 * that support Java 1.4 and before. Our library needs to do the bare minimum to accommodate such 26 * types, though their use may still require an explicit type parameter and/or warning suppression. 27 * 28 * @author Kevin Bourrillion 29 */ 30 @SuppressWarnings("ComparableType") 31 @GwtCompatible 32 class LegacyComparable implements Comparable, Serializable { 33 static final LegacyComparable X = new LegacyComparable("x"); 34 static final LegacyComparable Y = new LegacyComparable("y"); 35 static final LegacyComparable Z = new LegacyComparable("z"); 36 37 static final Iterable<LegacyComparable> VALUES_FORWARD = Arrays.asList(X, Y, Z); 38 static final Iterable<LegacyComparable> VALUES_BACKWARD = Arrays.asList(Z, Y, X); 39 40 private final String value; 41 LegacyComparable(String value)42 LegacyComparable(String value) { 43 this.value = value; 44 } 45 46 @Override compareTo(Object object)47 public int compareTo(Object object) { 48 // This method is spec'd to throw CCE if object is of the wrong type 49 LegacyComparable that = (LegacyComparable) object; 50 return this.value.compareTo(that.value); 51 } 52 53 @Override equals(Object object)54 public boolean equals(Object object) { 55 if (object instanceof LegacyComparable) { 56 LegacyComparable that = (LegacyComparable) object; 57 return this.value.equals(that.value); 58 } 59 return false; 60 } 61 62 @Override hashCode()63 public int hashCode() { 64 return value.hashCode(); 65 } 66 67 private static final long serialVersionUID = 0; 68 } 69