From fadc9d01f662ab001d9fdd0fd92c5f0c177557cd Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sat, 27 Jul 2019 23:10:16 -0400 Subject: Reimplement AbbrevMap, and implement Multimap This reimplements the old AbbrevMap structure as AbbrevMap2, and created a new Multimap structure as a apart of it. Multimap is exactly what it sounds like; a map that allows multiple values for a given key. The only real thing that is different about it, is that if you add a key-value pair multiple times, you'll have to remove it multiple times. --- src/main/java/bjc/esodata/ThresholdSet.java | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/main/java/bjc/esodata/ThresholdSet.java') diff --git a/src/main/java/bjc/esodata/ThresholdSet.java b/src/main/java/bjc/esodata/ThresholdSet.java index 245eb5f..cc7c0e1 100644 --- a/src/main/java/bjc/esodata/ThresholdSet.java +++ b/src/main/java/bjc/esodata/ThresholdSet.java @@ -2,6 +2,8 @@ package bjc.esodata; import java.util.*; +import bjc.data.*; + /** * Represents a counted set, that overflows to a map. * @@ -80,7 +82,8 @@ public class ThresholdSet { private Set keySet; // @TODO :CountMap Ben Culkin 6/19/2019 - // Replace this with a CountSet or some equivalent concept, whenever that gets written + // Replace this with a CountSet or some equivalent concept, whenever that gets written, if that + // gets written private Map keyMap; /** @@ -94,8 +97,9 @@ public class ThresholdSet { /** * Add multiple keys at once to the map. * - * @param keys - * The keys to add. + * @param key + * The keys to add. + * * @return An array containing the results of adding the keys. */ public int[] addKeys(KeyType... keys) { @@ -112,7 +116,8 @@ public class ThresholdSet { * Add a key to the collection. * * @param key - * The key to add to the collection. + * The key to add to the collection. + * * @return The number of times that key now exists in the collection. Should always be < 0. */ public int add(KeyType key) { @@ -226,6 +231,20 @@ public class ThresholdSet { return keyMap.get(key); } + /** + * Get a set containing all of the values that are in this set at least once. + * + * @return A set containing every value that occurs at least once in this set. + */ + public Set values() { + Set retSet = new HashSet<>(); + + retSet.addAll(keySet); + retSet.addAll(keyMap.keySet()); + + return retSet; + } + /** * Get a view of this collection as a java.util.Set. * -- cgit v1.2.3