Coverage Report - net.wotonomy.foundation.NSMutableDictionary
 
Classes in this File Line Coverage Branch Coverage Complexity
NSMutableDictionary
0% 
0% 
1.273
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2000 Blacksmith, Inc.
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, see http://www.gnu.org
 17  
 */
 18  
 
 19  
 package net.wotonomy.foundation;
 20  
 
 21  
 import java.util.Enumeration;
 22  
 import java.util.Map;
 23  
 
 24  
 /**
 25  
 * A pure java implementation of NSMutableDictionary that
 26  
 * implements Map for greater java interoperability.
 27  
 *
 28  
 * @author michael@mpowers.net
 29  
 * @author $Author: cgruber $
 30  
 * @version $Revision: 893 $
 31  
 */
 32  
 public class NSMutableDictionary
 33  
     extends NSDictionary
 34  
 {
 35  
     /**
 36  
     * Default constructor produces an empty dictionary.
 37  
     */
 38  
     public NSMutableDictionary ()
 39  
     {
 40  0
             super();
 41  0
     }
 42  
     
 43  
     /**
 44  
     * Default constructor produces an empty dictionary.
 45  
     */
 46  
     public NSMutableDictionary (int initialSize)
 47  
     {
 48  0
             super(initialSize);
 49  0
     }
 50  
     
 51  
     /**
 52  
     * Produces a dictionary that contains one key referencing one value.
 53  
     */
 54  
     public NSMutableDictionary (Object key, Object value)
 55  
     {
 56  0
             super( key, value );
 57  0
     }
 58  
 
 59  
     /**
 60  
     * Produces a dictionary containing the specified keys and values.
 61  
     * An IllegalArgumentException is thrown if the arrays are not 
 62  
     * of the same length.
 63  
     */
 64  
     public NSMutableDictionary (Object[] keys, Object[] values)
 65  
     {
 66  0
             super( keys, values );
 67  0
         }
 68  
 
 69  
     /**
 70  
     * Produces a dictionary that is a copy of the specified map (or dictionary).
 71  
     */
 72  
     public NSMutableDictionary (Map aMap)
 73  
     {
 74  0
             super( aMap );
 75  0
     }        
 76  
 
 77  
     /**
 78  
     * Removes the key-value pair for the specified key.
 79  
     */
 80  
     public void removeObjectForKey (Object aKey)
 81  
     {
 82  0
             remove( aKey );
 83  0
     }
 84  
 
 85  
     /**
 86  
     * Copies all mappings from the specified dictionary to this dictionary,
 87  
     * replacing any mappings this map had for any keys in the specified map.
 88  
     */
 89  
     public void addEntriesFromDictionary (Map aMap)
 90  
     {
 91  0
             putAll( aMap );
 92  0
     }
 93  
 
 94  
     /**
 95  
     * Removes all mappings from this dictionary.
 96  
     */
 97  
     public void removeAllObjects ()
 98  
     {
 99  0
             clear();
 100  0
     }
 101  
 
 102  
     /**
 103  
     * Removes all keys in the specified array from this dictionary. 
 104  
     */
 105  
     public void removeObjectsForKeys (NSArray anArray)
 106  
     {
 107  0
             Enumeration enumeration = anArray.objectEnumerator();
 108  0
             while ( enumeration.hasMoreElements() )
 109  
             {
 110  0
                     removeObjectForKey( enumeration.nextElement() );
 111  0
             }
 112  0
     }
 113  
 
 114  
     /**
 115  
     * Clears all mappings in this dictionary and then adds all entries
 116  
     * in the specified dictionary.
 117  
     */
 118  
     public void setDictionary (Map aMap)
 119  
     {
 120  0
             removeAllObjects();
 121  0
             addEntriesFromDictionary( aMap );
 122  0
     }
 123  
 
 124  
     /**
 125  
     * Sets the value for the specified key.  If the key currently
 126  
     * exists to the dictionary, the old value is replaced with the
 127  
     * specified value.  An IllegalArgumentException is thrown if 
 128  
     * either the key or value is null.
 129  
     */
 130  
     public void setObjectForKey (Object aValue, Object aKey)
 131  
     {
 132  0
             if ( ( aKey == null ) || ( aValue == null ) )
 133  
             {
 134  0
                     throw new IllegalArgumentException( 
 135  0
                             "Cannot use null objects with an NSMutableDictionary." );
 136  
             }
 137  0
             put( aKey, aValue );
 138  0
     }
 139  
 }
 140  
 
 141  
 /*
 142  
  * $Log$
 143  
  * Revision 1.2  2006/02/16 13:15:00  cgruber
 144  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 145  
  *
 146  
  * Revision 1.4  2005/05/11 15:21:53  cgruber
 147  
  * Change enum to enumeration, since enum is now a keyword as of Java 5.0
 148  
  *
 149  
  * A few other comments in the code.
 150  
  *
 151  
  * Revision 1.3  2002/06/30 17:16:26  mpowers
 152  
  * Added new constructor taking an int: thanks cgruber.
 153  
  *
 154  
  *
 155  
  * Revision 1.2  2001/02/23 23:43:41  mpowers
 156  
  * Removed ill-advised this.
 157  
  *
 158  
  * Revision 1.1.1.1  2000/12/21 15:47:34  mpowers
 159  
  * Contributing wotonomy.
 160  
  *
 161  
  * Revision 1.3  2000/12/20 16:25:38  michael
 162  
  * Added log to all files.
 163  
  *
 164  
  *
 165  
  */
 166