Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me implement those methods 1 package cse12pa6student 3 import java.util.List 6 public interface DefaultHapek, V> t *Sets key to hold value: *- If key

image text in transcribed
image text in transcribedHelp me implement those methods
1 package cse12pa6student 3 import java.util.List 6 public interface DefaultHapek, 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) Throws IllegaLArgumentException if key is null (there is no such restrction *for vatue) 2 16 void set(K key, V value); 19 Returns the value associated with key if it has been set 21If the defaultValue is null and the key is not found, throws * NoSuchElementException If key is not found and defaultvalue is non-nutl, returns the defaultvatue 26 Throws Illega LArgunentException if key is null 27 28 V get(K key) 30e* * Returns true if the given key was set by set, false othervise * Throws IllegaLArgumentException itt key is nult 34boolean containsKey(K key): : Returns the number of key/va lue pairs 39 int size) 40 41* * Returns the default vatue for this nap V defaultValue(); 46 42: * Returns a list of all keys in any order 49 Listc keys) s Returns a list of all vatues in any order Listev> vatues); MacBook Air Part I: An Implementation of DefaultMap You'l provide a fast implementation of an interface called DefaultHap in DefaultMapmpt.java. You can implement it however you like, but we recommend using one of Java's built in Map implementations (like HashMap or TreeMap) with the adapter pattern. The special feature of DefaultHap 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, Integer> thisMap new DefaultMapImplo(8): assertEquals(0, (int)thisMap.get("C")) assertEquals(e, (int)thisMap.get("A")): thisTree . set ("C", 3000); 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 NoSuchElenentException: DefaultMapcString, Integers thisMap - new DefauttMapImplo(nul)i thisMap.get("A"): I/ Throws NoSuchE LementExcept ion You will implement all the methods defined in the Defaul tHap interface. You must ensure that each 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 O(1) where O(log(n)) is required) is entries in the map. acceptable. In each, n represents the number of set, required Oflog(n) e get, required Ollog(n) e containskey, required Oflogin)) . keys, required O(n) " values, required Ofn) size, required O(1) defaultValue, required Oft MacBook Air 3 5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions