Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/util/Dictionary.java
38829 views
/*1* Copyright (c) 1995, 2004, 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</code> class is the abstract parent of any29* class, such as <code>Hashtable</code>, which maps keys to values.30* Every key and every value is an object. In any one <tt>Dictionary</tt>31* object, every key is associated with at most one value. Given a32* <tt>Dictionary</tt> and a key, the associated element can be looked up.33* Any non-<code>null</code> object can be used as a key and as a value.34* <p>35* As a rule, the <code>equals</code> 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* @author unascribed42* @see java.util.Map43* @see java.lang.Object#equals(java.lang.Object)44* @see java.lang.Object#hashCode()45* @see java.util.Hashtable46* @since JDK1.047*/48public abstract49class Dictionary<K,V> {50/**51* Sole constructor. (For invocation by subclass constructors, typically52* implicit.)53*/54public Dictionary() {55}5657/**58* Returns the number of entries (distinct keys) in this dictionary.59*60* @return the number of keys in this dictionary.61*/62abstract public int size();6364/**65* Tests if this dictionary maps no keys to value. The general contract66* for the <tt>isEmpty</tt> method is that the result is true if and only67* if this dictionary contains no entries.68*69* @return <code>true</code> if this dictionary maps no keys to values;70* <code>false</code> otherwise.71*/72abstract public boolean isEmpty();7374/**75* Returns an enumeration of the keys in this dictionary. The general76* contract for the keys method is that an <tt>Enumeration</tt> object77* is returned that will generate all the keys for which this dictionary78* contains entries.79*80* @return an enumeration of the keys in this dictionary.81* @see java.util.Dictionary#elements()82* @see java.util.Enumeration83*/84abstract public Enumeration<K> keys();8586/**87* Returns an enumeration of the values in this dictionary. The general88* contract for the <tt>elements</tt> method is that an89* <tt>Enumeration</tt> is returned that will generate all the elements90* contained in entries in this dictionary.91*92* @return an enumeration of the values in this dictionary.93* @see java.util.Dictionary#keys()94* @see java.util.Enumeration95*/96abstract public Enumeration<V> elements();9798/**99* Returns the value to which the key is mapped in this dictionary.100* The general contract for the <tt>isEmpty</tt> method is that if this101* dictionary contains an entry for the specified key, the associated102* value is returned; otherwise, <tt>null</tt> is returned.103*104* @return the value to which the key is mapped in this dictionary;105* @param key a key in this dictionary.106* <code>null</code> if the key is not mapped to any value in107* this dictionary.108* @exception NullPointerException if the <tt>key</tt> is <tt>null</tt>.109* @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)110*/111abstract public V get(Object key);112113/**114* Maps the specified <code>key</code> to the specified115* <code>value</code> in this dictionary. Neither the key nor the116* value can be <code>null</code>.117* <p>118* If this dictionary already contains an entry for the specified119* <tt>key</tt>, the value already in this dictionary for that120* <tt>key</tt> is returned, after modifying the entry to contain the121* new element. <p>If this dictionary does not already have an entry122* for the specified <tt>key</tt>, an entry is created for the123* specified <tt>key</tt> and <tt>value</tt>, and <tt>null</tt> is124* returned.125* <p>126* The <code>value</code> can be retrieved by calling the127* <code>get</code> method with a <code>key</code> that is equal to128* the original <code>key</code>.129*130* @param key the hashtable key.131* @param value the value.132* @return the previous value to which the <code>key</code> was mapped133* in this dictionary, or <code>null</code> if the key did not134* have a previous mapping.135* @exception NullPointerException if the <code>key</code> or136* <code>value</code> is <code>null</code>.137* @see java.lang.Object#equals(java.lang.Object)138* @see java.util.Dictionary#get(java.lang.Object)139*/140abstract public V put(K key, V value);141142/**143* Removes the <code>key</code> (and its corresponding144* <code>value</code>) from this dictionary. This method does nothing145* if the <code>key</code> is not in this dictionary.146*147* @param key the key that needs to be removed.148* @return the value to which the <code>key</code> had been mapped in this149* dictionary, or <code>null</code> if the key did not have a150* mapping.151* @exception NullPointerException if <tt>key</tt> is <tt>null</tt>.152*/153abstract public V remove(Object key);154}155156157