BaseComparable.java revision 1d580d0f6ee4f21eb309ba7b509d2c6d671c4044
1/*
2 * Copyright (C) 2010 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
17package com.google.common.collect.testing;
18
19import java.io.Serializable;
20
21/**
22 * Simple base class to verify that we handle generics correctly.
23 *
24 * @author Kevin Bourrillion
25 */
26public class BaseComparable implements Comparable<BaseComparable>, Serializable {
27  private final String s;
28
29  public BaseComparable(String s) {
30    this.s = s;
31  }
32
33  @Override public int hashCode() { // delegate to 's'
34    return s.hashCode();
35  }
36
37  @Override public boolean equals(Object other) {
38    if (other == null) {
39      return false;
40    } else if (other instanceof BaseComparable) {
41      return s.equals(((BaseComparable) other).s);
42    } else {
43      return false;
44    }
45  }
46
47  @Override
48  public int compareTo(BaseComparable o) {
49    return s.compareTo(o.s);
50  }
51
52  private static final long serialVersionUID = 0;
53}
54