All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twelvemonkeys.util.IgnoreCaseHashtable Maven / Gradle / Ivy

/*
 * Copyright (c) 2008, Harald Kuhr
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name "TwelveMonkeys" nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.twelvemonkeys.util;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

/**
 * A hashtable that igores case (this is implemented by converting all keys to
 * uppercase), if the keys used are strings. If the keys
 * used are not strings, it wil work as a normal java.util.Hashtable.
 * 

* * @see IgnoreCaseMap * @see java.util.Hashtable * @deprecated Replaced by IgnoreCaseMap */ public class IgnoreCaseHashtable extends Hashtable { /** * Constructs a new empty hashtable. * * @see java.util.Hashtable#Hashtable() */ public IgnoreCaseHashtable() { super(); } /** * Constructs a new map with the same key-value mappings as the given Map. *

* Note: As the keys in the given map parameter will be converted to * uppercase (if they are strings), any duplicate key/value pair where * key.equalsIgnoreCase(otherKey) is true, will be lost. * * @param pMap the map whose mappings are to be placed in this map. */ public IgnoreCaseHashtable(Map pMap) { super(); Iterator it = pMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); put(entry.getKey(), entry.getValue()); } } /** * Maps the specified key to the specified value in this hashtable. * Neither the key nor the value can be null. * Note: If the key used is a string, the key will not be case-sensitive. * * @param pKey the hashtable key. * @param pValue the value. * @return the previous value of the specified key in this hashtable, * or null if it did not have one. */ public Object put(Object pKey, Object pValue) { return super.put(toUpper(pKey), pValue); } /** * Returns the value to which the specified key is mapped in this * hashtable. * Note: If the key used is a string, the key will not be case-sensitive. * * @param pKey a key in the hashtable * @return the value to which the key is mapped in this hashtable; null if * the key is not mapped to any value in this hashtable. */ public Object get(Object pKey) { return super.get(toUpper(pKey)); } /** * Removes the key (and its corresponding value) from this hashtable. This * method does nothing if the key is not in the hashtable. * Note: If the key used is a string, the key will not be case-sensitive. * * @param pKey the key that needs to be removed. * @return the value to which the key had been mapped in this hashtable, * or null if the key did not have a mapping. */ public Object remove(Object pKey) { return super.remove(toUpper(pKey)); } /** * Tests if the specified object is a key in this hashtable. * Note: If the key used is a string, the key will not be case-sensitive. * * @param pKey possible key. * @return true if and only if the specified object is a key in this * hashtable, as determined by the equals method; false otherwise. */ public boolean containsKey(Object pKey) { return super.containsKey(toUpper(pKey)); } /** * Converts the parameter to uppercase, if it's a string. */ protected static Object toUpper(Object pStr) { if (pStr instanceof String) { return ((String) pStr).toUpperCase(); } return pStr; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy