package map; import container.*; import java.util.Iterator; public interface Map { /** Return the number of entries. */ public int size(); /** Are there any entries? */ public boolean isEmpty(); /** Add an entry with key k and value v. * Returns the new entry. */ public Entry insert(Object k, Object v) throws InvalidKeyException; /** If the map contains an entry with key k, * return such an entry, otherwise return null. * Why don't we just return the value? Because * then if we returned null it might mean either "no * entry" or "entry with value null." Also, because by * returning the entry, we make it possible for the * user to replace the entry's value. */ public Entry find(Object k) throws InvalidKeyException; /** If the dictionary contains an entry with key k, * remove and return such an entry, otherwise return null. * The reason to return the whole entry is for consistency * with find(). */ public Entry remove(Object k) throws InvalidKeyException; /** Return an iterator over all entries in the dictionary. * * (Note: As for any Iterator, its next() method returns Objects, * but they can be downcast to Entries.) */ public Iterator entries(); /** Replaces the value of an entry in the dictionary. * Returns the old value. */ public Object replaceValue(Entry e, Object v); }