summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/esodata/ThresholdSet.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/bjc/esodata/ThresholdSet.java')
-rw-r--r--src/main/java/bjc/esodata/ThresholdSet.java74
1 files changed, 42 insertions, 32 deletions
diff --git a/src/main/java/bjc/esodata/ThresholdSet.java b/src/main/java/bjc/esodata/ThresholdSet.java
index 6076a2a..50d95d0 100644
--- a/src/main/java/bjc/esodata/ThresholdSet.java
+++ b/src/main/java/bjc/esodata/ThresholdSet.java
@@ -7,16 +7,18 @@ import java.util.*;
*
* More specifically, this is a set/map combo type.
*
- * Initially, when you add an item, it will go into the set. Attempting to add a duplicate item to
- * that set will cause the entry to be removed from the set, and added to the map, which will count
- * the number of times that particular item has been added to the set. If you remove enough copies
- * of that item to put it back down to 1 copy, that copy will be removed from the map, and readded
- * to the set.
+ * Initially, when you add an item, it will go into the set. Attempting to add a
+ * duplicate item to that set will cause the entry to be removed from the set,
+ * and added to the map, which will count the number of times that particular
+ * item has been added to the set. If you remove enough copies of that item to
+ * put it back down to 1 copy, that copy will be removed from the map, and
+ * readded to the set.
*
- * The iterator that this type gives by default is an iterator over all of the values in the set,
- * not including any of those in the map.
+ * The iterator that this type gives by default is an iterator over all of the
+ * values in the set, not including any of those in the map.
*
- * @param <KeyType> The value being counted.
+ * @param <KeyType>
+ * The value being counted.
*
* @author Ben Culkin
*/
@@ -24,30 +26,33 @@ public class ThresholdSet<KeyType> {
// View of this class as a java.util.Set
private class SetView extends AbstractSet<KeyType> {
/*
- * This is technically not a valid implementation of add, because it does not guarantee that
- * the set will contain key after it returns (as a matter of fact, attempting to add the
- * component might actually cause it to be removed from the collection).
+ * This is technically not a valid implementation of add, because it does not
+ * guarantee that the set will contain key after it returns (as a matter of
+ * fact, attempting to add the component might actually cause it to be removed
+ * from the collection).
*/
@Override
public boolean add(KeyType key) {
// Qualified-this; allows us to reference the 'this' of our enclosing type.
int ret = ThresholdSet.this.add(key);
-
+
// No change to set contents
- if (ret > 2) return false;
+ if (ret > 2)
+ return false;
return true;
}
-
+
@Override
public boolean remove(Object o) {
// Will throw a ClassCastException if you give us something bad.
- KeyType k = (KeyType)o;
+ KeyType k = (KeyType) o;
int ret = ThresholdSet.this.remove(k);
// We removed the element.
- if (ret == 0) return true;
+ if (ret == 0)
+ return true;
return false;
}
@@ -55,12 +60,13 @@ public class ThresholdSet<KeyType> {
@Override
public boolean contains(Object o) {
// Will throw a ClassCastException if you give us something bad.
- KeyType k = (KeyType)o;
+ KeyType k = (KeyType) o;
int ret = ThresholdSet.this.contains(k);
// The object is set-visible
- if (ret == 1) return true;
+ if (ret == 1)
+ return true;
return false;
}
@@ -80,7 +86,8 @@ public class ThresholdSet<KeyType> {
private Set<KeyType> keySet;
// @TODO :CountMap Ben Culkin 6/19/2019
- // Replace this with a CountSet or some equivalent concept, whenever that gets written, if that
+ // Replace this with a CountSet or some equivalent concept, whenever that gets
+ // written, if that
// gets written
private Map<KeyType, Integer> keyMap;
@@ -95,8 +102,8 @@ public class ThresholdSet<KeyType> {
/**
* Add multiple keys at once to the map.
*
- * @param keys
- * The keys to add.
+ * @param keys
+ * The keys to add.
*
* @return An array containing the results of adding the keys.
*/
@@ -114,9 +121,10 @@ public class ThresholdSet<KeyType> {
* 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 &lt; 0.
+ * @return The number of times that key now exists in the collection. Should
+ * always be &lt; 0.
*/
public int add(KeyType key) {
if (keySet.contains(key)) {
@@ -145,7 +153,7 @@ public class ThresholdSet<KeyType> {
* Remove a bunch of keys from the collection.
*
* @param keys
- * The keys to remove from the collection.
+ * The keys to remove from the collection.
*
* @return The results from removing the keys.
*/
@@ -163,10 +171,10 @@ public class ThresholdSet<KeyType> {
* Remove a key from the collection.
*
* @param key
- * The key to remove from the collection.
+ * The key to remove from the collection.
*
- * @return The number of times that key now exists in the collection. Returns -1 if that key
- * wasn't in the collection beforehand.
+ * @return The number of times that key now exists in the collection. Returns -1
+ * if that key wasn't in the collection beforehand.
*/
public int remove(KeyType key) {
if (keySet.contains(key)) {
@@ -200,7 +208,7 @@ public class ThresholdSet<KeyType> {
* Get the number of times the set contains a set of given keys.
*
* @param keys
- * The keys to look for.
+ * The keys to look for.
*
* @return The containment counts for each key.
*/
@@ -218,13 +226,15 @@ public class ThresholdSet<KeyType> {
* Get the number of times the set contains a given key.
*
* @param key
- * The key to look for.
+ * The key to look for.
*
* @return The number of times the key occurs; -1 if it doesn't occur.
*/
public int contains(KeyType key) {
- if (keySet.contains(key)) return 1;
- if (!keyMap.containsKey(key)) return -1;
+ if (keySet.contains(key))
+ return 1;
+ if (!keyMap.containsKey(key))
+ return -1;
return keyMap.get(key);
}
@@ -256,7 +266,7 @@ public class ThresholdSet<KeyType> {
* Static threshold set constructor.
*
* @param keys
- * The initial keys to add to the threshold set.
+ * The initial keys to add to the threshold set.
*/
@SafeVarargs
public static <KType> ThresholdSet<KType> TS(KType... keys) {