1 package annotations.util; 2 3 /*>>> 4 import org.checkerframework.checker.nullness.qual.*; 5 */ 6 7 /** 8 * {@link EqualByStringRepresentation} is a "mix-in" class for objects that are 9 * equal if and only if their {@link #toString toString} representations are 10 * equal. {@link EqualByStringRepresentation} provides implementations of 11 * {@link #equals} and {@link #hashCode} in terms of {@link #toString}. 12 */ 13 public abstract class EqualByStringRepresentation { 14 /** 15 * {@inheritDoc} 16 */ 17 @Override 18 public abstract String toString(); 19 20 /** 21 * {@inheritDoc} 22 */ 23 @Override 24 public final boolean equals(Object that) { 25 return that != null && this.getClass() == that.getClass() 26 && this.toString().equals(that.toString()); 27 } 28 29 /** 30 * {@inheritDoc} 31 */ 32 @Override 33 public final int hashCode() { 34 return toString().hashCode(); 35 } 36 } 37