home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / util / Dictionary.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  5.8 KB  |  146 lines  |  [TEXT/CWIE]

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