001/*
002 * Copyright (C) 2010 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;
020import com.google.common.annotations.GwtIncompatible;
021import com.google.common.annotations.J2ktIncompatible;
022import java.io.Serializable;
023import org.jspecify.annotations.Nullable;
024
025/**
026 * Simple base class to verify that we handle generics correctly.
027 *
028 * @author Kevin Bourrillion
029 */
030@GwtCompatible
031public class BaseComparable implements Comparable<BaseComparable>, Serializable {
032  private final String s;
033
034  public BaseComparable(String s) {
035    this.s = s;
036  }
037
038  @Override
039  public int hashCode() { // delegate to 's'
040    return s.hashCode();
041  }
042
043  @Override
044  public boolean equals(@Nullable Object other) {
045    if (other == null) {
046      return false;
047    } else if (other instanceof BaseComparable) {
048      return s.equals(((BaseComparable) other).s);
049    } else {
050      return false;
051    }
052  }
053
054  @Override
055  public int compareTo(BaseComparable o) {
056    return s.compareTo(o.s);
057  }
058
059  @GwtIncompatible @J2ktIncompatible private static final long serialVersionUID = 0;
060}