From bc328a9674a1e09824d9a3d8b1bab3b2ccc5b035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Cuj=C3=A9?= Date: Wed, 21 Oct 2015 11:59:01 +0200 Subject: [PATCH] resolved LAS-201 added Agent equals comparator --- src/main/java/i5/las2peer/security/Agent.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/i5/las2peer/security/Agent.java b/src/main/java/i5/las2peer/security/Agent.java index b6ee50fc5..ec4229656 100644 --- a/src/main/java/i5/las2peer/security/Agent.java +++ b/src/main/java/i5/las2peer/security/Agent.java @@ -60,9 +60,9 @@ public abstract class Agent implements XmlAble, Cloneable, MessageReceiver { * @throws L2pSecurityException */ protected Agent(long id, KeyPair pair, SecretKey key) throws L2pSecurityException { - publicKey = pair.getPublic(); - privateKey = pair.getPrivate(); this.id = id; + this.publicKey = pair.getPublic(); + this.privateKey = pair.getPrivate(); encryptPrivateKey(key); lockPrivateKey(); @@ -78,8 +78,8 @@ protected Agent(long id, KeyPair pair, SecretKey key) throws L2pSecurityExceptio protected Agent(long id, PublicKey publicKey, byte[] encryptedPrivate) { this.id = id; this.publicKey = publicKey; - this.baEncrypedPrivate = encryptedPrivate.clone(); this.privateKey = null; + this.baEncrypedPrivate = encryptedPrivate.clone(); } /** @@ -325,4 +325,15 @@ else if ("monitoring".equals(type)) } } + @Override + public boolean equals(Object other) { + if (super.equals(other)) { + return true; + } + if (other == null || !other.getClass().isInstance(this)) { + return false; + } + return this.getId() == ((Agent) other).getId(); + } + }