Dictionary.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* Dictionary.java -- an abstract (and essentially worthless)
  2. class which is Hashtable's superclass
  3. Copyright (C) 1998, 2001, 2002, 2004 Free Software Foundation, Inc.
  4. This file is part of GNU Classpath.
  5. GNU Classpath is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. GNU Classpath is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Classpath; see the file COPYING. If not, write to the
  15. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA.
  17. Linking this library statically or dynamically with other modules is
  18. making a combined work based on this library. Thus, the terms and
  19. conditions of the GNU General Public License cover the whole
  20. combination.
  21. As a special exception, the copyright holders of this library give you
  22. permission to link this library with independent modules to produce an
  23. executable, regardless of the license terms of these independent
  24. modules, and to copy and distribute the resulting executable under
  25. terms of your choice, provided that you also meet, for each linked
  26. independent module, the terms and conditions of the license of that
  27. module. An independent module is a module which is not derived from
  28. or based on this library. If you modify this library, you may extend
  29. this exception to your version of the library, but you are not
  30. obligated to do so. If you do not wish to do so, delete this
  31. exception statement from your version. */
  32. package java.util;
  33. /**
  34. * A Dictionary maps keys to values; <i>how</i> it does that is
  35. * implementation-specific.
  36. *
  37. * This is an abstract class which has really gone by the wayside.
  38. * People at Javasoft are probably embarrassed by it. At this point,
  39. * it might as well be an interface rather than a class, but it remains
  40. * this poor, laughable skeleton for the sake of backwards compatibility.
  41. * At any rate, this was what came before the {@link Map} interface
  42. * in the Collections framework.
  43. *
  44. * @author Jon Zeppieri
  45. * @author Eric Blake (ebb9@email.byu.edu)
  46. * @see Map
  47. * @see Hashtable
  48. * @since 1.0
  49. * @status updated to 1.4
  50. */
  51. public abstract class Dictionary<K, V>
  52. {
  53. // WARNING: Dictionary is a CORE class in the bootstrap cycle. See the
  54. // comments in vm/reference/java/lang/Runtime for implications of this fact.
  55. /**
  56. * Sole constructor (often called implicitly).
  57. */
  58. public Dictionary()
  59. {
  60. }
  61. /**
  62. * Returns an Enumeration of the values in this Dictionary.
  63. *
  64. * @return an Enumeration of the values
  65. * @see #keys()
  66. */
  67. public abstract Enumeration<V> elements();
  68. /**
  69. * Returns the value associated with the supplied key, or null
  70. * if no such value exists. Since Dictionaries are not allowed null keys
  71. * or elements, a null result always means the key is not present.
  72. *
  73. * @param key the key to use to fetch the value
  74. * @return the mapped value
  75. * @throws NullPointerException if key is null
  76. * @see #put(Object, Object)
  77. */
  78. public abstract V get(Object key);
  79. /**
  80. * Returns true when there are no elements in this Dictionary.
  81. *
  82. * @return <code>size() == 0</code>
  83. */
  84. public abstract boolean isEmpty();
  85. /**
  86. * Returns an Enumeration of the keys in this Dictionary
  87. *
  88. * @return an Enumeration of the keys
  89. * @see #elements()
  90. */
  91. public abstract Enumeration<K> keys();
  92. /**
  93. * Inserts a new value into this Dictionary, located by the
  94. * supplied key. Dictionary does not support null keys or values, so
  95. * a null return can safely be interpreted as adding a new key.
  96. *
  97. * @param key the key which locates the value
  98. * @param value the value to put into the Dictionary
  99. * @return the previous value of the key, or null if there was none
  100. * @throws NullPointerException if key or value is null
  101. * @see #get(Object)
  102. */
  103. public abstract V put(K key, V value);
  104. /**
  105. * Removes from the Dictionary the value located by the given key. A null
  106. * return safely means that the key was not mapped in the Dictionary.
  107. *
  108. * @param key the key used to locate the value to be removed
  109. * @return the value associated with the removed key
  110. * @throws NullPointerException if key is null
  111. */
  112. public abstract V remove(Object key);
  113. /**
  114. * Returns the number of values currently in this Dictionary.
  115. *
  116. * @return the number of keys in the Dictionary
  117. */
  118. public abstract int size();
  119. } // class Dictionary