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