Added methods hashCode() and equals() for models

This commit is contained in:
Andrey Terentev 2023-11-16 17:33:00 +07:00
parent 3b89c79540
commit 0104db48f5
2 changed files with 32 additions and 1 deletions

View File

@ -28,4 +28,19 @@ public class Bucket {
if (slots.isUnlimited()) return true; if (slots.isUnlimited()) return true;
return slots.getSlots() >= usedSlots + requiredSlots; return slots.getSlots() >= usedSlots + requiredSlots;
} }
@Override
public int hashCode() {
return identifier.hashCode();
}
@Override
public boolean equals(Object object) {
if (object == this) return true;
if (object == null) return false;
if (object instanceof Bucket other) {
return identifier.equals(other.identifier);
}
return false;
}
} }

View File

@ -2,4 +2,20 @@ package ru.dragonestia.loadbalancer.model;
import lombok.NonNull; import lombok.NonNull;
public record User(@NonNull String identifier) {} public record User(@NonNull String identifier) {
@Override
public int hashCode() {
return identifier.hashCode();
}
@Override
public boolean equals(Object object) {
if (object == this) return true;
if (object == null) return false;
if (object instanceof User other) {
return identifier.equals(other.identifier);
}
return false;
}
}