1 /*
2  * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package java.util;
27 
28 /**
29  * The {@code Dictionary} class is the abstract parent of any
30  * class, such as {@code Hashtable}, which maps keys to values.
31  * Every key and every value is an object. In any one {@code Dictionary}
32  * object, every key is associated with at most one value. Given a
33  * {@code Dictionary} and a key, the associated element can be looked up.
34  * Any non-{@code null} object can be used as a key and as a value.
35  * <p>
36  * As a rule, the {@code equals} method should be used by
37  * implementations of this class to decide if two keys are the same.
38  * <p>
39  * <strong>NOTE: This class is obsolete.  New implementations should
40  * implement the Map interface, rather than extending this class.</strong>
41  *
42  * @see     java.util.Map
43  * @see     java.lang.Object#equals(java.lang.Object)
44  * @see     java.lang.Object#hashCode()
45  * @see     java.util.Hashtable
46  * @since   1.0
47  */
48 public abstract
49 class Dictionary<K,V> {
50     /**
51      * Sole constructor.  (For invocation by subclass constructors, typically
52      * implicit.)
53      */
Dictionary()54     public Dictionary() {
55     }
56 
57     /**
58      * Returns the number of entries (distinct keys) in this dictionary.
59      *
60      * @return  the number of keys in this dictionary.
61      */
size()62     public abstract int size();
63 
64     /**
65      * Tests if this dictionary maps no keys to value. The general contract
66      * for the {@code isEmpty} method is that the result is true if and only
67      * if this dictionary contains no entries.
68      *
69      * @return  {@code true} if this dictionary maps no keys to values;
70      *          {@code false} otherwise.
71      */
isEmpty()72     public abstract boolean isEmpty();
73 
74     /**
75      * Returns an enumeration of the keys in this dictionary. The general
76      * contract for the keys method is that an {@code Enumeration} object
77      * is returned that will generate all the keys for which this dictionary
78      * contains entries.
79      *
80      * @return  an enumeration of the keys in this dictionary.
81      * @see     java.util.Dictionary#elements()
82      * @see     java.util.Enumeration
83      */
keys()84     public abstract Enumeration<K> keys();
85 
86     /**
87      * Returns an enumeration of the values in this dictionary. The general
88      * contract for the {@code elements} method is that an
89      * {@code Enumeration} is returned that will generate all the elements
90      * 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.Enumeration
95      */
elements()96     public abstract Enumeration<V> elements();
97 
98     /**
99      * Returns the value to which the key is mapped in this dictionary.
100      * The general contract for the {@code isEmpty} method is that if this
101      * dictionary contains an entry for the specified key, the associated
102      * value is returned; otherwise, {@code null} 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} if the key is not mapped to any value in
107      *          this dictionary.
108      * @throws    NullPointerException if the {@code key} is {@code null}.
109      * @see     java.util.Dictionary#put(java.lang.Object, java.lang.Object)
110      */
get(Object key)111     public abstract V get(Object key);
112 
113     /**
114      * Maps the specified {@code key} to the specified
115      * {@code value} in this dictionary. Neither the key nor the
116      * value can be {@code null}.
117      * <p>
118      * If this dictionary already contains an entry for the specified
119      * {@code key}, the value already in this dictionary for that
120      * {@code key} is returned, after modifying the entry to contain the
121      *  new element. <p>If this dictionary does not already have an entry
122      *  for the specified {@code key}, an entry is created for the
123      *  specified {@code key} and {@code value}, and {@code null} is
124      *  returned.
125      * <p>
126      * The {@code value} can be retrieved by calling the
127      * {@code get} method with a {@code key} that is equal to
128      * the original {@code key}.
129      *
130      * @param      key     the hashtable key.
131      * @param      value   the value.
132      * @return     the previous value to which the {@code key} was mapped
133      *             in this dictionary, or {@code null} if the key did not
134      *             have a previous mapping.
135      * @throws     NullPointerException  if the {@code key} or
136      *               {@code value} is {@code null}.
137      * @see        java.lang.Object#equals(java.lang.Object)
138      * @see        java.util.Dictionary#get(java.lang.Object)
139      */
put(K key, V value)140     public abstract V put(K key, V value);
141 
142     /**
143      * Removes the {@code key} (and its corresponding
144      * {@code value}) from this dictionary. This method does nothing
145      * if the {@code key} 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} had been mapped in this
149      *          dictionary, or {@code null} if the key did not have a
150      *          mapping.
151      * @throws    NullPointerException if {@code key} is {@code null}.
152      */
remove(Object key)153     public abstract V remove(Object key);
154 }
155