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

package com.hypixel.hytale.math.range;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.hypixel.hytale.math.util.MathUtil;
import com.hypixel.hytale.math.codec.IntRangeArrayCodec;

public class IntRange
{
    public static final IntRangeArrayCodec CODEC;
    private int inclusiveMin;
    private int inclusiveMax;
    private int range;
    
    public IntRange() {
        this(0, 0);
    }
    
    public IntRange(final int inclusiveMin, final int inclusiveMax) {
        this.inclusiveMin = inclusiveMin;
        this.inclusiveMax = inclusiveMax;
        this.range = inclusiveMax - inclusiveMin + 1;
    }
    
    public int getInclusiveMin() {
        return this.inclusiveMin;
    }
    
    public int getInclusiveMax() {
        return this.inclusiveMax;
    }
    
    public void setInclusiveMin(final int inclusiveMin) {
        this.inclusiveMin = inclusiveMin;
        this.range = this.inclusiveMax - inclusiveMin + 1;
    }
    
    public void setInclusiveMax(final int inclusiveMax) {
        this.inclusiveMax = inclusiveMax;
        this.range = inclusiveMax - this.inclusiveMin + 1;
    }
    
    public int getInt(final float factor) {
        final int value = this.inclusiveMin + MathUtil.fastFloor(this.range * factor);
        return Integer.min(this.inclusiveMax, value);
    }
    
    public int getInt(final double factor) {
        final int value = this.inclusiveMin + MathUtil.floor(this.range * factor);
        return Integer.min(this.inclusiveMax, value);
    }
    
    public boolean includes(final int value) {
        return value >= this.inclusiveMin && value <= this.inclusiveMax;
    }
    
    @Override
    public boolean equals(@Nullable final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final IntRange intRange = (IntRange)o;
        return this.inclusiveMin == intRange.inclusiveMin && this.inclusiveMax == intRange.inclusiveMax;
    }
    
    @Override
    public int hashCode() {
        int result = this.inclusiveMin;
        result = 31 * result + this.inclusiveMax;
        return result;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "IntRange{inclusiveMin=" + this.inclusiveMin + ", inclusiveMax=" + this.inclusiveMax;
    }
    
    static {
        CODEC = new IntRangeArrayCodec();
    }
}
