From 338b2b16b6934d27dc4cd536fb5527b71985de4f Mon Sep 17 00:00:00 2001 From: bjculkin Date: Fri, 17 Mar 2017 19:46:55 -0400 Subject: Add more toString/hashCode/equals --- .../main/java/bjc/utils/esodata/TapeLibrary.java | 52 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java') 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 * The element type of the tapes. */ public class TapeLibrary implements Tape { @@ -240,9 +240,12 @@ 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 The - * tape to insert and load. + * @param tp + * The tape to insert and load. */ public void insertTape(String label, Tape tp) { tapes.put(label, tp); @@ -293,4 +296,47 @@ public class TapeLibrary implements Tape { 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(); + } } -- cgit v1.2.3