11d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/*
21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2009 The Guava Authors
31d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
41d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License");
51d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * you may not use this file except in compliance with the License.
61d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * You may obtain a copy of the License at
71d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
81d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * http://www.apache.org/licenses/LICENSE-2.0
91d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
101d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Unless required by applicable law or agreed to in writing, software
111d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS,
121d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * See the License for the specific language governing permissions and
141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * limitations under the License.
151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */
161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
171d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpackage com.google.common.collect;
181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
191d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport com.google.common.annotations.GwtCompatible;
201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
211d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport java.io.Serializable;
221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport java.util.Arrays;
231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
241d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/**
251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * A class that implements {@code Comparable} without generics, such as those
261d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * found in libraries that support Java 1.4 and before. Our library needs to
271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * do the bare minimum to accommodate such types, though their use may still
281d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * require an explicit type parameter and/or warning suppression.
291d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
301d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @author Kevin Bourrillion
311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */
321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert@GwtCompatible
331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertclass LegacyComparable implements Comparable, Serializable {
341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  static final LegacyComparable X = new LegacyComparable("x");
351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  static final LegacyComparable Y = new LegacyComparable("y");
361d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  static final LegacyComparable Z = new LegacyComparable("z");
371d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
381d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  static final Iterable<LegacyComparable> VALUES_FORWARD
391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert      = Arrays.asList(X, Y, Z);
401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  static final Iterable<LegacyComparable> VALUES_BACKWARD
411d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert      = Arrays.asList(Z, Y, X);
421d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
431d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  private final String value;
441d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
451d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  LegacyComparable(String value) {
461d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    this.value = value;
471d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  }
481d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
491d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  @Override
501d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  public int compareTo(Object object) {
511d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    // This method is spec'd to throw CCE if object is of the wrong type
521d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    LegacyComparable that = (LegacyComparable) object;
531d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    return this.value.compareTo(that.value);
541d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  }
551d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
561d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  @Override public boolean equals(Object object) {
571d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    if (object instanceof LegacyComparable) {
581d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert      LegacyComparable that = (LegacyComparable) object;
591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert      return this.value.equals(that.value);
601d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    }
611d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    return false;
621d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  }
631d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
641d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  @Override public int hashCode() {
651d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    return value.hashCode();
661d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  }
671d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
681d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  private static final long serialVersionUID = 0;
691d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert}
70