// 
// Decompiled by Procyon v0.6.0
// 

package org.jline.utils;

public class Timeout
{
    private final long timeout;
    private long cur;
    private long end;
    
    public Timeout(final long timeout) {
        this.cur = 0L;
        this.end = Long.MAX_VALUE;
        this.timeout = timeout;
    }
    
    public boolean isInfinite() {
        return this.timeout <= 0L;
    }
    
    public boolean isFinite() {
        return this.timeout > 0L;
    }
    
    public boolean elapsed() {
        if (this.timeout > 0L) {
            this.cur = System.currentTimeMillis();
            if (this.end == Long.MAX_VALUE) {
                this.end = this.cur + this.timeout;
            }
            return this.cur >= this.end;
        }
        return false;
    }
    
    public long timeout() {
        return (this.timeout > 0L) ? Math.max(1L, this.end - this.cur) : this.timeout;
    }
}
