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/TapeChanger.java | 53 +++++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java') 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 * The element type of the tapes. */ public class TapeChanger implements Tape { @@ -26,9 +26,9 @@ public class TapeChanger implements Tape { /** * 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 implements Tape { * * The specified tape is loaded. * - * @param The - * tape to insert and load. + * @param tp + * The tape to insert and load. */ public void insertTape(Tape tp) { tapes.insertAfter(tp); @@ -320,4 +320,45 @@ public class TapeChanger implements Tape { 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; + } } -- cgit v1.2.3