Path: blob/master/src/java.base/share/classes/java/util/Dictionary.java
41152 views
/*1* Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.util;2627/**28* The {@code Dictionary} class is the abstract parent of any29* class, such as {@code Hashtable}, which maps keys to values.30* Every key and every value is an object. In any one {@code Dictionary}31* object, every key is associated with at most one value. Given a32* {@code Dictionary} and a key, the associated element can be looked up.33* Any non-{@code null} object can be used as a key and as a value.34* <p>35* As a rule, the {@code equals} method should be used by36* implementations of this class to decide if two keys are the same.37* <p>38* <strong>NOTE: This class is obsolete. New implementations should39* implement the Map interface, rather than extending this class.</strong>40*41* @see java.util.Map42* @see java.lang.Object#equals(java.lang.Object)43* @see java.lang.Object#hashCode()44* @see java.util.Hashtable45* @since 1.046*/47public abstract48class Dictionary<K,V> {49/**50* Sole constructor. (For invocation by subclass constructors, typically51* implicit.)52*/53public Dictionary() {54}5556/**57* Returns the number of entries (distinct keys) in this dictionary.58*59* @return the number of keys in this dictionary.60*/61public abstract int size();6263/**64* Tests if this dictionary maps no keys to value. The general contract65* for the {@code isEmpty} method is that the result is true if and only66* if this dictionary contains no entries.67*68* @return {@code true} if this dictionary maps no keys to values;69* {@code false} otherwise.70*/71public abstract boolean isEmpty();7273/**74* Returns an enumeration of the keys in this dictionary. The general75* contract for the keys method is that an {@code Enumeration} object76* is returned that will generate all the keys for which this dictionary77* contains entries.78*79* @return an enumeration of the keys in this dictionary.80* @see java.util.Dictionary#elements()81* @see java.util.Enumeration82*/83public abstract Enumeration<K> keys();8485/**86* Returns an enumeration of the values in this dictionary. The general87* contract for the {@code elements} method is that an88* {@code Enumeration} is returned that will generate all the elements89* contained in entries in this dictionary.90*91* @return an enumeration of the values in this dictionary.92* @see java.util.Dictionary#keys()93* @see java.util.Enumeration94*/95public abstract Enumeration<V> elements();9697/**98* Returns the value to which the key is mapped in this dictionary.99* The general contract for the {@code isEmpty} method is that if this100* dictionary contains an entry for the specified key, the associated101* value is returned; otherwise, {@code null} is returned.102*103* @return the value to which the key is mapped in this dictionary;104* @param key a key in this dictionary.105* {@code null} if the key is not mapped to any value in106* this dictionary.107* @throws NullPointerException if the {@code key} is {@code null}.108* @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)109*/110public abstract V get(Object key);111112/**113* Maps the specified {@code key} to the specified114* {@code value} in this dictionary. Neither the key nor the115* value can be {@code null}.116* <p>117* If this dictionary already contains an entry for the specified118* {@code key}, the value already in this dictionary for that119* {@code key} is returned, after modifying the entry to contain the120* new element. <p>If this dictionary does not already have an entry121* for the specified {@code key}, an entry is created for the122* specified {@code key} and {@code value}, and {@code null} is123* returned.124* <p>125* The {@code value} can be retrieved by calling the126* {@code get} method with a {@code key} that is equal to127* the original {@code key}.128*129* @param key the hashtable key.130* @param value the value.131* @return the previous value to which the {@code key} was mapped132* in this dictionary, or {@code null} if the key did not133* have a previous mapping.134* @throws NullPointerException if the {@code key} or135* {@code value} is {@code null}.136* @see java.lang.Object#equals(java.lang.Object)137* @see java.util.Dictionary#get(java.lang.Object)138*/139public abstract V put(K key, V value);140141/**142* Removes the {@code key} (and its corresponding143* {@code value}) from this dictionary. This method does nothing144* if the {@code key} is not in this dictionary.145*146* @param key the key that needs to be removed.147* @return the value to which the {@code key} had been mapped in this148* dictionary, or {@code null} if the key did not have a149* mapping.150* @throws NullPointerException if {@code key} is {@code null}.151*/152public abstract V remove(Object key);153}154155156