From be691d2218f0d574aaa8f8b74b243e9eca32061a Mon Sep 17 00:00:00 2001 From: Notmoo Date: Wed, 26 Jul 2017 14:50:33 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20m=C3=A9thodes=20hashCode()=20et?= =?UTF-8?q?=20equals()=20pour=20les=20classes=20"beans"=20du=20module=20Co?= =?UTF-8?q?re?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/pqt/core/entities/members/Client.java | 19 ++++++++++++++ .../pqt/core/entities/members/DataServer.java | 19 ++++++++++++++ .../pqt/core/entities/members/PqtMember.java | 19 ++++++++++++++ .../pqt/core/entities/messages/Message.java | 25 ++++++++++++++++--- .../pqt/core/entities/product/Category.java | 19 ++++++++++++++ .../entities/product/LightweightProduct.java | 21 ++++++++++++++++ .../pqt/core/entities/product/Product.java | 21 ++++++++++++++++ .../core/entities/product/ProductUpdate.java | 19 ++++++++++++++ .../core/entities/sale/LightweightSale.java | 24 ++++++++++++++++++ .../java/com/pqt/core/entities/sale/Sale.java | 23 +++++++++++++++++ .../core/entities/user_account/Account.java | 21 ++++++++++++++++ 11 files changed, 226 insertions(+), 4 deletions(-) diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/members/Client.java b/Workspace/core/src/main/java/com/pqt/core/entities/members/Client.java index 0d667489..2accc6d4 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/members/Client.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/members/Client.java @@ -2,6 +2,7 @@ package com.pqt.core.entities.members; import java.io.Serializable; import java.util.Date; +import java.util.Objects; /** * Created by Notmoo on 18/07/2017. @@ -42,4 +43,22 @@ public class Client extends PqtMember{ public void setLastUpdate(Date lastUpdate) { this.lastUpdate = lastUpdate; } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), address); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + Client other = Client.class.cast(obj); + return super.equals(obj) + && Objects.equals(this.address, other.address); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/members/DataServer.java b/Workspace/core/src/main/java/com/pqt/core/entities/members/DataServer.java index 9804f487..1966cfc8 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/members/DataServer.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/members/DataServer.java @@ -2,6 +2,7 @@ package com.pqt.core.entities.members; import java.io.Serializable; import java.util.Date; +import java.util.Objects; public class DataServer extends PqtMember{ @@ -39,4 +40,22 @@ public class DataServer extends PqtMember{ public void setLastUpdate(Date lastUpdate) { this.lastUpdate = lastUpdate; } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), address); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + DataServer other = DataServer.class.cast(obj); + return super.equals(obj) + && Objects.equals(this.address, other.address); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/members/PqtMember.java b/Workspace/core/src/main/java/com/pqt/core/entities/members/PqtMember.java index 94399c6b..5e16b5d5 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/members/PqtMember.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/members/PqtMember.java @@ -3,6 +3,7 @@ package com.pqt.core.entities.members; import com.pqt.core.entities.log.ILoggable; import java.io.Serializable; +import java.util.Objects; public class PqtMember implements ILoggable, Serializable { @@ -32,4 +33,22 @@ public class PqtMember implements ILoggable, Serializable { public void setType(PqtMemberType type) { this.type = type; } + + @Override + public int hashCode() { + return Objects.hash(id, type); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + PqtMember other = PqtMember.class.cast(obj); + return this.id == other.id + && Objects.equals(this.type, other.type); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/messages/Message.java b/Workspace/core/src/main/java/com/pqt/core/entities/messages/Message.java index 78080326..d58bf6b8 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/messages/Message.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/messages/Message.java @@ -2,10 +2,7 @@ package com.pqt.core.entities.messages; import com.pqt.core.entities.members.PqtMember; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class Message { @@ -51,4 +48,24 @@ public class Message { public MessageType getType() { return type; } + + @Override + public int hashCode() { + return Objects.hash(fields, emitter, receiver, type); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + Message other = Message.class.cast(obj); + return Objects.equals(this.fields, other.fields) + && Objects.equals(this.emitter, other.emitter) + && Objects.equals(this.receiver, other.receiver) + && Objects.equals(this.type, other.type); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/product/Category.java b/Workspace/core/src/main/java/com/pqt/core/entities/product/Category.java index 82b7073c..409bc5fd 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/product/Category.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/product/Category.java @@ -1,6 +1,7 @@ package com.pqt.core.entities.product; import java.io.Serializable; +import java.util.Objects; /** * Created by Notmoo on 18/07/2017. @@ -32,4 +33,22 @@ public class Category implements Serializable{ public void setName(String name) { this.name = name; } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + Category other = Category.class.cast(obj); + return this.id == other.id + && Objects.equals(this.name, other.name); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/product/LightweightProduct.java b/Workspace/core/src/main/java/com/pqt/core/entities/product/LightweightProduct.java index e13118ed..4d315492 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/product/LightweightProduct.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/product/LightweightProduct.java @@ -2,6 +2,7 @@ package com.pqt.core.entities.product; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class LightweightProduct { private long id; @@ -94,4 +95,24 @@ public class LightweightProduct { public void setCategory(Category category) { this.category = category; } + + @Override + public int hashCode() { + return Objects.hash(id, name, componentIds, category); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + LightweightProduct other = LightweightProduct.class.cast(obj); + return this.id == other.id + && Objects.equals(this.name, other.name) + && Objects.equals(this.componentIds, other.componentIds) + && Objects.equals(this.category, other.category); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/product/Product.java b/Workspace/core/src/main/java/com/pqt/core/entities/product/Product.java index 2f72df2b..90136f82 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/product/Product.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/product/Product.java @@ -5,6 +5,7 @@ import com.pqt.core.entities.log.ILoggable; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Created by Notmoo on 18/07/2017. @@ -100,4 +101,24 @@ public class Product implements ILoggable, Serializable{ public void setCategory(Category category) { this.category = category; } + + @Override + public int hashCode() { + return Objects.hash(id, name, components, category); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + Product other = Product.class.cast(obj); + return this.id == other.id + && Objects.equals(this.name, other.name) + && Objects.equals(this.components, other.components) + && Objects.equals(this.category, other.category); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/product/ProductUpdate.java b/Workspace/core/src/main/java/com/pqt/core/entities/product/ProductUpdate.java index 402f7071..106f5a45 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/product/ProductUpdate.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/product/ProductUpdate.java @@ -5,6 +5,7 @@ import sun.misc.Version; import java.io.Serializable; import java.util.Date; +import java.util.Objects; public class ProductUpdate implements ILoggable, Serializable { @@ -50,4 +51,22 @@ public class ProductUpdate implements ILoggable, Serializable { public void setNewVersion(Product newVersion) { this.newVersion = newVersion; } + + @Override + public int hashCode() { + return Objects.hash(oldVersion, newVersion); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + ProductUpdate other = ProductUpdate.class.cast(obj); + return Objects.equals(this.oldVersion, other.oldVersion) + && Objects.equals(this.newVersion, other.newVersion); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/sale/LightweightSale.java b/Workspace/core/src/main/java/com/pqt/core/entities/sale/LightweightSale.java index b605721d..4f4db0a9 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/sale/LightweightSale.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/sale/LightweightSale.java @@ -1,12 +1,14 @@ package com.pqt.core.entities.sale; import com.pqt.core.entities.members.Client; +import com.pqt.core.entities.product.LightweightProduct; import com.pqt.core.entities.product.Product; import com.pqt.core.entities.user_account.Account; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Objects; public class LightweightSale { @@ -99,4 +101,26 @@ public class LightweightSale { public void setStatus(SaleStatus status) { this.status = status; } + + @Override + public int hashCode() { + return Objects.hash(id, products, orderedBy, orderedFor, orderedWith, type); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + LightweightSale other = LightweightSale.class.cast(obj); + return this.id == other.id + && Objects.equals(this.products, other.products) + && Objects.equals(this.orderedBy, other.orderedBy) + && Objects.equals(this.orderedFor, other.orderedFor) + && Objects.equals(this.orderedWith, other.orderedWith) + && Objects.equals(this.type, other.type); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/sale/Sale.java b/Workspace/core/src/main/java/com/pqt/core/entities/sale/Sale.java index 1da9bd55..b474f9a7 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/sale/Sale.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/sale/Sale.java @@ -8,6 +8,7 @@ import com.pqt.core.entities.user_account.Account; import java.io.Serializable; import java.util.Date; import java.util.Map; +import java.util.Objects; /** * Created by Notmoo on 18/07/2017. @@ -100,4 +101,26 @@ public class Sale implements ILoggable, Serializable{ public void setStatus(SaleStatus status) { this.status = status; } + + @Override + public int hashCode() { + return Objects.hash(id, products, orderedBy, orderedFor, orderedWith, type); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + Sale other = Sale.class.cast(obj); + return this.id == other.id + && Objects.equals(this.products, other.products) + && Objects.equals(this.orderedBy, other.orderedBy) + && Objects.equals(this.orderedFor, other.orderedFor) + && Objects.equals(this.orderedWith, other.orderedWith) + && Objects.equals(this.type, other.type); + } } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/user_account/Account.java b/Workspace/core/src/main/java/com/pqt/core/entities/user_account/Account.java index 687fab3f..b497886e 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/user_account/Account.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/user_account/Account.java @@ -4,6 +4,7 @@ import com.pqt.core.entities.log.ILoggable; import java.io.Serializable; import java.util.Date; +import java.util.Objects; /** * Created by Notmoo on 18/07/2017. @@ -65,4 +66,24 @@ public class Account implements ILoggable, Serializable { public void setPermissionLevel(AccountLevel permissionLevel) { this.permissionLevel = permissionLevel; } + + @Override + public int hashCode() { + return Objects.hash(id, username, passwordHash, permissionLevel); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + + if(!this.getClass().isInstance(obj)) + return false; + + Account acc = Account.class.cast(obj); + return this.id == acc.id + && Objects.equals(this.username, acc.username) + && Objects.equals(this.passwordHash, acc.passwordHash) + && Objects.equals(this.permissionLevel, acc.permissionLevel); + } }