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
|
@AllArgsConstructor
|
||||||
public abstract class TbSubscription<T> {
|
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 serviceId;
|
||||||
private final String sessionId;
|
private final String sessionId;
|
||||||
private final int subscriptionId;
|
private final int subscriptionId;
|
||||||
@ -49,7 +52,10 @@ public abstract class TbSubscription<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
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;
|
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;
|
private final UUID id;
|
||||||
|
|
||||||
public UUIDBased() {
|
public UUIDBased() {
|
||||||
@ -43,10 +46,12 @@ public abstract class UUIDBased implements HasUUID, Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
if (hash == 0) {
|
||||||
int result = 1;
|
final int prime = 31;
|
||||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
int result = 1;
|
||||||
return result;
|
hash = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user