summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/bjc/data/QueuedIterator.java2
-rw-r--r--src/main/java/bjc/esodata/AbbrevMap.java409
-rw-r--r--src/main/java/bjc/esodata/ThresholdSet.java8
3 files changed, 211 insertions, 208 deletions
diff --git a/src/main/java/bjc/data/QueuedIterator.java b/src/main/java/bjc/data/QueuedIterator.java
index 8071106..eabfb79 100644
--- a/src/main/java/bjc/data/QueuedIterator.java
+++ b/src/main/java/bjc/data/QueuedIterator.java
@@ -196,7 +196,7 @@ public class QueuedIterator<E> implements Iterator<E> {
/**
* Add a new set of values who we will iterate through last.
*
- * @param itr
+ * @param vals
* The iterable to go through last.
*/
public void last(E... vals) {
diff --git a/src/main/java/bjc/esodata/AbbrevMap.java b/src/main/java/bjc/esodata/AbbrevMap.java
index 048577d..51ec5c0 100644
--- a/src/main/java/bjc/esodata/AbbrevMap.java
+++ b/src/main/java/bjc/esodata/AbbrevMap.java
@@ -1,207 +1,206 @@
package bjc.esodata;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import bjc.funcdata.FunctionalMap;
-import bjc.funcdata.IMap;
-
-// /**
-// * Represents a mapping from a set of strings to a mapping of all unambiguous
-// * prefixes of their respective strings.
-// *
-// * This works the same as Ruby's Abbrev module.
-// *
-// * @author EVE
-// */
-// public class AbbrevMap {
-// /* All of the words we have abbreviations for. */
-// private final Set<String> wrds;
-
-// /* Maps abbreviations to their strings. */
-// private IMap<String, String> abbrevMap;
-
-// /* Counts how many times we've seen a substring. */
-// private Set<String> seen;
-
-// /* Maps ambiguous abbreviations to the strings they could be. */
-// private SetMultimap<String, String> ambMap;
-
-// /**
-// * Create a new abbreviation map.
-// *
-// * @param words
-// * The initial set of words to put in the map.
-// */
-// public AbbrevMap(final String... words) {
-// wrds = new HashSet<>(Arrays.asList(words));
-
-// recalculate();
-// }
-
-// /**
-// * Recalculate all the abbreviations in this map.
-// *
-// * This may be needed after certain operations to ensure that all of the
-// * results are correct.
-// */
-// public void recalculate() {
-// abbrevMap = new FunctionalMap<>();
-
-// ambMap = HashMultimap.create();
-
-// seen = new HashSet<>();
-
-// for(final String word : wrds) {
-// intAddWord(word);
-// }
-// }
-
-// /**
-// * Adds words to the abbreviation map.
-// *
-// * @param words
-// * The words to add to the abbreviation map.
-// */
-// public void addWords(final String... words) {
-// wrds.addAll(Arrays.asList(words));
-
-// for(final String word : words) {
-// intAddWord(word);
-// }
-// }
-
-// /* Actually add abbreviations of a word. */
-// private void intAddWord(final String word) {
-// /* A word always abbreviates to itself. */
-// abbrevMap.put(word, word);
-
-// /* Skip blank words. */
-// if(word.equals("")) return;
-
-// /* Handle each possible abbreviation. */
-// for(int i = word.length(); i > 0; i--) {
-// final String subword = word.substring(0, i);
-
-// if(seen.contains(subword)) {
-// /*
-// * Remove a mapping if its ambiguous and not a
-// * whole word.
-// */
-// if(abbrevMap.containsKey(subword) && !wrds.contains(subword)) {
-// final String oldword = abbrevMap.remove(subword);
-
-// ambMap.put(subword, oldword);
-// ambMap.put(subword, word);
-// } else if(!wrds.contains(subword)) {
-// ambMap.put(subword, word);
-// }
-// } else {
-// seen.add(subword);
-
-// abbrevMap.put(subword, word);
-// }
-// }
-// }
-
-// /**
-// * Removes words from the abbreviation map.
-// *
-// * NOTE: There may be inconsistent behavior after removing a word from
-// * the map. Use {@link AbbrevMap#recalculate()} to fix it if it occurs.
-// *
-// * @param words
-// * The words to remove.
-// */
-// public void removeWords(final String... words) {
-// wrds.removeAll(Arrays.asList(words));
-
-// for(final String word : words) {
-// intRemoveWord(word);
-// }
-// }
-
-// /* Actually remove a word. */
-// private void intRemoveWord(final String word) {
-// /* Skip blank words. */
-// if(word.equals("")) return;
-
-// /* Handle each possible abbreviation. */
-// for(int i = word.length(); i > 0; i--) {
-// final String subword = word.substring(0, i);
-
-// if(abbrevMap.containsKey(subword)) {
-// abbrevMap.remove(subword);
-// } else {
-// ambMap.remove(subword, word);
-
-// final Set<String> possWords = ambMap.get(subword);
-
-// if(possWords.size() == 0) {
-// seen.remove(subword);
-// } else if(possWords.size() == 1) {
-// /*
-// * An abbreviation went from ambiguous
-// * to non-ambiguous.
-// */
-// final String newWord = possWords.iterator().next();
-
-// abbrevMap.put(subword, newWord);
-// ambMap.remove(subword, newWord);
-// }
-// }
-// }
-// }
-
-// /**
-// * Convert an abbreviation into all the strings it could abbreviate
-// * into.
-// *
-// * @param abbrev
-// * The abbreviation to convert.
-// *
-// * @return All the expansions for the provided abbreviation.
-// */
-// public String[] deabbrev(final String abbrev) {
-// if(abbrevMap.containsKey(abbrev)) {
-// return new String[] {
-// abbrevMap.get(abbrev)
-// };
-// }
-
-// return ambMap.get(abbrev).toArray(new String[0]);
-// }
-
-// @Override
-// public int hashCode() {
-// final int prime = 31;
-
-// int result = 1;
-// result = prime * result + (wrds == null ? 0 : wrds.hashCode());
-
-// return result;
-// }
-
-// @Override
-// public boolean equals(final Object obj) {
-// if(this == obj) return true;
-// if(obj == null) return false;
-// if(!(obj instanceof AbbrevMap)) return false;
-
-// final AbbrevMap other = (AbbrevMap) obj;
-
-// if(wrds == null) {
-// if(other.wrds != null) return false;
-// } else if(!wrds.equals(other.wrds)) return false;
-
-// return true;
-// }
-
-// @Override
-// public String toString() {
-// final String fmt = "AbbrevMap [wrds=%s, abbrevMap=%s, seen=%s, ambMap=%s]";
-
-// return String.format(fmt, wrds, abbrevMap, seen, ambMap);
-// }
-// }
+import java.util.*;
+
+import bjc.funcdata.*;
+
+/*
+ * Represents a mapping from a set of strings to a mapping of all unambiguous
+ * prefixes of their respective strings.
+ *
+ * This works the same as Ruby's Abbrev module.
+ *
+ * @author EVE
+ */
+//public class AbbrevMap {
+// private ThresholdSet<String> wordSet;
+//
+// /* All of the words we have abbreviations for. */
+// private final Set<String> wrds;
+//
+// /* Maps abbreviations to their strings. */
+// private IMap<String, String> abbrevMap;
+//
+// /* Counts how many times we've seen a substring. */
+// private Set<String> seen;
+//
+// /* Maps ambiguous abbreviations to the strings they could be. */
+// private SetMultimap<String, String> ambMap;
+//
+// /**
+// * Create a new abbreviation map.
+// *
+// * @param words
+// * The initial set of words to put in the map.
+// */
+// public AbbrevMap(final String... words) {
+// wrds = new HashSet<>(Arrays.asList(words));
+//
+// recalculate();
+// }
+//
+// /**
+// * Recalculate all the abbreviations in this map.
+// *
+// * This may be needed after certain operations to ensure that all of the
+// * results are correct.
+// */
+// public void recalculate() {
+// abbrevMap = new FunctionalMap<>();
+//
+// ambMap = HashMultimap.create();
+//
+// seen = new HashSet<>();
+//
+// for(final String word : wrds) {
+// intAddWord(word);
+// }
+// }
+//
+// /**
+// * Adds words to the abbreviation map.
+// *
+// * @param words
+// * The words to add to the abbreviation map.
+// */
+// public void addWords(final String... words) {
+// wrds.addAll(Arrays.asList(words));
+//
+// for(final String word : words) {
+// intAddWord(word);
+// }
+// }
+//
+// /* Actually add abbreviations of a word. */
+// private void intAddWord(final String word) {
+// /* A word always abbreviates to itself. */
+// abbrevMap.put(word, word);
+//
+// /* Skip blank words. */
+// if(word.equals("")) return;
+//
+// /* Handle each possible abbreviation. */
+// for(int i = word.length(); i > 0; i--) {
+// final String subword = word.substring(0, i);
+//
+// if(seen.contains(subword)) {
+// /*
+// * Remove a mapping if its ambiguous and not a
+// * whole word.
+// */
+// if(abbrevMap.containsKey(subword) && !wrds.contains(subword)) {
+// final String oldword = abbrevMap.remove(subword);
+//
+// ambMap.put(subword, oldword);
+// ambMap.put(subword, word);
+// } else if(!wrds.contains(subword)) {
+// ambMap.put(subword, word);
+// }
+// } else {
+// seen.add(subword);
+//
+// abbrevMap.put(subword, word);
+// }
+// }
+// }
+//
+// /**
+// * Removes words from the abbreviation map.
+// *
+// * NOTE: There may be inconsistent behavior after removing a word from
+// * the map. Use {@link AbbrevMap#recalculate()} to fix it if it occurs.
+// *
+// * @param words
+// * The words to remove.
+// */
+// public void removeWords(final String... words) {
+// wrds.removeAll(Arrays.asList(words));
+//
+// for(final String word : words) {
+// intRemoveWord(word);
+// }
+// }
+//
+// /* Actually remove a word. */
+// private void intRemoveWord(final String word) {
+// /* Skip blank words. */
+// if(word.equals("")) return;
+//
+// /* Handle each possible abbreviation. */
+// for(int i = word.length(); i > 0; i--) {
+// final String subword = word.substring(0, i);
+//
+// if(abbrevMap.containsKey(subword)) {
+// abbrevMap.remove(subword);
+// } else {
+// ambMap.remove(subword, word);
+//
+// final Set<String> possWords = ambMap.get(subword);
+//
+// if(possWords.size() == 0) {
+// seen.remove(subword);
+// } else if(possWords.size() == 1) {
+// /*
+// * An abbreviation went from ambiguous
+// * to non-ambiguous.
+// */
+// final String newWord = possWords.iterator().next();
+//
+// abbrevMap.put(subword, newWord);
+// ambMap.remove(subword, newWord);
+// }
+// }
+// }
+// }
+//
+// /**
+// * Convert an abbreviation into all the strings it could abbreviate
+// * into.
+// *
+// * @param abbrev
+// * The abbreviation to convert.
+// *
+// * @return All the expansions for the provided abbreviation.
+// */
+// public String[] deabbrev(final String abbrev) {
+// if(abbrevMap.containsKey(abbrev)) {
+// return new String[] {
+// abbrevMap.get(abbrev)
+// };
+// }
+//
+// return ambMap.get(abbrev).toArray(new String[0]);
+// }
+//
+// @Override
+// public int hashCode() {
+// final int prime = 31;
+//
+// int result = 1;
+// result = prime * result + (wrds == null ? 0 : wrds.hashCode());
+//
+// return result;
+// }
+//
+// @Override
+// public boolean equals(final Object obj) {
+// if(this == obj) return true;
+// if(obj == null) return false;
+// if(!(obj instanceof AbbrevMap)) return false;
+//
+// final AbbrevMap other = (AbbrevMap) obj;
+//
+// if(wrds == null) {
+// if(other.wrds != null) return false;
+// } else if(!wrds.equals(other.wrds)) return false;
+//
+// return true;
+// }
+//
+// @Override
+// public String toString() {
+// final String fmt = "AbbrevMap [wrds=%s, abbrevMap=%s, seen=%s, ambMap=%s]";
+//
+// return String.format(fmt, wrds, abbrevMap, seen, ambMap);
+// }
+//}
diff --git a/src/main/java/bjc/esodata/ThresholdSet.java b/src/main/java/bjc/esodata/ThresholdSet.java
index b6f677e..20b4ceb 100644
--- a/src/main/java/bjc/esodata/ThresholdSet.java
+++ b/src/main/java/bjc/esodata/ThresholdSet.java
@@ -16,7 +16,7 @@ import java.util.*;
* 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
*/
@@ -71,7 +71,9 @@ public class ThresholdSet<KeyType> {
}
}
+ // Set of uniquely stored keys
private Set<KeyType> keySet;
+
// @TODO :CountMap Ben Culkin 6/19/2019
// Replace this with a CountSet or some equivalent concept, whenever that gets written
private Map<KeyType, Integer> keyMap;
@@ -189,7 +191,7 @@ public class ThresholdSet<KeyType> {
/**
* Get the number of times the set contains a set of given keys.
*
- * @param key
+ * @param keys
* The keys to look for.
*
* @return The containment counts for each key.
@@ -228,6 +230,8 @@ public class ThresholdSet<KeyType> {
return new SetView();
}
+ // Implementation methods for setView
+
int setSize() {
return keySet.size();
}