Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you implement the interface and fill out the methods using any data structures . Part l: An Implementation of DefaultMap You'll provide a fast
Can you implement the interface and fill out the methods using any data structures . Part l: An Implementation of DefaultMap You'll provide a fast implementation of an interface called DefaultHap in DefaultMapImpt. java. You can implement it however you like, but we recommend using one of Java's bult in Map implementations (like HashMap or TreeMap) with the adapter pattern. The special feature of DefaultMap is that it will be constructed with a default value that it returns for keys that aren't found. So, for example, a default map constructed with a 0 default value will return 0 for all keys that aren't present: DefaultMapeString, Integers thisMap new DefaultMapImplo(e): assertEquals(, (int)thisMap.get("C")) assertEquats(e, (int)thisMap.get("A")): thisTree.set("C", 3800); assertEquals(3800, (int)thisMap.get("C")); assertEquals(e, (int)thisMap.get ("A")): In addition, if nult is provided as the default value, any attempt to get a key that isn't set should result in a NoSuchElesentException: DefaultMap-String, Integers thisMap new DefauttMapImplo(nul)i thisMap.get("A"): I1 Throws NoSuchE LesentException You will implement all the methods defined in the DefaultHap interface. You must ensure that eacih has the specified big-O bound in the average case, and argue why based on the documentation of any libraries you use, or based on your implementation. Note that these are big-O bounds, so doing better (like 0(1) where O(login) is required) is acceptable. In each, n represents the number of entries in the map. ' set, required Oflog)) e get, required Ollog(n) e containskey, required Oflogin)) . keys, required Ofn) " values, required Ofn) size, required On) defaultVaLue, required Off MacBook Air 3 5 1 package csel2pa6student 3 import java.util.List; 6 public interface DefaultMapx, v> t /* *Sets key to hold value: *- If key is not present, adds it (size increases) * - If key is present, updates it (size doesn't increase) 2 Throws IllegaLArgumentException if key is null (there is no such restriction 13 *for vatue) 16 void set(K key, V value); 17 19 * Returns the value associated with key i, it has been set 20 21If the defaultValue is null and the key is not found, throws * NoSuchElementException 23 2I key is not found and defaultvalue is non-nutt, returns the defaultvatue 25 26 Throws IllegaLArgunentException if key is null 27 28 29 30e* V get(K key); * Returns true if the given key was et by set, false otherwise Throws Tllega LArgumentException itt key is nult 34 boolean containsKey(K key) s Returns the number of key/value pairs 38 39 int size) 40 41 * * Returns the defautt vatue for this nap v defaultValue(): 45 * Returns a list of all keys in any order 48 49 Listc keys): : Returns a list of all vatues in any order Listevs vatues); MacBook Air
Can you implement the interface and fill out the methods using any data structures .
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