Ajout des méthodes hashCode() et equals() pour les classes "beans" du module Core

This commit is contained in:
Notmoo 2017-07-26 14:50:33 +02:00
parent 9c2c2a2acd
commit be691d2218
11 changed files with 226 additions and 4 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}