diff options
Diffstat (limited to 'src/main/java/bjc/esodata')
| -rw-r--r-- | src/main/java/bjc/esodata/AbbrevMap2.java | 15 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/DefaultList.java | 6 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/Directory.java | 3 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/DoubleTape.java | 29 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/MapSet.java | 9 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/Multimap.java | 14 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/PushdownMap.java | 19 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/QueueStack.java | 21 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/SimpleDirectory.java | 21 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/SimpleStack.java | 21 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/SingleTape.java | 63 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/SpaghettiStack.java | 27 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/Stack.java | 36 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/ThresholdSet.java | 30 | ||||
| -rw-r--r-- | src/main/java/bjc/esodata/UnifiedDirectory.java | 21 |
15 files changed, 121 insertions, 214 deletions
diff --git a/src/main/java/bjc/esodata/AbbrevMap2.java b/src/main/java/bjc/esodata/AbbrevMap2.java index f131aec..259c963 100644 --- a/src/main/java/bjc/esodata/AbbrevMap2.java +++ b/src/main/java/bjc/esodata/AbbrevMap2.java @@ -36,9 +36,7 @@ public class AbbrevMap2 { */ public void add(String... words) { for (String word : words) { - for (String substr : genAbbrevs(word)) { - backing.add(substr, word); - } + for (String substr : genAbbrevs(word)) backing.add(substr, word); } } @@ -65,9 +63,7 @@ public class AbbrevMap2 { */ public void removeWords(String... words) { for (String word : words) { - for (String substr : genAbbrevs(word)) { - backing.remove(substr, word); - } + for (String substr : genAbbrevs(word)) backing.remove(substr, word); } } @@ -95,10 +91,7 @@ public class AbbrevMap2 { public String deabbrev(String word) { Set<String> st = backing.get(word); - if (st.size() == 1) { - return st.iterator().next(); - } else { - return null; - } + if (st.size() == 1) return st.iterator().next(); + else return null; } } diff --git a/src/main/java/bjc/esodata/DefaultList.java b/src/main/java/bjc/esodata/DefaultList.java index c4535bd..e622301 100644 --- a/src/main/java/bjc/esodata/DefaultList.java +++ b/src/main/java/bjc/esodata/DefaultList.java @@ -90,10 +90,8 @@ public class DefaultList<ValueType> extends AbstractList<ValueType> { @Override public ValueType get(int idx) { - if (idx < 0 || idx >= backing.size()) - return defVal; - - return backing.get(idx); + if (idx < 0 || idx >= backing.size()) return defVal; + else return backing.get(idx); } @Override diff --git a/src/main/java/bjc/esodata/Directory.java b/src/main/java/bjc/esodata/Directory.java index e083cd8..fa47b6f 100644 --- a/src/main/java/bjc/esodata/Directory.java +++ b/src/main/java/bjc/esodata/Directory.java @@ -59,8 +59,7 @@ public interface Directory<K, V> { * @return The new sub-directory, or null if one by that name already exists. */ default Directory<K, V> newSubdirectory(final K key) { - if (hasSubdirectory(key)) - return null; + if (hasSubdirectory(key)) return null; final Directory<K, V> dir = new SimpleDirectory<>(); diff --git a/src/main/java/bjc/esodata/DoubleTape.java b/src/main/java/bjc/esodata/DoubleTape.java index cc7cdb9..30d94a1 100644 --- a/src/main/java/bjc/esodata/DoubleTape.java +++ b/src/main/java/bjc/esodata/DoubleTape.java @@ -112,9 +112,7 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided { public boolean left(final int amt) { final boolean succ = front.left(amt); - if (succ) { - back.right(amt); - } + if (succ) back.right(amt); return succ; } @@ -128,9 +126,7 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided { public boolean right(final int amt) { final boolean succ = front.right(amt); - if (succ) { - back.left(amt); - } + if (succ) back.left(amt); return succ; } @@ -167,26 +163,23 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided { @Override public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof DoubleTape<?>)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof DoubleTape<?>)) return false; final DoubleTape<?> other = (DoubleTape<?>) obj; if (back == null) { - if (other.back != null) - return false; - } else if (!back.equals(other.back)) + if (other.back != null) return false; + } else if (!back.equals(other.back)) { return false; + } if (front == null) { - if (other.front != null) - return false; - } else if (!front.equals(other.front)) + if (other.front != null) return false; + } else if (!front.equals(other.front)) { return false; + } return true; } diff --git a/src/main/java/bjc/esodata/MapSet.java b/src/main/java/bjc/esodata/MapSet.java index a80c482..7d77ad6 100644 --- a/src/main/java/bjc/esodata/MapSet.java +++ b/src/main/java/bjc/esodata/MapSet.java @@ -116,8 +116,7 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType> * @return False if there is no map attached to the key, true otherwise. */ public boolean setMap(String key) { - if (!backing.containsKey(key)) - return false; + if (!backing.containsKey(key)) return false; currentMap = backing.get(key); @@ -165,16 +164,14 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType> @Override public Set<Map.Entry<KeyType, ValueType>> entrySet() { - if (currentMap == null) - throw new NullPointerException("Current map is not set"); + if (currentMap == null) throw new NullPointerException("Current map is not set"); return currentMap.entrySet(); } @Override public ValueType put(KeyType key, ValueType value) { - if (currentMap == null) - throw new NullPointerException("Current map is not set"); + if (currentMap == null) throw new NullPointerException("Current map is not set"); return currentMap.put(key, value); } diff --git a/src/main/java/bjc/esodata/Multimap.java b/src/main/java/bjc/esodata/Multimap.java index a79f1b0..fae872e 100644 --- a/src/main/java/bjc/esodata/Multimap.java +++ b/src/main/java/bjc/esodata/Multimap.java @@ -51,9 +51,8 @@ public class Multimap<KeyType, ValueType> { */ public void remove(KeyType key, ValueType value) { // We have no values for that key; bail. - if (!backing.containsKey(key)) - return; - + if (!backing.containsKey(key)) return; + backing.get(key).remove(value); } @@ -76,10 +75,8 @@ public class Multimap<KeyType, ValueType> { * @return A set containing all of the values that have been mapped to that key. */ public Set<ValueType> get(KeyType key) { - if (!backing.containsKey(key)) - return new HashSet<>(); - - return backing.get(key).values(); + if (!backing.containsKey(key)) return new HashSet<>(); + else return backing.get(key).values(); } /** @@ -107,8 +104,7 @@ public class Multimap<KeyType, ValueType> { * mapping. */ public boolean contains(KeyType key, ValueType value) { - if (!backing.containsKey(key)) - return false; + if (!backing.containsKey(key)) return false; return backing.get(key).contains(value) > 0; } diff --git a/src/main/java/bjc/esodata/PushdownMap.java b/src/main/java/bjc/esodata/PushdownMap.java index 54ae939..a10c149 100644 --- a/src/main/java/bjc/esodata/PushdownMap.java +++ b/src/main/java/bjc/esodata/PushdownMap.java @@ -113,9 +113,7 @@ public class PushdownMap<KeyType, ValueType> implements IMap<KeyType, ValueType> public ValueType remove(final KeyType key) { final Stack<ValueType> stk = backing.get(key); - if (stk.size() > 1) { - return stk.pop(); - } + if (stk.size() > 1) return stk.pop(); return backing.remove(key).top(); } @@ -137,20 +135,17 @@ public class PushdownMap<KeyType, ValueType> implements IMap<KeyType, ValueType> @Override public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof PushdownMap<?, ?>)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof PushdownMap<?, ?>)) return false; final PushdownMap<?, ?> other = (PushdownMap<?, ?>) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) + if (other.backing != null) return false; + } else if (!backing.equals(other.backing)) { return false; + } return true; } diff --git a/src/main/java/bjc/esodata/QueueStack.java b/src/main/java/bjc/esodata/QueueStack.java index c40721a..e310f16 100644 --- a/src/main/java/bjc/esodata/QueueStack.java +++ b/src/main/java/bjc/esodata/QueueStack.java @@ -29,16 +29,14 @@ public class QueueStack<T> extends Stack<T> { @Override public T pop() { - if (backing.isEmpty()) - throw new StackUnderflow(); + if (backing.isEmpty()) throw new StackUnderflow(); return backing.remove(); } @Override public T top() { - if (backing.isEmpty()) - throw new StackUnderflow(); + if (backing.isEmpty()) throw new StackUnderflow(); return backing.peek(); } @@ -76,20 +74,17 @@ public class QueueStack<T> extends Stack<T> { @Override public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof QueueStack<?>)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof QueueStack<?>)) return false; final QueueStack<?> other = (QueueStack<?>) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) + if (other.backing != null) return false; + } else if (!backing.equals(other.backing)) { return false; + } return true; } diff --git a/src/main/java/bjc/esodata/SimpleDirectory.java b/src/main/java/bjc/esodata/SimpleDirectory.java index 672d92f..36f5f5a 100644 --- a/src/main/java/bjc/esodata/SimpleDirectory.java +++ b/src/main/java/bjc/esodata/SimpleDirectory.java @@ -71,26 +71,23 @@ public class SimpleDirectory<K, V> implements Directory<K, V> { @Override public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof SimpleDirectory<?, ?>)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof SimpleDirectory<?, ?>)) return false; final SimpleDirectory<?, ?> other = (SimpleDirectory<?, ?>) obj; if (children == null) { - if (other.children != null) - return false; - } else if (!children.equals(other.children)) + if (other.children != null) return false; + } else if (!children.equals(other.children)) { return false; + } if (data == null) { - if (other.data != null) - return false; - } else if (!data.equals(other.data)) + if (other.data != null) return false; + } else if (!data.equals(other.data)) { return false; + } return true; } diff --git a/src/main/java/bjc/esodata/SimpleStack.java b/src/main/java/bjc/esodata/SimpleStack.java index b50521e..9c016c3 100644 --- a/src/main/java/bjc/esodata/SimpleStack.java +++ b/src/main/java/bjc/esodata/SimpleStack.java @@ -27,16 +27,14 @@ public class SimpleStack<T> extends Stack<T> { @Override public T pop() { - if (backing.isEmpty()) - throw new StackUnderflow(); + if (backing.isEmpty()) throw new StackUnderflow(); return backing.pop(); } @Override public T top() { - if (backing.isEmpty()) - throw new StackUnderflow(); + if (backing.isEmpty()) throw new StackUnderflow(); return backing.peek(); } @@ -69,20 +67,17 @@ public class SimpleStack<T> extends Stack<T> { @Override public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof SimpleStack<?>)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof SimpleStack<?>)) return false; final SimpleStack<?> other = (SimpleStack<?>) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) + if (other.backing != null) return false; + } else if (!backing.equals(other.backing)) { return false; + } return true; } diff --git a/src/main/java/bjc/esodata/SingleTape.java b/src/main/java/bjc/esodata/SingleTape.java index ec56e2b..7c3a34f 100644 --- a/src/main/java/bjc/esodata/SingleTape.java +++ b/src/main/java/bjc/esodata/SingleTape.java @@ -45,9 +45,7 @@ public class SingleTape<T> implements Tape<T> { backing = new ArrayList<>(vals.length); - for (T val : vals) { - backing.add(val); - } + for (T val : vals) backing.add(val); } /** @@ -66,9 +64,7 @@ public class SingleTape<T> implements Tape<T> { public SingleTape(Iterable<T> itr) { this(false); - for (T itm : itr) { - backing.add(itm); - } + for (T itm : itr) backing.add(itm); } /** @@ -86,8 +82,7 @@ public class SingleTape<T> implements Tape<T> { @Override public T item() { - if (pos < 0 || pos >= backing.size()) - return null; + if (pos < 0 || pos >= backing.size()) return null; return backing.get(pos); } @@ -114,19 +109,16 @@ public class SingleTape<T> implements Tape<T> { @Override public void insertAfter(final T itm) { - if (pos == backing.size() - 1) { - backing.add(itm); - } else { - backing.add(pos + 1, itm); - } + if (pos == backing.size() - 1) backing.add(itm); + else backing.add(pos + 1, itm); } @Override public T remove() { final T res = backing.remove(pos); - if (pos != 0) { - pos -= 1; - } + + if (pos != 0) pos -= 1; + return res; } @@ -147,8 +139,7 @@ public class SingleTape<T> implements Tape<T> { @Override public boolean left(final int amt) { - if (pos - amt < 0) - return false; + if (pos - amt < 0) return false; pos -= amt; return true; @@ -163,11 +154,10 @@ public class SingleTape<T> implements Tape<T> { public boolean right(final int amt) { if (pos + amt > backing.size()) { if (autoExtend) { - while (pos + amt >= backing.size() - 1) { - backing.add(null); - } - } else + while (pos + amt >= backing.size() - 1) backing.add(null); + } else { return false; + } } pos += amt; @@ -176,15 +166,15 @@ public class SingleTape<T> implements Tape<T> { @Override public boolean seekTo(int tgtPos) { - if (tgtPos < 0) - return false; + if (tgtPos < 0) return false; - if (tgtPos >= backing.size() - 1) - if (autoExtend) - while (tgtPos >= backing.size() - 1) - backing.add(null); - else + if (tgtPos >= backing.size() - 1) { + if (autoExtend) { + while (tgtPos >= backing.size() - 1) backing.add(null); + } else { return false; + } + } pos = tgtPos; @@ -208,20 +198,17 @@ public class SingleTape<T> implements Tape<T> { @Override public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof SingleTape<?>)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof SingleTape<?>)) return false; final SingleTape<?> other = (SingleTape<?>) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) + if (other.backing != null) return false; + } else if (!backing.equals(other.backing)) { return false; + } return true; } diff --git a/src/main/java/bjc/esodata/SpaghettiStack.java b/src/main/java/bjc/esodata/SpaghettiStack.java index fc3e154..4bd77d3 100644 --- a/src/main/java/bjc/esodata/SpaghettiStack.java +++ b/src/main/java/bjc/esodata/SpaghettiStack.java @@ -37,16 +37,14 @@ class SpaghettiStack<T> extends Stack<T> { @Override public T pop() { - if (backing.isEmpty()) - return parent.pop(); + if (backing.isEmpty()) return parent.pop(); return backing.pop(); } @Override public T top() { - if (backing.isEmpty()) - return parent.top(); + if (backing.isEmpty()) return parent.top(); return backing.top(); } @@ -82,26 +80,23 @@ class SpaghettiStack<T> extends Stack<T> { @Override public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof SpaghettiStack<?>)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof SpaghettiStack<?>)) return false; final SpaghettiStack<?> other = (SpaghettiStack<?>) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) + if (other.backing != null) return false; + } else if (!backing.equals(other.backing)) { return false; + } if (parent == null) { - if (other.parent != null) - return false; - } else if (!parent.equals(other.parent)) + if (other.parent != null) return false; + } else if (!parent.equals(other.parent)) { return false; + } return true; } diff --git a/src/main/java/bjc/esodata/Stack.java b/src/main/java/bjc/esodata/Stack.java index 5ee5ef2..360e57d 100644 --- a/src/main/java/bjc/esodata/Stack.java +++ b/src/main/java/bjc/esodata/Stack.java @@ -96,9 +96,7 @@ public abstract class Stack<T> { * The elements to insert. */ public void pushAll(@SuppressWarnings("unchecked") T... elms) { - for (T elm : elms) { - push(elm); - } + for (T elm : elms) push(elm); } /** @@ -108,9 +106,7 @@ public abstract class Stack<T> { * The elements to insert. */ public void pushAll(List<T> elms) { - for (T elm : elms) { - push(elm); - } + for (T elm : elms) push(elm); } /** @@ -124,9 +120,7 @@ public abstract class Stack<T> { public List<T> multipop(int n) { List<T> lst = new LinkedList<>(); - for (int i = 0; i < n; i++) { - lst.add(pop()); - } + for (int i = 0; i < n; i++) lst.add(pop()); return lst; } @@ -142,9 +136,7 @@ public abstract class Stack<T> { public List<T> multipoprev(int n) { LinkedList<T> lst = new LinkedList<>(); - for (int i = 0; i < n; i++) { - lst.addFirst(pop()); - } + for (int i = 0; i < n; i++) lst.addFirst(pop()); return lst; } @@ -160,9 +152,7 @@ public abstract class Stack<T> { * The number of items to drop. */ public void drop(final int n) { - for (int i = 0; i < n; i++) { - pop(); - } + for (int i = 0; i < n; i++) pop(); } /** Drop one item from the stack. */ @@ -201,9 +191,7 @@ public abstract class Stack<T> { public void multidup(final int n, final int m) { List<T> lst = multipoprev(n); - for (int i = 0; i <= m; i++) { - pushAll(lst); - } + for (int i = 0; i <= m; i++) pushAll(lst); } /** @@ -235,15 +223,11 @@ public abstract class Stack<T> { List<T> lst = multipoprev(n); - for (final T nelm : lst) { - push(nelm); - } + for (final T nelm : lst) push(nelm); push(elm); - for (int i = 0; i < m; i++) { - pushAll(lst); - } + for (int i = 0; i < m; i++) pushAll(lst); } /** @@ -555,9 +539,7 @@ public abstract class Stack<T> { public void multiapply(final int n, final int m, final Consumer<Stack<T>> action) { final List<Consumer<Stack<T>>> actions = new ArrayList<>(m); - for (int i = 0; i < m; i++) { - actions.add(action); - } + for (int i = 0; i < m; i++) actions.add(action); multispread(n, actions); } diff --git a/src/main/java/bjc/esodata/ThresholdSet.java b/src/main/java/bjc/esodata/ThresholdSet.java index ae277e1..9b8560b 100644 --- a/src/main/java/bjc/esodata/ThresholdSet.java +++ b/src/main/java/bjc/esodata/ThresholdSet.java @@ -37,8 +37,7 @@ public class ThresholdSet<KeyType> { int ret = ThresholdSet.this.add(key); // No change to set contents - if (ret > 2) - return false; + if (ret > 2) return false; return true; } @@ -52,8 +51,7 @@ public class ThresholdSet<KeyType> { int ret = ThresholdSet.this.remove(k); // We removed the element. - if (ret == 0) - return true; + if (ret == 0) return true; return false; } @@ -67,8 +65,7 @@ public class ThresholdSet<KeyType> { int ret = ThresholdSet.this.contains(k); // The object is set-visible - if (ret == 1) - return true; + if (ret == 1) return true; return false; } @@ -112,9 +109,7 @@ public class ThresholdSet<KeyType> { public int[] addKeys(@SuppressWarnings("unchecked") KeyType... keys) { int[] ret = new int[keys.length]; - for (int i = 0; i < keys.length; i++) { - ret[i] = add(keys[i]); - } + for (int i = 0; i < keys.length; i++) ret[i] = add(keys[i]); return ret; } @@ -162,9 +157,7 @@ public class ThresholdSet<KeyType> { public int[] removeKeys(@SuppressWarnings("unchecked") KeyType... keys) { int[] ret = new int[keys.length]; - for (int i = 0; i < keys.length; i++) { - ret[i] = remove(keys[i]); - } + for (int i = 0; i < keys.length; i++) ret[i] = remove(keys[i]); return ret; } @@ -217,9 +210,7 @@ public class ThresholdSet<KeyType> { public int[] containsKeys(@SuppressWarnings("unchecked") KeyType... keys) { int[] ret = new int[keys.length]; - for (int i = 0; i < keys.length; i++) { - ret[i] = contains(keys[i]); - } + for (int i = 0; i < keys.length; i++) ret[i] = contains(keys[i]); return ret; } @@ -233,12 +224,9 @@ public class ThresholdSet<KeyType> { * @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; - - return keyMap.get(key); + if (keySet.contains(key)) return 1; + if (!keyMap.containsKey(key)) return -1; + else return keyMap.get(key); } /** diff --git a/src/main/java/bjc/esodata/UnifiedDirectory.java b/src/main/java/bjc/esodata/UnifiedDirectory.java index 2221615..dcbac89 100644 --- a/src/main/java/bjc/esodata/UnifiedDirectory.java +++ b/src/main/java/bjc/esodata/UnifiedDirectory.java @@ -82,26 +82,23 @@ public class UnifiedDirectory<K, V> implements Directory<K, V> { @Override public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof UnifiedDirectory<?, ?>)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof UnifiedDirectory<?, ?>)) return false; final UnifiedDirectory<?, ?> other = (UnifiedDirectory<?, ?>) obj; if (children == null) { - if (other.children != null) - return false; - } else if (!children.equals(other.children)) + if (other.children != null) return false; + } else if (!children.equals(other.children)) { return false; + } if (data == null) { - if (other.data != null) - return false; - } else if (!data.equals(other.data)) + if (other.data != null) return false; + } else if (!data.equals(other.data)) { return false; + } return true; } |
