From 889fac2bdf993dc86f64a8893c0260fdcf848acb Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 10 Apr 2017 16:40:33 -0400 Subject: Cleanup --- .../src/main/java/bjc/utils/esodata/AbbrevMap.java | 92 ++++++++--------- .../src/main/java/bjc/utils/esodata/Directory.java | 7 +- .../main/java/bjc/utils/esodata/DoubleTape.java | 47 ++++----- .../main/java/bjc/utils/esodata/PushdownMap.java | 65 ++++++------ .../main/java/bjc/utils/esodata/QueueStack.java | 31 +++--- .../java/bjc/utils/esodata/SimpleDirectory.java | 45 ++++----- .../main/java/bjc/utils/esodata/SimpleStack.java | 32 +++--- .../main/java/bjc/utils/esodata/SingleTape.java | 43 ++++---- .../java/bjc/utils/esodata/SpaghettiStack.java | 43 ++++---- .../src/main/java/bjc/utils/esodata/Stack.java | 111 +++++++++++---------- .../src/main/java/bjc/utils/esodata/Tape.java | 7 +- .../main/java/bjc/utils/esodata/TapeChanger.java | 90 +++++++---------- .../main/java/bjc/utils/esodata/TapeLibrary.java | 89 +++++++---------- .../java/bjc/utils/esodata/UnifiedDirectory.java | 49 ++++----- 14 files changed, 326 insertions(+), 425 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/esodata') diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/AbbrevMap.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/AbbrevMap.java index 433f672..75c3c1b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/AbbrevMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/AbbrevMap.java @@ -1,21 +1,21 @@ package bjc.utils.esodata; -import bjc.utils.funcdata.FunctionalMap; -import bjc.utils.funcdata.IMap; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import com.google.common.collect.HashMultimap; import com.google.common.collect.SetMultimap; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import bjc.utils.funcdata.FunctionalMap; +import bjc.utils.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. - * + * * @author EVE * */ @@ -23,7 +23,7 @@ public class AbbrevMap { /* * All of the words we have abbreviations for. */ - private Set wrds; + private final Set wrds; /* * Maps abbreviations to their strings. @@ -42,11 +42,11 @@ public class AbbrevMap { /** * Create a new abbreviation map. - * + * * @param words * The initial set of words to put in the map. */ - public AbbrevMap(String... words) { + public AbbrevMap(final String... words) { wrds = new HashSet<>(Arrays.asList(words)); recalculate(); @@ -62,7 +62,7 @@ public class AbbrevMap { seen = new HashSet<>(); - for (String word : wrds) { + for (final String word : wrds) { /* * A word always abbreviates to itself. */ @@ -74,14 +74,14 @@ public class AbbrevMap { /** * Adds words to the abbreviation map. - * + * * @param words * The words to add to the abbreviation map. */ - public void addWords(String... words) { + public void addWords(final String... words) { wrds.addAll(Arrays.asList(words)); - for (String word : words) { + for (final String word : words) { /* * A word always abbreviates to itself. */ @@ -94,18 +94,17 @@ public class AbbrevMap { /* * Actually add abbreviations of a word. */ - private void intAddWord(String word) { + private void intAddWord(final String word) { /* * Skip blank words. */ - if (word.equals("")) - return; + if (word.equals("")) return; /* * Handle each possible abbreviation. */ for (int i = word.length(); i > 0; i--) { - String subword = word.substring(0, i); + final String subword = word.substring(0, i); if (seen.contains(subword)) { /* @@ -113,7 +112,7 @@ public class AbbrevMap { * whole word. */ if (abbrevMap.containsKey(subword) && !wrds.contains(subword)) { - String oldword = abbrevMap.remove(subword); + final String oldword = abbrevMap.remove(subword); ambMap.put(subword, oldword); ambMap.put(subword, word); @@ -130,17 +129,17 @@ public class AbbrevMap { /** * Removes words from the abbreviation map. - * + * * NOTE: There may be inconsistent behavior. Use * {@link AbbrevMap#recalculate()} to fix it if it occurs. - * + * * @param words * The words to remove. */ - public void removeWords(String... words) { + public void removeWords(final String... words) { wrds.removeAll(Arrays.asList(words)); - for (String word : words) { + for (final String word : words) { intRemoveWord(word); } } @@ -148,30 +147,29 @@ public class AbbrevMap { /* * Actually remove a word. */ - private void intRemoveWord(String word) { + private void intRemoveWord(final String word) { /* * Skip blank words. */ - if (word.equals("")) - return; + if (word.equals("")) return; /* * Handle each possible abbreviation. */ for (int i = word.length(); i > 0; i--) { - String subword = word.substring(0, i); + final String subword = word.substring(0, i); - if (abbrevMap.containsKey(subword)) + if (abbrevMap.containsKey(subword)) { abbrevMap.remove(subword); - else { + } else { ambMap.remove(subword, word); - Set possWords = ambMap.get(subword); + final Set possWords = ambMap.get(subword); if (possWords.size() == 0) { seen.remove(subword); } else if (possWords.size() == 1) { - String newWord = possWords.iterator().next(); + final String newWord = possWords.iterator().next(); abbrevMap.put(subword, newWord); ambMap.remove(subword, newWord); @@ -183,17 +181,16 @@ public class AbbrevMap { /** * 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(String abbrev) { + public String[] deabbrev(final String abbrev) { if (abbrevMap.containsKey(abbrev)) return new String[] { abbrevMap.get(abbrev) }; - else - return ambMap.get(abbrev).toArray(new String[0]); + else return ambMap.get(abbrev).toArray(new String[0]); } @Override @@ -201,34 +198,29 @@ public class AbbrevMap { final int prime = 31; int result = 1; - result = prime * result + ((wrds == null) ? 0 : wrds.hashCode()); + result = prime * result + (wrds == null ? 0 : wrds.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof AbbrevMap)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof AbbrevMap)) return false; - AbbrevMap other = (AbbrevMap) obj; + final AbbrevMap other = (AbbrevMap) obj; if (wrds == null) { - if (other.wrds != null) - return false; - } else if (!wrds.equals(other.wrds)) - return false; + if (other.wrds != null) return false; + } else if (!wrds.equals(other.wrds)) return false; return true; } @Override public String toString() { - String fmt = "AbbrevMap [wrds=%s, abbrevMap=%s, seen=%s, ambMap=%s]"; + final String fmt = "AbbrevMap [wrds=%s, abbrevMap=%s, seen=%s, ambMap=%s]"; return String.format(fmt, wrds, abbrevMap, seen, ambMap); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java index 52e3172..17b70f5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java @@ -59,11 +59,10 @@ public interface Directory { * @return The new sub-directory, or null if one by that name already * exists. */ - default Directory newSubdirectory(K key) { - if (hasSubdirectory(key)) - return null; + default Directory newSubdirectory(final K key) { + if (hasSubdirectory(key)) return null; - Directory dir = new SimpleDirectory<>(); + final Directory dir = new SimpleDirectory<>(); putSubdirectory(key, dir); diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java index 8df7aa9..0faaabf 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java @@ -42,7 +42,7 @@ public class DoubleTape implements Tape { * Whether or not to auto-extend the tape to the right w/ * nulls. */ - public DoubleTape(boolean autoExtnd) { + public DoubleTape(final boolean autoExtnd) { front = new SingleTape<>(autoExtnd); back = new SingleTape<>(autoExtnd); } @@ -64,7 +64,7 @@ public class DoubleTape implements Tape { * The new value for the tape item. */ @Override - public void item(T itm) { + public void item(final T itm) { front.item(itm); } @@ -85,7 +85,7 @@ public class DoubleTape implements Tape { * The item to add. */ @Override - public void insertBefore(T itm) { + public void insertBefore(final T itm) { front.insertBefore(itm); back.insertAfter(null); } @@ -94,7 +94,7 @@ public class DoubleTape implements Tape { * Insert an element after the current item. */ @Override - public void insertAfter(T itm) { + public void insertAfter(final T itm) { front.insertAfter(itm); back.insertBefore(itm); } @@ -156,8 +156,8 @@ public class DoubleTape implements Tape { * @return True if the cursor was moved left. */ @Override - public boolean left(int amt) { - boolean succ = front.left(amt); + public boolean left(final int amt) { + final boolean succ = front.left(amt); if (succ) { back.right(amt); @@ -189,8 +189,8 @@ public class DoubleTape implements Tape { * @return Whether the cursor was moved right. */ @Override - public boolean right(int amt) { - boolean succ = front.right(amt); + public boolean right(final int amt) { + final boolean succ = front.right(amt); if (succ) { back.left(amt); @@ -206,7 +206,7 @@ public class DoubleTape implements Tape { * active. */ public void flip() { - Tape tmp = front; + final Tape tmp = front; front = back; @@ -222,33 +222,26 @@ public class DoubleTape implements Tape { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((back == null) ? 0 : back.hashCode()); - result = prime * result + ((front == null) ? 0 : front.hashCode()); + result = prime * result + (back == null ? 0 : back.hashCode()); + result = prime * result + (front == null ? 0 : front.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof DoubleTape)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof DoubleTape)) return false; - DoubleTape other = (DoubleTape) obj; + final DoubleTape other = (DoubleTape) obj; if (back == null) { - if (other.back != null) - return false; - } else if (!back.equals(other.back)) - return false; + 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)) - return false; + if (other.front != null) return false; + } else if (!front.equals(other.front)) return false; return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/PushdownMap.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/PushdownMap.java index bf72f29..a631704 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/PushdownMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/PushdownMap.java @@ -1,17 +1,17 @@ package bjc.utils.esodata; -import bjc.utils.funcdata.FunctionalMap; -import bjc.utils.funcdata.IList; -import bjc.utils.funcdata.IMap; - import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; +import bjc.utils.funcdata.FunctionalMap; +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.IMap; + /** * A variant of a map where inserting a duplicate key shadows the existing value * instead of replacing it. - * + * * @author EVE * * @param @@ -20,7 +20,7 @@ import java.util.function.Function; * The values in the map. */ public class PushdownMap implements IMap { - private IMap> backing; + private final IMap> backing; /** * Create a new empty stack-based map. @@ -29,7 +29,7 @@ public class PushdownMap implements IMap backing = new FunctionalMap<>(); } - private PushdownMap(IMap> back) { + private PushdownMap(final IMap> back) { backing = back; } @@ -39,7 +39,7 @@ public class PushdownMap implements IMap } @Override - public boolean containsKey(KeyType key) { + public boolean containsKey(final KeyType key) { return backing.containsKey(key); } @@ -49,22 +49,22 @@ public class PushdownMap implements IMap } @Override - public void forEach(BiConsumer action) { + public void forEach(final BiConsumer action) { backing.forEach((key, stk) -> action.accept(key, stk.top())); } @Override - public void forEachKey(Consumer action) { + public void forEachKey(final Consumer action) { backing.forEachKey(action); } @Override - public void forEachValue(Consumer action) { + public void forEachValue(final Consumer action) { backing.forEachValue(stk -> action.accept(stk.top())); } @Override - public ValueType get(KeyType key) { + public ValueType get(final KeyType key) { return backing.get(key).top(); } @@ -79,22 +79,22 @@ public class PushdownMap implements IMap } @Override - public IMap transform(Function transformer) { + public IMap transform(final Function transformer) { throw new UnsupportedOperationException("Cannot transform pushdown maps."); } @Override - public ValueType put(KeyType key, ValueType val) { + public ValueType put(final KeyType key, final ValueType val) { if (backing.containsKey(key)) { - Stack stk = backing.get(key); + final Stack stk = backing.get(key); - ValueType vl = stk.top(); + final ValueType vl = stk.top(); stk.push(val); return vl; } else { - Stack stk = new SimpleStack<>(); + final Stack stk = new SimpleStack<>(); stk.push(val); @@ -103,14 +103,12 @@ public class PushdownMap implements IMap } @Override - public ValueType remove(KeyType key) { - Stack stk = backing.get(key); + public ValueType remove(final KeyType key) { + final Stack stk = backing.get(key); - if (stk.size() > 1) { + if (stk.size() > 1) return stk.pop(); - } else { - return backing.remove(key).top(); - } + else return backing.remove(key).top(); } @Override @@ -123,27 +121,22 @@ public class PushdownMap implements IMap final int prime = 31; int result = 1; - result = prime * result + ((backing == null) ? 0 : backing.hashCode()); + result = prime * result + (backing == null ? 0 : backing.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof PushdownMap)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof PushdownMap)) return false; - PushdownMap other = (PushdownMap) obj; + final PushdownMap other = (PushdownMap) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) - return false; + if (other.backing != null) return false; + } else if (!backing.equals(other.backing)) return false; return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java index ebb9d8c..850598a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java @@ -11,7 +11,7 @@ import java.util.LinkedList; * @author Ben Culkin */ public class QueueStack extends Stack { - private Deque backing; + private final Deque backing; /** * Create a new empty stack queue. @@ -22,22 +22,20 @@ public class QueueStack extends Stack { } @Override - public void push(T elm) { + public void push(final T elm) { backing.add(elm); } @Override public T pop() { - if (backing.isEmpty()) - throw new StackUnderflowException(); + if (backing.isEmpty()) throw new StackUnderflowException(); return backing.remove(); } @Override public T top() { - if (backing.isEmpty()) - throw new StackUnderflowException(); + if (backing.isEmpty()) throw new StackUnderflowException(); return backing.peek(); } @@ -68,27 +66,22 @@ public class QueueStack extends Stack { final int prime = 31; int result = 1; - result = prime * result + ((backing == null) ? 0 : backing.hashCode()); + result = prime * result + (backing == null ? 0 : backing.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof QueueStack)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof QueueStack)) return false; - QueueStack other = (QueueStack) obj; + final QueueStack other = (QueueStack) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) - return false; + if (other.backing != null) return false; + } else if (!backing.equals(other.backing)) return false; return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java index bab64f5..69fd019 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java @@ -16,9 +16,9 @@ import bjc.utils.funcdata.IMap; * The value type of the directory. */ public class SimpleDirectory implements Directory { - private IMap> children; + private final IMap> children; - private IMap data; + private final IMap data; /** * Create a new directory. @@ -29,32 +29,32 @@ public class SimpleDirectory implements Directory { } @Override - public Directory getSubdirectory(K key) { + public Directory getSubdirectory(final K key) { return children.get(key); } @Override - public boolean hasSubdirectory(K key) { + public boolean hasSubdirectory(final K key) { return children.containsKey(key); } @Override - public Directory putSubdirectory(K key, Directory val) { + public Directory putSubdirectory(final K key, final Directory val) { return children.put(key, val); } @Override - public boolean containsKey(K key) { + public boolean containsKey(final K key) { return data.containsKey(key); } @Override - public V getKey(K key) { + public V getKey(final K key) { return data.get(key); } @Override - public V putKey(K key, V val) { + public V putKey(final K key, final V val) { return data.put(key, val); } @@ -63,34 +63,27 @@ public class SimpleDirectory implements Directory { final int prime = 31; int result = 1; - result = prime * result + ((children == null) ? 0 : children.hashCode()); - result = prime * result + ((data == null) ? 0 : data.hashCode()); + result = prime * result + (children == null ? 0 : children.hashCode()); + result = prime * result + (data == null ? 0 : data.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof SimpleDirectory)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof SimpleDirectory)) return false; - SimpleDirectory other = (SimpleDirectory) obj; + final SimpleDirectory other = (SimpleDirectory) obj; if (children == null) { - if (other.children != null) - return false; - } else if (!children.equals(other.children)) - return false; + 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)) - return false; + if (other.data != null) return false; + } else if (!data.equals(other.data)) return false; return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java index 0e109aa..fdb3300 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java @@ -11,7 +11,7 @@ import java.util.LinkedList; * @author Ben Culkin */ public class SimpleStack extends Stack { - private Deque backing; + private final Deque backing; /** * Create a new empty stack. @@ -22,22 +22,20 @@ public class SimpleStack extends Stack { } @Override - public void push(T elm) { + public void push(final T elm) { backing.push(elm); } @Override public T pop() { - if (backing.isEmpty()) - throw new StackUnderflowException(); + if (backing.isEmpty()) throw new StackUnderflowException(); return backing.pop(); } @Override public T top() { - if (backing.isEmpty()) - throw new StackUnderflowException(); + if (backing.isEmpty()) throw new StackUnderflowException(); return backing.peek(); } @@ -52,6 +50,7 @@ public class SimpleStack extends Stack { return backing.size() == 0; } + @Override @SuppressWarnings("unchecked") public T[] toArray() { return (T[]) backing.toArray(); @@ -62,27 +61,22 @@ public class SimpleStack extends Stack { final int prime = 31; int result = 1; - result = prime * result + ((backing == null) ? 0 : backing.hashCode()); + result = prime * result + (backing == null ? 0 : backing.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof SimpleStack)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof SimpleStack)) return false; - SimpleStack other = (SimpleStack) obj; + final SimpleStack other = (SimpleStack) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) - return false; + if (other.backing != null) return false; + } else if (!backing.equals(other.backing)) return false; return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java index 253c15f..a3e5462 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java @@ -16,7 +16,7 @@ import java.util.ArrayList; * * @param * The element type of the tape. - * + * * @author bjculkin */ public class SingleTape implements Tape { @@ -40,7 +40,7 @@ public class SingleTape implements Tape { * Whether or not to auto-extend the tape to the right w/ * nulls. */ - public SingleTape(boolean autoExtnd) { + public SingleTape(final boolean autoExtnd) { autoExtend = autoExtnd; backing = new ArrayList<>(); @@ -63,7 +63,7 @@ public class SingleTape implements Tape { * The new value for the tape item. */ @Override - public void item(T itm) { + public void item(final T itm) { backing.set(pos, itm); } @@ -84,7 +84,7 @@ public class SingleTape implements Tape { * The item to add. */ @Override - public void insertBefore(T itm) { + public void insertBefore(final T itm) { backing.add(pos, itm); } @@ -92,7 +92,7 @@ public class SingleTape implements Tape { * Insert an element after the current item. */ @Override - public void insertAfter(T itm) { + public void insertAfter(final T itm) { if (pos == backing.size() - 1) { backing.add(itm); } else { @@ -110,7 +110,7 @@ public class SingleTape implements Tape { */ @Override public T remove() { - T res = backing.remove(pos); + final T res = backing.remove(pos); if (pos != 0) { pos -= 1; } @@ -157,9 +157,8 @@ public class SingleTape implements Tape { * @return True if the cursor was moved left. */ @Override - public boolean left(int amt) { - if (pos - amt < 0) - return false; + public boolean left(final int amt) { + if (pos - amt < 0) return false; pos -= amt; return true; @@ -188,14 +187,13 @@ public class SingleTape implements Tape { * @return Whether the cursor was moved right. */ @Override - public boolean right(int amt) { + public boolean right(final int amt) { if (pos + amt >= backing.size() - 1) { if (autoExtend) { while (pos + amt >= backing.size() - 1) { backing.add(null); } - } else - return false; + } else return false; } pos += amt; @@ -212,27 +210,22 @@ public class SingleTape implements Tape { final int prime = 31; int result = 1; - result = prime * result + ((backing == null) ? 0 : backing.hashCode()); + result = prime * result + (backing == null ? 0 : backing.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof SingleTape)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof SingleTape)) return false; - SingleTape other = (SingleTape) obj; + final SingleTape other = (SingleTape) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) - return false; + if (other.backing != null) return false; + } else if (!backing.equals(other.backing)) return false; return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java index 6fc4766..7c8c757 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java @@ -11,9 +11,9 @@ import java.util.stream.Stream; * @author Ben Culkin */ class SpaghettiStack extends Stack { - private Stack backing; + private final Stack backing; - private Stack parent; + private final Stack parent; /** * Create a new empty spaghetti stack, off of the specified parent. @@ -21,29 +21,27 @@ class SpaghettiStack extends Stack { * @param par * The parent stack */ - public SpaghettiStack(Stack par) { + public SpaghettiStack(final Stack par) { backing = new SimpleStack<>(); parent = par; } @Override - public void push(T elm) { + public void push(final T elm) { backing.push(elm); } @Override public T pop() { - if (backing.empty()) - return parent.pop(); + if (backing.empty()) return parent.pop(); return backing.pop(); } @Override public T top() { - if (backing.empty()) - return parent.top(); + if (backing.empty()) return parent.top(); return backing.top(); } @@ -69,34 +67,27 @@ class SpaghettiStack extends Stack { final int prime = 31; int result = 1; - result = prime * result + ((backing == null) ? 0 : backing.hashCode()); - result = prime * result + ((parent == null) ? 0 : parent.hashCode()); + result = prime * result + (backing == null ? 0 : backing.hashCode()); + result = prime * result + (parent == null ? 0 : parent.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof SpaghettiStack)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof SpaghettiStack)) return false; - SpaghettiStack other = (SpaghettiStack) obj; + final SpaghettiStack other = (SpaghettiStack) obj; if (backing == null) { - if (other.backing != null) - return false; - } else if (!backing.equals(other.backing)) - return false; + 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)) - return false; + if (other.parent != null) return false; + } else if (!parent.equals(other.parent)) return false; return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java index 217c671..9d74e9a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java @@ -17,21 +17,26 @@ import java.util.function.Consumer; * thrown. Check the size of the stack if you want to avoid this. *

