package net.minecraft.server.level;

import java.util.Objects;

public final class Ticket<T> implements Comparable<Ticket<?>> {
    private final TicketType<T> type;
    private final int ticketLevel;
    private final T key;
    private long createdTick;
    
    protected Ticket(final TicketType<T> xi, final int integer, final T object) {
        this.type = xi;
        this.ticketLevel = integer;
        this.key = object;
    }
    
    @Override
    public int compareTo(final Ticket<?> xh) {
        final int integer3 = Integer.compare(this.ticketLevel, xh.ticketLevel);
        if (integer3 != 0) {
            return integer3;
        }
        final int integer4 = Integer.compare(System.identityHashCode(this.type), System.identityHashCode(xh.type));
        if (integer4 != 0) {
            return integer4;
        }
        return this.type.getComparator().compare(this.key, (T)xh.key);
    }
    
    @Override
    public boolean equals(final Object object) {
        if (this == object) {
            return true;
        }
        if (!(object instanceof Ticket)) {
            return false;
        }
        final Ticket<?> xh3 = object;
        return this.ticketLevel == xh3.ticketLevel && Objects.equals(this.type, xh3.type) && Objects.equals(this.key, xh3.key);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.type, this.ticketLevel, this.key);
    }
    
    @Override
    public String toString() {
        return "Ticket[" + this.type + " " + this.ticketLevel + " (" + this.key + ")] at " + this.createdTick;
    }
    
    public TicketType<T> getType() {
        return this.type;
    }
    
    public int getTicketLevel() {
        return this.ticketLevel;
    }
    
    protected void setCreatedTick(final long long1) {
        this.createdTick = long1;
    }
    
    protected boolean timedOut(final long long1) {
        final long long2 = this.type.timeout();
        return long2 != 0L && long1 - this.createdTick > long2;
    }
}
