I have the following case class
case class Something(val input : Array[Int], val output : Array[Int] = null, val remainder : Array[Int] = null, val next : Something = null) {
override def equals(thatGeneric: scala.Any): Boolean = {
if(!thatGeneric.isInstanceOf[Something])
return false
val that = thatGeneric.asInstanceOf[Something]
val thisInput = if(this.input == null) null else this.input.deep
val thatInput = if(that.input == null) null else that.input.deep
val thisOutput = if(this.output == null) null else this.output.deep
val thatOutput = if(that.output == null) null else that.output.deep
val thisRemainder = if(this.remainder == null) null else this.remainder.deep
val thatRemainder = if(that.remainder == null) null else that.remainder.deep
return (thisInput,thisOutput,thisRemainder,this.next) == (thatInput,thatOutput,thatRemainder,that.next)
}
/**
* TODO fix hashcode in case I want to use this in collection
* @return
*/
override def hashCode(): Int = super.hashCode()
}
I know that case classes are supposed to have your equals and hashCode methods created for you but for Arrays since ==
doesn't work then I guess thats why it doesn't work for my case class.
Is there a better way to not have to hand-write my equals and hashCode methods for my case class?
Note: I also welcome advice on why/how to improve my current equals method
Edit: Do appreciate the notes about my use of case class in general, but my question was basically: Assume you have the need of an Array in your case class, how do you avoid rolling your own equals and hashCode. (If the answer is that its impossible and I need to use a list then that is the answer, just not sure that is the case.)