class AccessInterval {

    @Override
    public boolean equals(Object obj) {
        if(this == obj) {
            return true;
        }

        if(obj instanceof AccessInterval) {
            AccessInterval other = (AccessInterval) obj;

            // only compare the user IDs because of the cyclic reference: User <-> AccessInterval
            boolean userEquals;
            if(Objects.nonNull(this.user) && Objects.nonNull(other.user)) {
                userEquals = Objects.equals(this.user.getId(), other.user.getId());
            } else {
                userEquals = Objects.isNull(this.user) && Objects.isNull(other.user);
            }

            return userEquals &&
                    Objects.equals(this.id, other.id) &&
                    Objects.equals(this.startTime, other.startTime) &&
                    Objects.equals(this.endTime, other.endTime);
        }

        return false;
    }

    public  AccessInterval(User user, LocalDateTime startTime, LocalDateTime endTime);

}