From 275a627719fc2231b16caea41130ff09f0f2b6a1 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Fri, 8 Apr 2016 13:28:09 -0400 Subject: Switch functional data to use interfaces --- .../java/bjc/utils/funcdata/IFunctionalMap.java | 104 +++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java new file mode 100644 index 0000000..9bd62bc --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java @@ -0,0 +1,104 @@ +package bjc.utils.funcdata; + +import java.util.function.BiConsumer; +import java.util.function.Function; + +/** + * Functional wrapper over map providing some useful things + * + * @author ben + * + * @param + * The type of this map's keys + * @param + * The type of this map's values + * + */ +public interface IFunctionalMap { + + /** + * Add an entry to the map + * + * @param key + * The key to put the value under + * @param val + * The value to add + * @return The previous value of the key in the map, or null if the key + * wasn't in the map. However, note that it may also return + * null if the key was set to null. + * + * @throws UnsupportedOperationException + * if the map implementation doesn't support modifying the + * map + */ + V put(K key, V val); + + /** + * Get the value assigned to the given key + * + * @param key + * The key to look for a value under + * @return The value of the key + * + * + */ + V get(K key); + + /** + * Transform the values returned by this map. + * + * NOTE: This transform is applied once for each lookup of a value, so + * the transform passed should be a proper function, or things will + * likely not work as expected. + * + * @param + * The new type of returned values + * @param transformer + * The function to use to transform values + * @return The map where each value will be transformed after lookup + */ + IFunctionalMap mapValues(Function transformer); + + /** + * Check if this map contains the specified key + * + * @param key + * The key to check + * @return Whether or not the map contains the key + */ + boolean containsKey(K key); + + /** + * Get a list of all the keys in this map + * + * @return A list of all the keys in this map + */ + IFunctionalList keyList(); + + /** + * Execute an action for each entry in the map + * + * @param action + * the action to execute for each entry in the map + */ + void forEach(BiConsumer action); + + /** + * Remove the value bound to the key + * + * @param key + * The key to remove from the map + * @return The previous value for the key in the map, or null if the + * key wasn't in the class. NOTE: Just because you recieved + * null, doesn't mean the map wasn't changed. It may mean that + * someone put a null value for that key into the map + */ + V remove(K key); + + /** + * Get the number of entries in this map + * + * @return The number of entries in this map + */ + int getSize(); +} \ No newline at end of file -- cgit v1.2.3