*

- * + * * @param * The datatype stored in the stack. - * + * * @author Ben Culkin */ public abstract class Stack { /** * The exception thrown when attempting to access an element from the * stack that isn't there. - * + * * @author EVE * */ public static class StackUnderflowException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1423867176204571539L; } /** @@ -52,7 +57,7 @@ public abstract class Stack { /** * Retrieve the top element of this stack without removing it from the * stack. - * + * * @return The top element of this stack. */ public abstract T top(); @@ -90,7 +95,7 @@ public abstract class Stack { * @param n * The number of items to drop. */ - public void drop(int n) { + public void drop(final int n) { for (int i = 0; i < n; i++) { pop(); } @@ -109,8 +114,8 @@ public abstract class Stack { * @param n * The number of items below the top to delete. */ - public void nip(int n) { - T elm = pop(); + public void nip(final int n) { + final T elm = pop(); drop(n); @@ -132,15 +137,15 @@ public abstract class Stack { * @param m * The number of times to duplicate items. */ - public void multidup(int n, int m) { - List lst = new ArrayList<>(n); + public void multidup(final int n, final int m) { + final List lst = new ArrayList<>(n); for (int i = n; i > 0; i--) { lst.set(i - 1, pop()); } for (int i = 0; i < m; i++) { - for (T elm : lst) { + for (final T elm : lst) { push(elm); } } @@ -152,7 +157,7 @@ public abstract class Stack { * @param n * The number of items to duplicate. */ - public void dup(int n) { + public void dup(final int n) { multidup(n, 2); } @@ -171,22 +176,22 @@ public abstract class Stack { * @param m * The number of times to duplicate items. */ - public void multiover(int n, int m) { - List lst = new ArrayList<>(n); + public void multiover(final int n, final int m) { + final List lst = new ArrayList<>(n); - T elm = pop(); + final T elm = pop(); for (int i = n; i > 0; i--) { lst.set(i - 1, pop()); } - for (T nelm : lst) { + for (final T nelm : lst) { push(nelm); } push(elm); for (int i = 1; i < m; i++) { - for (T nelm : lst) { + for (final T nelm : lst) { push(nelm); } } @@ -198,7 +203,7 @@ public abstract class Stack { * @param n * The number of items to duplicate. */ - public void over(int n) { + public void over(final int n) { multiover(n, 2); } @@ -213,9 +218,9 @@ public abstract class Stack { * Duplicate the third item in the stack. */ public void pick() { - T z = pop(); - T y = pop(); - T x = pop(); + final T z = pop(); + final T y = pop(); + final T x = pop(); push(x); push(y); @@ -227,8 +232,8 @@ public abstract class Stack { * Swap the top two items on the stack. */ public void swap() { - T y = pop(); - T x = pop(); + final T y = pop(); + final T x = pop(); push(y); push(x); @@ -238,8 +243,8 @@ public abstract class Stack { * Duplicate the second item below the first item. */ public void deepdup() { - T y = pop(); - T x = pop(); + final T y = pop(); + final T x = pop(); push(x); push(x); @@ -250,9 +255,9 @@ public abstract class Stack { * Swap the second and third items in the stack. */ public void deepswap() { - T z = pop(); - T y = pop(); - T x = pop(); + final T z = pop(); + final T y = pop(); + final T x = pop(); push(y); push(x); @@ -263,9 +268,9 @@ public abstract class Stack { * Rotate the top three items on the stack */ public void rot() { - T z = pop(); - T y = pop(); - T x = pop(); + final T z = pop(); + final T y = pop(); + final T x = pop(); push(y); push(z); @@ -276,9 +281,9 @@ public abstract class Stack { * Inversely rotate the top three items on the stack */ public void invrot() { - T z = pop(); - T y = pop(); - T x = pop(); + final T z = pop(); + final T y = pop(); + final T x = pop(); push(z); push(x); @@ -296,8 +301,8 @@ public abstract class Stack { * @param cons * The action to hide the elements from */ - public void dip(int n, Consumer> cons) { - List elms = new ArrayList<>(n); + public void dip(final int n, final Consumer> cons) { + final List elms = new ArrayList<>(n); for (int i = n; i > 0; i--) { elms.set(i - 1, pop()); @@ -305,7 +310,7 @@ public abstract class Stack { cons.accept(this); - for (T elm : elms) { + for (final T elm : elms) { push(elm); } } @@ -316,7 +321,7 @@ public abstract class Stack { * @param cons * The action to hide the top from */ - public void dip(Consumer> cons) { + public void dip(final Consumer> cons) { dip(1, cons); } @@ -329,7 +334,7 @@ public abstract class Stack { * @param cons * The action to execute. */ - public void keep(int n, Consumer> cons) { + public void keep(final int n, final Consumer> cons) { dup(n); dip(n, cons); } @@ -342,15 +347,15 @@ public abstract class Stack { * @param conses * The actions to execute. */ - public void multicleave(int n, List>> conses) { - List elms = new ArrayList<>(n); + public void multicleave(final int n, final List>> conses) { + final List elms = new ArrayList<>(n); for (int i = n; i > 0; i--) { elms.set(i - 1, pop()); } - for (Consumer> cons : conses) { - for (T elm : elms) { + for (final Consumer> cons : conses) { + for (final T elm : elms) { push(elm); } @@ -364,7 +369,7 @@ public abstract class Stack { * @param conses * The actions to execute. */ - public void cleave(List>> conses) { + public void cleave(final List>> conses) { multicleave(1, conses); } @@ -376,11 +381,11 @@ public abstract class Stack { * @param conses * The actions to execute. */ - public void multispread(int n, List>> conses) { - List> nelms = new ArrayList<>(conses.size()); + public void multispread(final int n, final List>> conses) { + final List> nelms = new ArrayList<>(conses.size()); for (int i = conses.size(); i > 0; i--) { - List elms = new ArrayList<>(n); + final List elms = new ArrayList<>(n); for (int j = n; j > 0; j--) { elms.set(j, pop()); @@ -390,8 +395,8 @@ public abstract class Stack { } int i = 0; - for (List elms : nelms) { - for (T elm : elms) { + for (final List elms : nelms) { + for (final T elm : elms) { push(elm); } @@ -406,7 +411,7 @@ public abstract class Stack { * @param conses * The actions to execute. */ - public void spread(List>> conses) { + public void spread(final List>> conses) { multispread(1, conses); } @@ -420,8 +425,8 @@ public abstract class Stack { * @param cons * The action to execute. */ - public void multiapply(int n, int m, Consumer> cons) { - List>> conses = new ArrayList<>(m); + public void multiapply(final int n, final int m, final Consumer> cons) { + final List>> conses = new ArrayList<>(m); for (int i = 0; i < m; i++) { conses.add(cons); @@ -438,7 +443,7 @@ public abstract class Stack { * @param cons * The action to execute. */ - public void apply(int n, Consumer> cons) { + public void apply(final int n, final Consumer> cons) { multiapply(1, n, cons); } @@ -447,7 +452,7 @@ public abstract class Stack { */ /** * Get an array representing this stack. - * + * * @return The stack as an array. */ public abstract T[] toArray(); diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java index f53f6f7..5f4c3a5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java @@ -9,7 +9,7 @@ package bjc.utils.esodata; * * @param * The element type of the tape. - * + * * @author bjculkin */ public interface Tape { @@ -45,8 +45,9 @@ public interface Tape { /** * Insert an element after the current item. - * - * @param itm The item to insert. + * + * @param itm + * The item to insert. */ void insertAfter(T itm); diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java index 10764fe..8b8613f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java @@ -32,12 +32,12 @@ public class TapeChanger implements Tape { * The tapes to put in this tape changer. */ @SafeVarargs - public TapeChanger(Tape current, Tape... others) { + public TapeChanger(final Tape current, final Tape... others) { this(); tapes.insertBefore(current); - for (Tape tp : others) { + for (final Tape tp : others) { tapes.insertAfter(tp); tapes.right(); } @@ -53,8 +53,7 @@ public class TapeChanger implements Tape { */ @Override public T item() { - if (currentTape == null) - return null; + if (currentTape == null) return null; return currentTape.item(); } @@ -66,9 +65,8 @@ public class TapeChanger implements Tape { * The new value for the tape item. */ @Override - public void item(T itm) { - if (currentTape == null) - return; + public void item(final T itm) { + if (currentTape == null) return; currentTape.item(itm); } @@ -80,8 +78,7 @@ public class TapeChanger implements Tape { */ @Override public int size() { - if (currentTape == null) - return 0; + if (currentTape == null) return 0; return currentTape.size(); } @@ -93,9 +90,8 @@ public class TapeChanger implements Tape { * The item to add. */ @Override - public void insertBefore(T itm) { - if (currentTape == null) - return; + public void insertBefore(final T itm) { + if (currentTape == null) return; currentTape.insertBefore(itm); } @@ -104,9 +100,8 @@ public class TapeChanger implements Tape { * Insert an element after the current item. */ @Override - public void insertAfter(T itm) { - if (currentTape == null) - return; + public void insertAfter(final T itm) { + if (currentTape == null) return; currentTape.insertAfter(itm); } @@ -121,8 +116,7 @@ public class TapeChanger implements Tape { */ @Override public T remove() { - if (currentTape == null) - return null; + if (currentTape == null) return null; return currentTape.remove(); } @@ -132,8 +126,7 @@ public class TapeChanger implements Tape { */ @Override public void first() { - if (currentTape == null) - return; + if (currentTape == null) return; currentTape.first(); } @@ -143,8 +136,7 @@ public class TapeChanger implements Tape { */ @Override public void last() { - if (currentTape == null) - return; + if (currentTape == null) return; currentTape.last(); } @@ -173,9 +165,8 @@ public class TapeChanger implements Tape { * @return True if the cursor was moved left. */ @Override - public boolean left(int amt) { - if (currentTape == null) - return false; + public boolean left(final int amt) { + if (currentTape == null) return false; return currentTape.left(amt); } @@ -203,9 +194,8 @@ public class TapeChanger implements Tape { * @return Whether the cursor was moved right. */ @Override - public boolean right(int amt) { - if (currentTape == null) - return false; + public boolean right(final int amt) { + if (currentTape == null) return false; return currentTape.right(amt); } @@ -219,8 +209,7 @@ public class TapeChanger implements Tape { * If the current tape is not double-sided, does nothing. */ public void flip() { - if (currentTape == null) - return; + if (currentTape == null) return; if (currentTape.isDoubleSided()) { ((DoubleTape) currentTape).flip(); @@ -229,8 +218,7 @@ public class TapeChanger implements Tape { @Override public boolean isDoubleSided() { - if (currentTape == null) - return false; + if (currentTape == null) return false; return currentTape.isDoubleSided(); } @@ -253,7 +241,7 @@ public class TapeChanger implements Tape { * @return Whether or not the next tape was loaded. */ public boolean nextTape() { - boolean succ = tapes.right(); + final boolean succ = tapes.right(); if (succ) { currentTape = tapes.item(); @@ -271,7 +259,7 @@ public class TapeChanger implements Tape { * @return Whether or not the previous tape was loaded. */ public boolean prevTape() { - boolean succ = tapes.left(); + final boolean succ = tapes.left(); if (succ) { currentTape = tapes.item(); @@ -290,7 +278,7 @@ public class TapeChanger implements Tape { * @param tp * The tape to insert and load. */ - public void insertTape(Tape tp) { + public void insertTape(final Tape tp) { tapes.insertAfter(tp); tapes.right(); @@ -307,10 +295,9 @@ public class TapeChanger implements Tape { * @return The removed tape. */ public Tape removeTape() { - if (currentTape == null) - return null; + if (currentTape == null) return null; - Tape tp = tapes.remove(); + final Tape tp = tapes.remove(); currentTape = tapes.item(); return tp; @@ -338,33 +325,26 @@ public class TapeChanger implements Tape { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((currentTape == null) ? 0 : currentTape.hashCode()); - result = prime * result + ((tapes == null) ? 0 : tapes.hashCode()); + result = prime * result + (currentTape == null ? 0 : currentTape.hashCode()); + result = prime * result + (tapes == null ? 0 : tapes.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof TapeChanger)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof TapeChanger)) return false; - TapeChanger other = (TapeChanger) obj; + final TapeChanger other = (TapeChanger) obj; if (currentTape == null) { - if (other.currentTape != null) - return false; - } else if (!currentTape.equals(other.currentTape)) - return false; + if (other.currentTape != null) return false; + } else if (!currentTape.equals(other.currentTape)) return false; if (tapes == null) { - if (other.tapes != null) - return false; - } else if (!tapes.equals(other.tapes)) - return false; + if (other.tapes != null) return false; + } else if (!tapes.equals(other.tapes)) return false; return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java index 85bea49..4a5add6 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java @@ -16,8 +16,8 @@ import java.util.Map; * The element type of the tapes. */ public class TapeLibrary implements Tape { - private Map> tapes; - private Tape currentTape; + private final Map> tapes; + private Tape currentTape; /** * Create a new empty tape library. @@ -33,8 +33,7 @@ public class TapeLibrary implements Tape { */ @Override public T item() { - if (currentTape == null) - return null; + if (currentTape == null) return null; return currentTape.item(); } @@ -46,9 +45,8 @@ public class TapeLibrary implements Tape { * The new value for the tape item. */ @Override - public void item(T itm) { - if (currentTape == null) - return; + public void item(final T itm) { + if (currentTape == null) return; currentTape.item(itm); } @@ -60,8 +58,7 @@ public class TapeLibrary implements Tape { */ @Override public int size() { - if (currentTape == null) - return 0; + if (currentTape == null) return 0; return currentTape.size(); } @@ -73,9 +70,8 @@ public class TapeLibrary implements Tape { * The item to add. */ @Override - public void insertBefore(T itm) { - if (currentTape == null) - return; + public void insertBefore(final T itm) { + if (currentTape == null) return; currentTape.insertBefore(itm); } @@ -84,9 +80,8 @@ public class TapeLibrary implements Tape { * Insert an element after the current item. */ @Override - public void insertAfter(T itm) { - if (currentTape == null) - return; + public void insertAfter(final T itm) { + if (currentTape == null) return; currentTape.insertAfter(itm); } @@ -101,8 +96,7 @@ public class TapeLibrary implements Tape { */ @Override public T remove() { - if (currentTape == null) - return null; + if (currentTape == null) return null; return currentTape.remove(); } @@ -112,8 +106,7 @@ public class TapeLibrary implements Tape { */ @Override public void first() { - if (currentTape == null) - return; + if (currentTape == null) return; currentTape.first(); } @@ -123,8 +116,7 @@ public class TapeLibrary implements Tape { */ @Override public void last() { - if (currentTape == null) - return; + if (currentTape == null) return; currentTape.last(); } @@ -153,9 +145,8 @@ public class TapeLibrary implements Tape { * @return True if the cursor was moved left. */ @Override - public boolean left(int amt) { - if (currentTape == null) - return false; + public boolean left(final int amt) { + if (currentTape == null) return false; return currentTape.left(amt); } @@ -183,9 +174,8 @@ public class TapeLibrary implements Tape { * @return Whether the cursor was moved right. */ @Override - public boolean right(int amt) { - if (currentTape == null) - return false; + public boolean right(final int amt) { + if (currentTape == null) return false; return currentTape.right(amt); } @@ -199,8 +189,7 @@ public class TapeLibrary implements Tape { * If the current tape is not double-sided, does nothing. */ public void flip() { - if (currentTape == null) - return; + if (currentTape == null) return; if (currentTape.isDoubleSided()) { ((DoubleTape) currentTape).flip(); @@ -209,8 +198,7 @@ public class TapeLibrary implements Tape { @Override public boolean isDoubleSided() { - if (currentTape == null) - return false; + if (currentTape == null) return false; return currentTape.isDoubleSided(); } @@ -235,7 +223,7 @@ public class TapeLibrary implements Tape { * * @return Whether or not the next tape was loaded. */ - public boolean switchTape(String label) { + public boolean switchTape(final String label) { if (tapes.containsKey(label)) { currentTape = tapes.get(label); return true; @@ -252,14 +240,14 @@ public class TapeLibrary implements Tape { * The specified tape is loaded. * * Adding a duplicate tape will overwrite any existing types. - * + * * @param label * The label of the tape to add. * * @param tp * The tape to insert and load. */ - public void insertTape(String label, Tape tp) { + public void insertTape(final String label, final Tape tp) { tapes.put(label, tp); currentTape = tp; @@ -275,7 +263,7 @@ public class TapeLibrary implements Tape { * * @return The removed tape. */ - public Tape removeTape(String label) { + public Tape removeTape(final String label) { return tapes.remove(label); } @@ -305,7 +293,7 @@ public class TapeLibrary implements Tape { * * @return Whether or not a tape of that name exists */ - public boolean hasTape(String label) { + public boolean hasTape(final String label) { return tapes.containsKey(label); } @@ -314,34 +302,27 @@ public class TapeLibrary implements Tape { final int prime = 31; int result = 1; - result = prime * result + ((currentTape == null) ? 0 : currentTape.hashCode()); - result = prime * result + ((tapes == null) ? 0 : tapes.hashCode()); + result = prime * result + (currentTape == null ? 0 : currentTape.hashCode()); + result = prime * result + (tapes == null ? 0 : tapes.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof TapeLibrary)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof TapeLibrary)) return false; - TapeLibrary other = (TapeLibrary) obj; + final TapeLibrary other = (TapeLibrary) obj; if (currentTape == null) { - if (other.currentTape != null) - return false; - } else if (!currentTape.equals(other.currentTape)) - return false; + if (other.currentTape != null) return false; + } else if (!currentTape.equals(other.currentTape)) return false; if (tapes == null) { - if (other.tapes != null) - return false; - } else if (!tapes.equals(other.tapes)) - return false; + if (other.tapes != null) return false; + } else if (!tapes.equals(other.tapes)) return false; return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java index a0d9096..ffb639f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java @@ -16,9 +16,9 @@ import bjc.utils.funcdata.IMap; * The value type of the directory. */ public class UnifiedDirectory implements Directory { - private IMap> children; + private final IMap> children; - private IMap data; + private final IMap data; /** * Create a new directory. @@ -29,19 +29,19 @@ public class UnifiedDirectory implements Directory { } @Override - public Directory getSubdirectory(K key) { + public Directory getSubdirectory(final K key) { return children.get(key); } @Override - public boolean hasSubdirectory(K key) { + public boolean hasSubdirectory(final K key) { return children.containsKey(key); } @Override - public Directory putSubdirectory(K key, Directory val) { + public Directory putSubdirectory(final K key, final Directory val) { if (data.containsKey(key)) { - String msg = String.format("Key %s is already used for data", key); + final String msg = String.format("Key %s is already used for data", key); throw new IllegalArgumentException(msg); } @@ -50,19 +50,19 @@ public class UnifiedDirectory implements Directory { } @Override - public boolean containsKey(K key) { + public boolean containsKey(final K key) { return data.containsKey(key); } @Override - public V getKey(K key) { + public V getKey(final K key) { return data.get(key); } @Override - public V putKey(K key, V val) { + public V putKey(final K key, final V val) { if (children.containsKey(key)) { - String msg = String.format("Key %s is already used for sub-directories.", key); + final String msg = String.format("Key %s is already used for sub-directories.", key); throw new IllegalArgumentException(msg); } @@ -74,33 +74,26 @@ public class UnifiedDirectory implements Directory { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((children == null) ? 0 : children.hashCode()); - result = prime * result + ((data == null) ? 0 : data.hashCode()); + result = prime * result + (children == null ? 0 : children.hashCode()); + result = prime * result + (data == null ? 0 : data.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof UnifiedDirectory)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof UnifiedDirectory)) return false; - UnifiedDirectory other = (UnifiedDirectory) obj; + final UnifiedDirectory other = (UnifiedDirectory) obj; if (children == null) { - if (other.children != null) - return false; - } else if (!children.equals(other.children)) - return false; + 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)) - return false; + if (other.data != null) return false; + } else if (!data.equals(other.data)) return false; return true; } -- cgit v1.2.3