com.codepoetics.fluvius.scratchpad.HashMapScratchpadStorage Maven / Gradle / Ivy
package com.codepoetics.fluvius.scratchpad;
import com.codepoetics.fluvius.api.scratchpad.Key;
import com.codepoetics.fluvius.api.scratchpad.ScratchpadStorage;
import com.codepoetics.fluvius.preconditions.Preconditions;
import java.util.HashMap;
import java.util.Map;
final class HashMapScratchpadStorage implements ScratchpadStorage {
public static ScratchpadStorage empty() {
return new HashMapScratchpadStorage(new HashMap, Object>());
}
private final Map, Object> storage;
private HashMapScratchpadStorage(Map, Object> storage) {
this.storage = storage;
}
@Override
public boolean containsKey(Key> key) {
return storage.containsKey(key);
}
@Override
public void put(Key> key, Object value) {
storage.put(key, value);
}
@Override
public T get(Key key) {
return Preconditions.checkNotNull("value of key " + key.getName(), (T) storage.get(key));
}
@Override
public ScratchpadStorage copy() {
return new HashMapScratchpadStorage(new HashMap<>(storage));
}
@Override
public String toString() {
return storage.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy