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