1. /*
  2. * @(#)Dictionary.java 1.15 00/02/02
  3. *
  4. * Copyright 1995-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.util;
  11. /**
  12. * The <code>Dictionary</code> class is the abstract parent of any
  13. * class, such as <code>Hashtable</code>, which maps keys to values.
  14. * Every key and every value is an object. In any one <tt>Dictionary</tt>
  15. * object, every key is associated with at most one value. Given a
  16. * <tt>Dictionary</tt> and a key, the associated element can be looked up.
  17. * Any non-<code>null</code> object can be used as a key and as a value.
  18. * <p>
  19. * As a rule, the <code>equals</code> method should be used by
  20. * implementations of this class to decide if two keys are the same.
  21. * <p>
  22. * <strong>NOTE: This class is obsolete. New implementations should
  23. * implement the Map interface, rather than extendidng this class.</strong>
  24. *
  25. * @author unascribed
  26. * @version 1.15, 02/02/00
  27. * @see java.util.Map
  28. * @see java.lang.Object#equals(java.lang.Object)
  29. * @see java.lang.Object#hashCode()
  30. * @see java.util.Hashtable
  31. * @since JDK1.0
  32. */
  33. public abstract
  34. class Dictionary {
  35. /**
  36. * Sole constructor. (For invocation by subclass constructors, typically
  37. * implicit.)
  38. */
  39. public Dictionary() {
  40. }
  41. /**
  42. * Returns the number of entries (dinstint keys) in this dictionary.
  43. *
  44. * @return the number of keys in this dictionary.
  45. */
  46. abstract public int size();
  47. /**
  48. * Tests if this dictionary maps no keys to value. The general contract
  49. * for the <tt>isEmpty</tt> method is that the result is true if and only
  50. * if this dictionary contains no entries.
  51. *
  52. * @return <code>true</code> if this dictionary maps no keys to values;
  53. * <code>false</code> otherwise.
  54. */
  55. abstract public boolean isEmpty();
  56. /**
  57. * Returns an enumeration of the keys in this dictionary. The general
  58. * contract for the keys method is that an <tt>Enumeration</tt> object
  59. * is returned that will generate all the keys for which this dictionary
  60. * contains entries.
  61. *
  62. * @return an enumeration of the keys in this dictionary.
  63. * @see java.util.Dictionary#elements()
  64. * @see java.util.Enumeration
  65. */
  66. abstract public Enumeration keys();
  67. /**
  68. * Returns an enumeration of the values in this dictionary. The general
  69. * contract for the <tt>elements</tt> method is that an
  70. * <tt>Enumeration</tt> is returned that will generate all the elements
  71. * contained in entries in this dictionary.
  72. *
  73. * @return an enumeration of the values in this dictionary.
  74. * @see java.util.Dictionary#keys()
  75. * @see java.util.Enumeration
  76. */
  77. abstract public Enumeration elements();
  78. /**
  79. * Returns the value to which the key is mapped in this dictionary.
  80. * The general contract for the <tt>isEmpty</tt> method is that if this
  81. * dictionary contains an entry for the specified key, the associated
  82. * value is returned; otherwise, <tt>null</tt> is returned.
  83. *
  84. * @return the value to which the key is mapped in this dictionary;
  85. * @param key a key in this dictionary.
  86. * <code>null</code> if the key is not mapped to any value in
  87. * this dictionary.
  88. * @exception NullPointerException if the <tt>key</tt> is <tt>null</tt>.
  89. * @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)
  90. */
  91. abstract public Object get(Object key);
  92. /**
  93. * Maps the specified <code>key</code> to the specified
  94. * <code>value</code> in this dictionary. Neither the key nor the
  95. * value can be <code>null</code>.
  96. * <p>
  97. * If this dictionary already contains an entry for the specified
  98. * <tt>key</tt>, the value already in this dictionary for that
  99. * <tt>key</tt> is returned, after modifying the entry to contain the
  100. * new element. <p>If this dictionary does not already have an entry
  101. * for the specified <tt>key</tt>, an entry is created for the
  102. * specified <tt>key</tt> and <tt>value</tt>, and <tt>null</tt> is
  103. * returned.
  104. * <p>
  105. * The <code>value</code> can be retrieved by calling the
  106. * <code>get</code> method with a <code>key</code> that is equal to
  107. * the original <code>key</code>.
  108. *
  109. * @param key the hashtable key.
  110. * @param value the value.
  111. * @return the previous value to which the <code>key</code> was mapped
  112. * in this dictionary, or <code>null</code> if the key did not
  113. * have a previous mapping.
  114. * @exception NullPointerException if the <code>key</code> or
  115. * <code>value</code> is <code>null</code>.
  116. * @see java.lang.Object#equals(java.lang.Object)
  117. * @see java.util.Dictionary#get(java.lang.Object)
  118. */
  119. abstract public Object put(Object key, Object value);
  120. /**
  121. * Removes the <code>key</code> (and its corresponding
  122. * <code>value</code>) from this dictionary. This method does nothing
  123. * if the <code>key</code> is not in this dictionary.
  124. *
  125. * @param key the key that needs to be removed.
  126. * @return the value to which the <code>key</code> had been mapped in this
  127. * dictionary, or <code>null</code> if the key did not have a
  128. * mapping.
  129. * @exception NullPointerException if <tt>key</tt> is <tt>null</tt>.
  130. */
  131. abstract public Object remove(Object key);
  132. }