HashMap "WriteOnce" Implementation .. need help

Posted by JavaNewbie on Stack Overflow See other posts from Stack Overflow or by JavaNewbie
Published on 2011-01-10T07:44:45Z Indexed on 2011/01/10 7:53 UTC
Read the original article Hit count: 125

Filed under:
|
import java.util.*;


    public class HashMapExample {

        public static class WriteOnceMap<K, V> extends HashMap<K, V> {

            public V put(K key, V value) {
                /*
                 WriteOnceMap is a map that does not allow changing value for a particular key.
                 It means that put() method should throw IllegalArgumentException if the key is already
                 assosiated with some value in the map.

                 Please implement this method to conform to the above description of WriteOnceMap.
                */
            }


            public void putAll(Map<? extends K, ? extends V> m) {
                /*
                 Pleaase implement this method to conform to the description of WriteOnceMap above.
                 It should either
                 (1) copy all of the mappings from the specified map to this map or
                 (2) throw IllegalArgumentException and leave this map intact
                 if the parameter already contains some keys from this map.
                */
            }
        }
    }

© Stack Overflow or respective owner

Related posts about java

Related posts about hashmap