Question
placeholder for key type * @param placeholder for value type */ public interface Map { ** * Removes al> Create a contains key method and
Create a contains key method and a clear method without using java s given hash map.
Given Code:
Map Interface class:
package assign09;
import java. util. List;
/** * This interface represents a map of keys to values. It cannot contain * duplicate keys, and each key can map to at most one value. * * @ par am - placeholder for key type * @ par am - placeholder for value type */ public interface Map {
/** * Removes all mappings from this map. * * O(table length) */ public void clear();
/** * Determines whether this map contains the specified key. * * O(1) * * @ par am key * @return true if this map contains the key, false otherwise */ public Boolean contains Key(K key);
/** * Determines whether this map contains the specified value. * * O(table length) * * @par am value * @return true if this map contains one or more keys to the specified value, * false otherwise */ public Boolean contains Value(V value);
/** * Returns a List view of the mappings contained in this map, where the ordering of * mapping in the list is insignificant. * * O(table length) * * @return a List object containing all mapping (i.e., entries) in this map */ public List> entries();
/** * Gets the value to which the specified key is mapped. * * O(1) * * @ par am key * @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);
/** * Determines whether this map contains any mappings. * * O(1) * * @return true if this map contains no mappings, false otherwise */ public Boolean is Empty(); /** * Associates the specified value with the specified key in this map. * (I.e., if the key already exists in this map, resets the value; * otherwise adds the specified key-value pair.) * * O(1) * * @ par am key * @ par am value * @return the previous value associated with key, or null if there was no * mapping for key */ public V put(K key, V value);
/** * Removes the mapping for a key from this map if it is present. * * O(1) * * @par am key * @return the previous value associated with key, or null if there was no * mapping for key */ public V remove(K key);
/** * Determines the number of mappings in this map. * * O(1) * * @return the number of mappings in this map */ public int size(); }
Map Enrty class:
package assign09;
/** * This class represents a single entry in a map, i.e., a key-value pair. * * * @par am - placeholder for key type * @par am - placeholder for values type */ public class Map Entry {
private K key; private V value;
/** * Creates a new Map Entry with the specified key and value. * * @par am key * @par am value */ public Map Entry(K key, V value) { this. key = key; this. value = value; }
/** * @return the key of this Map Entry */ public K get Key() { return this .key; }
/** * @return the value of this Map Entry */ public V get Value() { return this. value; } /** * Resets the value of this Map Entry. * * @par am value */ public void set Value(V value) { this. value = value; } /** * Overrides Objects' s equals method to leverage the equals methods of the * key and value members. */ public Boolean equals(Object other) { if(!(other instance of Map Entry)) return false; Map Entry rhs = (Map Entry)other; return key. equals(rhs .key) && value .equals(rhs. value); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started