You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

28 lines
797 B

/**
* Copyright 2022 Jamie Munro, Distributed under the Common Public Attribution License Version 1.0 (CPAL-1.0)
* Tile engine
*/
import java.util.HashMap;
/**
* DefaultHashMap Class
* Simple extension of the built in HashMap class to provide a default object when no object with the supplied key can be found.
* Taken from maerics's stackoverflow answer here: https://stackoverflow.com/a/7519422
*/
class DefaultHashMap<K,V> extends HashMap<K,V> {
protected V defaultValue;
/**
* Public constructor
* @param defaultValue object to be returned if no object with matching key is found
*/
public DefaultHashMap(V defaultValue) {
this.defaultValue = defaultValue;
}
@Override
public V get(Object k) {
return containsKey(k) ? super.get(k) : defaultValue;
}
}