cache hashcode for UUIDBased and TbSubscription
This commit is contained in:
parent
1f518cddbe
commit
6a726a8c56
@ -27,6 +27,9 @@ import java.util.function.BiConsumer;
|
||||
@AllArgsConstructor
|
||||
public abstract class TbSubscription<T> {
|
||||
|
||||
/** Cache the hash code */
|
||||
private transient int hash; // Default to 0. The hash code calculated for this object likely never be zero
|
||||
|
||||
private final String serviceId;
|
||||
private final String sessionId;
|
||||
private final int subscriptionId;
|
||||
@ -49,7 +52,10 @@ public abstract class TbSubscription<T> {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(sessionId, subscriptionId, tenantId, entityId, type);
|
||||
if (hash == 0) {
|
||||
hash = Objects.hash(sessionId, subscriptionId, tenantId, entityId, type);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,9 @@ public abstract class UUIDBased implements HasUUID, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** Cache the hash code */
|
||||
private transient int hash; // Default to 0. The hash code calculated for this object likely never be zero
|
||||
|
||||
private final UUID id;
|
||||
|
||||
public UUIDBased() {
|
||||
@ -43,10 +46,12 @@ public abstract class UUIDBased implements HasUUID, Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (hash == 0) {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
hash = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user