Properly implement hashCode().
This commit is contained in:
parent
d565bdb373
commit
8379263d09
4 changed files with 9 additions and 8 deletions
|
@ -2,7 +2,7 @@ package com.nutomic.ensichat.messages
|
|||
|
||||
import java.security.spec.X509EncodedKeySpec
|
||||
import java.security.{KeyFactory, PublicKey}
|
||||
import java.util.Date
|
||||
import java.util.{Date, Objects}
|
||||
|
||||
import com.nutomic.ensichat.bluetooth.Device
|
||||
import com.nutomic.ensichat.messages.Message._
|
||||
|
@ -35,7 +35,7 @@ class DeviceInfoMessage(override val sender: Device.ID, override val receiver: D
|
|||
override def equals(a: Any) =
|
||||
super.equals(a) && a.asInstanceOf[DeviceInfoMessage].publicKey.toString == publicKey.toString
|
||||
|
||||
override def hashCode = super.hashCode + publicKey.hashCode
|
||||
override def hashCode = Objects.hash(super.hashCode: java.lang.Integer, publicKey)
|
||||
|
||||
override def toString = "DeviceInfoMessage(" + sender.toString + ", " + receiver.toString +
|
||||
", " + date.toString + ", " + publicKey.toString + ")"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.nutomic.ensichat.messages
|
||||
|
||||
import java.io.IOException
|
||||
import java.util.Date
|
||||
import java.util.{Date, Objects}
|
||||
|
||||
import com.nutomic.ensichat.bluetooth.Device
|
||||
import org.msgpack.ScalaMessagePack
|
||||
|
@ -116,7 +116,7 @@ abstract class Message(val messageType: Int) {
|
|||
* Implementations must provide their own implementation to check the result of this
|
||||
* function and their own data.
|
||||
*/
|
||||
override def hashCode: Int = sender.hashCode + receiver.hashCode + date.hashCode
|
||||
override def hashCode: Int = Objects.hash(sender, receiver, date)
|
||||
|
||||
override def toString: String
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.nutomic.ensichat.messages
|
||||
|
||||
import java.util.Date
|
||||
import java.util.{Date, Objects}
|
||||
|
||||
import com.nutomic.ensichat.activities.AddContactsActivity
|
||||
import com.nutomic.ensichat.bluetooth.Device
|
||||
|
@ -28,7 +28,8 @@ class ResultAddContactMessage(override val sender: Device.ID, override val recei
|
|||
override def equals(a: Any) =
|
||||
super.equals(a) && a.asInstanceOf[ResultAddContactMessage].Accepted == Accepted
|
||||
|
||||
override def hashCode = super.hashCode + Accepted.hashCode
|
||||
override def hashCode =
|
||||
Objects.hash(super.hashCode: java.lang.Integer, Accepted: java.lang.Boolean)
|
||||
|
||||
override def toString = "ResultAddContactMessage(" + sender.toString + ", " + receiver.toString +
|
||||
", " + date.toString + ", " + Accepted + ")"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.nutomic.ensichat.messages
|
||||
|
||||
import java.util.Date
|
||||
import java.util.{Date, Objects}
|
||||
|
||||
import com.nutomic.ensichat.bluetooth.Device
|
||||
import com.nutomic.ensichat.messages.Message._
|
||||
|
@ -24,7 +24,7 @@ class TextMessage(override val sender: Device.ID, override val receiver: Device.
|
|||
|
||||
override def equals(a: Any) = super.equals(a) && a.asInstanceOf[TextMessage].text == text
|
||||
|
||||
override def hashCode = super.hashCode + text.hashCode
|
||||
override def hashCode = Objects.hash(super.hashCode: java.lang.Integer, text)
|
||||
|
||||
override def toString = "TextMessage(" + sender.toString + ", " + receiver.toString +
|
||||
", " + date.toString + ", " + text + ")"
|
||||
|
|
Reference in a new issue