diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-17 19:46:55 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-17 19:46:55 -0400 |
| commit | 338b2b16b6934d27dc4cd536fb5527b71985de4f (patch) | |
| tree | 6dc7e85370507d22150cd7cef353a033b50a71d7 /BJC-Utils2/src/main | |
| parent | 5832ef0286430d04484b70d49c73e081a80ec9c7 (diff) | |
Add more toString/hashCode/equals
Diffstat (limited to 'BJC-Utils2/src/main')
11 files changed, 409 insertions, 28 deletions
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 79ae031..05f686a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java @@ -6,9 +6,9 @@ package bjc.utils.esodata; * What's useful about this is that you can hand sub-directories to people and
* be able to ensure that they can't write outside of it.
*
- * @param K
+ * @param <K>
* The key type of the map.
- * @param V
+ * @param <V>
* The value type of the map.
*/
public interface Directory<K, V> {
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 6e256b6..ec24431 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java @@ -19,7 +19,7 @@ package bjc.utils.esodata; * * Flip refers to the entire tape for 'obvious' reasons. * - * @param T + * @param <T> * The element type of the tape. * @author bjculkin */ @@ -217,4 +217,45 @@ public class DoubleTape<T> implements Tape<T> { public boolean isDoubleSided() { return true; } + + @Override + 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()); + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + + DoubleTape<?> other = (DoubleTape<?>) obj; + + if(back == null) { + 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; + + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("DoubleTape [front="); + builder.append(front); + builder.append(", back="); + builder.append(back); + builder.append("]"); + + return builder.toString(); + } } 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 4b758e3..7587b86 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/PushdownMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/PushdownMap.java @@ -117,4 +117,40 @@ public class PushdownMap<KeyType, ValueType> implements IMap<KeyType, ValueType> public IList<ValueType> valueList() { return backing.valueList().map(stk -> stk.top()); } + + @Override + public int hashCode() { + final int prime = 31; + + int result = 1; + 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(getClass() != obj.getClass()) return false; + + PushdownMap<?, ?> other = (PushdownMap<?, ?>) obj; + + if(backing == null) { + if(other.backing != null) return false; + } else if(!backing.equals(other.backing)) return false; + + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("PushdownMap [backing="); + builder.append(backing); + builder.append("]"); + + return builder.toString(); + } } 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 a2c2f32..005c90e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java @@ -29,14 +29,14 @@ public class QueueStack<T> extends Stack<T> { @Override public T pop() { if(backing.isEmpty()) throw new StackUnderflowException(); - + return backing.remove(); } @Override public T top() { if(backing.isEmpty()) throw new StackUnderflowException(); - + return backing.peek(); } @@ -49,15 +49,46 @@ public class QueueStack<T> extends Stack<T> { public boolean empty() { return backing.size() == 0; } - + @Override public String toString() { - return backing.toString(); + StringBuilder builder = new StringBuilder(); + + builder.append("QueueStack [backing="); + builder.append(backing); + builder.append("]"); + + return builder.toString(); } - + @SuppressWarnings("unchecked") @Override public T[] toArray() { return (T[]) backing.toArray(); } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + 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(getClass() != obj.getClass()) return false; + + QueueStack<?> other = (QueueStack<?>) obj; + + if(backing == null) { + 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 3c1ced5..741b33d 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java @@ -57,4 +57,47 @@ public class SimpleDirectory<K, V> implements Directory<K, V> { public V putKey(K key, V val) { return data.put(key, val); } + + @Override + 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()); + + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + + SimpleDirectory<?, ?> other = (SimpleDirectory<?, ?>) obj; + + if(children == null) { + 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; + + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("SimpleDirectory [children="); + builder.append(children); + builder.append(", data="); + builder.append(data); + builder.append("]"); + + return builder.toString(); + } }
\ No newline at end of file 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 ec01280..1de06a6 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java @@ -6,7 +6,7 @@ import java.util.LinkedList; /** * Simple implementation of a stack. * - * @param T + * @param <T> * The datatype stored in the stack. * @author Ben Culkin */ @@ -29,14 +29,14 @@ public class SimpleStack<T> extends Stack<T> { @Override public T pop() { if(backing.isEmpty()) throw new StackUnderflowException(); - + return backing.pop(); } @Override public T top() { if(backing.isEmpty()) throw new StackUnderflowException(); - + return backing.peek(); } @@ -49,14 +49,45 @@ public class SimpleStack<T> extends Stack<T> { public boolean empty() { return backing.size() == 0; } - - @Override - public String toString() { - return backing.toString(); - } - + @SuppressWarnings("unchecked") public T[] toArray() { return (T[]) backing.toArray(); } + + @Override + public int hashCode() { + final int prime = 31; + + int result = 1; + 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(getClass() != obj.getClass()) return false; + + SimpleStack<?> other = (SimpleStack<?>) obj; + + if(backing == null) { + if(other.backing != null) return false; + } else if(!backing.equals(other.backing)) return false; + + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("SimpleStack [backing="); + builder.append(backing); + builder.append("]"); + + return builder.toString(); + } } 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 22b869e..056cab4 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java @@ -11,11 +11,12 @@ import java.util.ArrayList; * unbounded to the right, but in practice bounded by available memory. * * You can choose whether or not you want the tape to automatically extend - * itself to the right with null elements by specifiying its auto-extension + * itself to the right with null elements by specifying its auto-extension * policy. * - * @param T + * @param <T> * The element type of the tape. + * * @author bjculkin */ public class SingleTape<T> implements Tape<T> { @@ -204,4 +205,44 @@ public class SingleTape<T> implements Tape<T> { public boolean isDoubleSided() { return false; } + + @Override + public int hashCode() { + final int prime = 31; + + int result = 1; + 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(getClass() != obj.getClass()) return false; + + SingleTape<?> other = (SingleTape<?>) obj; + + if(backing == null) { + if(other.backing != null) return false; + } else if(!backing.equals(other.backing)) return false; + + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("SingleTape [backing="); + builder.append(backing); + builder.append(", pos="); + builder.append(pos); + builder.append(", autoExtend="); + builder.append(autoExtend); + builder.append("]"); + + return builder.toString(); + } } 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 fdf9cc8..c4c469f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java @@ -66,4 +66,34 @@ class SpaghettiStack<T> extends Stack<T> { public T[] toArray() { return (T[]) Stream.concat(Arrays.stream(parent.toArray()), Arrays.stream(backing.toArray())).toArray(); } + + @Override + public int hashCode() { + final int prime = 31; + + int result = 1; + 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(getClass() != obj.getClass()) return false; + + SpaghettiStack<?> other = (SpaghettiStack<?>) obj; + + if(backing == null) { + 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; + + return true; + } } 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 fa3e61c..64c0460 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java @@ -9,7 +9,7 @@ package bjc.utils.esodata; * If there is no tape currently loaded into the changer, all the methods will * either return null/false. * - * @param T + * @param <T> * The element type of the tapes. */ public class TapeChanger<T> implements Tape<T> { @@ -26,9 +26,9 @@ public class TapeChanger<T> implements Tape<T> { /** * Create a new tape changer with the specified tapes. * - * The first tape in the list will be mounted. - * - * @param taps + * @param current + * The tape to mount first. + * @param others * The tapes to put in this tape changer. */ @SafeVarargs @@ -275,8 +275,8 @@ public class TapeChanger<T> implements Tape<T> { * * The specified tape is loaded. * - * @param The - * tape to insert and load. + * @param tp + * The tape to insert and load. */ public void insertTape(Tape<T> tp) { tapes.insertAfter(tp); @@ -320,4 +320,45 @@ public class TapeChanger<T> implements Tape<T> { public int tapeCount() { return tapes.size(); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("TapeChanger [tapes="); + builder.append(tapes); + builder.append(", currentTape="); + builder.append(currentTape); + builder.append("]"); + + return builder.toString(); + } + + @Override + 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()); + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + + TapeChanger<?> other = (TapeChanger<?>) obj; + + if(currentTape == null) { + 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; + + 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 732f579..0bae303 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java @@ -12,7 +12,7 @@ import java.util.Map; * If there is no tape currently loaded into the changer, all the methods will * either return null/false. * - * @param T + * @param <T> * The element type of the tapes. */ public class TapeLibrary<T> implements Tape<T> { @@ -240,9 +240,12 @@ public class TapeLibrary<T> implements Tape<T> { * The specified tape is loaded. * * Adding a duplicate tape will overwrite any existing types. + * + * @param label + * The label of the tape to add. * - * @param The - * tape to insert and load. + * @param tp + * The tape to insert and load. */ public void insertTape(String label, Tape<T> tp) { tapes.put(label, tp); @@ -293,4 +296,47 @@ public class TapeLibrary<T> implements Tape<T> { public boolean hasTape(String label) { return tapes.containsKey(label); } + + @Override + 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()); + + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + + TapeLibrary<?> other = (TapeLibrary<?>) obj; + + if(currentTape == null) { + 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; + + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("TapeLibrary [tapes="); + builder.append(tapes); + builder.append(", currentTape="); + builder.append(currentTape); + builder.append("]"); + + return builder.toString(); + } } 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 d4c5081..61ec72b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java @@ -63,4 +63,45 @@ public class UnifiedDirectory<K, V> implements Directory<K, V> { return data.put(key, val); } + + @Override + 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()); + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + + UnifiedDirectory<?, ?> other = (UnifiedDirectory<?, ?>) obj; + + if(children == null) { + 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; + + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("UnifiedDirectory [children="); + builder.append(children); + builder.append(", data="); + builder.append(data); + builder.append("]"); + + return builder.toString(); + } }
\ No newline at end of file |
