MCPcopy Create free account
hub / github.com/Berkeley-CS61B/skeleton-sp23 / MyHashMapFactory

Class MyHashMapFactory

lab08/src/hashmap/MyHashMapFactory.java:13–36  ·  view source on GitHub ↗

This is a helper factory class that allows us to test different bucket types without having to write a separate test for each one. You don't need to understand how this works. Please don't modify this class unless you REALLY know what you're doing. @author Noah Adhikari, Spring 2023

Source from the content-addressed store, hash-verified

11 * @author Noah Adhikari, Spring 2023
12 */
13public class MyHashMapFactory {
14
15 /** Returns a MyHashMap with the specified bucket type.
16 * @param bucketType the type of bucket to use
17 */
18 public static <K, V> MyHashMap<K, V> createBucketedMap(Class<? extends Collection> bucketType) {
19 return new MyHashMap<>() {
20 @Override
21 protected Collection<Node> createBucket() {
22 try {
23 return bucketType.getConstructor().newInstance();
24 } catch (Exception e) {
25 throw new RuntimeException(e);
26 }
27 }
28
29 // for the timing tests
30 @Override
31 public String toString() {
32 return "MyHashMap with " + bucketType.getSimpleName() + " buckets";
33 }
34 };
35 }
36}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected