/** * Class to represent a map implemented using linked lists. * @author cs416 * @version 2 * @param Key type * @param Value type */ public class CSLinkedMap, V> implements CSMap { private CSList list; /** * Constructor. */ public CSLinkedMap() { this.list = new CSLinkedList<>(); } /** * Class to represent an entry in a map. * @author cs416 * @version 2 */ private final class Entry { public final K key; public final V value; /** * Constructor. * @param key K Key * @param value V Value */ Entry(K key, V value) { this.key = key; this.value = value; } /** * Print a nice human readable map entry of form (key->value). * @return String */ public String toString() { return "(" + key + "->" + value + ")"; } /** * Check if two Entries are equal. * We will say that two entries are equal if their keys are the same * @param o Object * @return boolean */ @Override public boolean equals(Object o) { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } } /** * Returns the value to which the specified key is mapped, * or null if this map contains no mapping for the key. * If this map permits null values, then a return value of null does not necessarily indicate * that the map contains no mapping for the key; * it's also possible that the map explicitly maps the key to null. * The Map#containsKey operation may be used to distinguish these two cases. * @param key the key whose associated value is to be returned * @return the value to which the specified key is mapped, * or null if this map contains no mapping for the key */ public V get(K key) { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * Inserts the (K, V) pair into the map if it does not already exist and * returns true. * If the map already contains a mapping for the key, return false * @param key key with which the specified value is to be associated * @param value value to be associated with the specified key * @return true if the key, value are inserted, false otherwise. */ public boolean insert(K key, V value) { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * Print the LinkedMap in nice format. * @return String */ public String toString() { StringBuilder s = new StringBuilder(); s.append(list); return s.toString(); } /** * Removes all of the mappings from this map. * The map will be empty after this call returns. */ public void clear() { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * Returns true if this map contains a mapping for the specified key. * @param key key whose presence in this map is to be tested * @return true if this map contains a mapping for the specified key */ public boolean containsKey(K key) { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * Returns true if this map contains no key-value mappings. * @return true if this map contains no key-value mappings */ public boolean isEmpty() { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * Removes the mapping for a key from this map if it is present. * * @param key key whose mapping is to be removed from the map * @return true if the key was removed from the Map, false otherwise */ public boolean remove(K key) { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * Returns the number of key-value mappings in this map. * @return the number of key-value mappings in this map */ public int size() { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } }