/* * StringSearchKey.java - A simple search key based on Strings. * * Copyright (c) 1996 Chuck McManis, All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL purposes and without * fee is hereby granted provided that this copyright notice * appears in all copies. * * CHUCK MCMANIS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. CHUCK MCMANIS * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT * OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ /** * This simple search key is implemented with String objects. */ class StringSearchKey implements SearchKey { private String value; StringSearchKey(String s) { value = s; } public int compareKey(SearchKey k) { if (! (k instanceof StringSearchKey)) { throw new RuntimeException("Incompatible key comparison."); } return value.compareTo(((StringSearchKey) k).value); } public boolean equalKey(SearchKey k) { if (! (k instanceof StringSearchKey)) { throw new RuntimeException("Incompatible key comparison."); } return value.equals(((StringSearchKey) k).value); } }