package jalview.util; /** * A class to wrap a case insensitive string. For use in collections where we * want to preserve case, but do not want to duplicate upper and lower case * variants */ public final class CaseInsensitiveString { String value; public CaseInsensitiveString(String s) { this.value = s; } @Override public String toString() { return value; } /** * Answers true if the object compared to is a CaseInsensitiveString wrapping * the same string value (ignoring case), or if both wrap a null value, else * false */ @Override public boolean equals(Object o) { if (o == null) { return false; } if (!(o instanceof CaseInsensitiveString)) { return false; } CaseInsensitiveString obj = (CaseInsensitiveString) o; if (value == null) { return obj.value == null; } return value.equalsIgnoreCase(obj.value); } /** * hashCode overriden to guarantee that 'equal' objects have the same hash * code */ @Override public int hashCode() { return value == null ? super.hashCode() : value.toUpperCase() .hashCode(); } }