All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minestom.server.utils.Range Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
package net.minestom.server.utils;

/**
 * Represents the base for any data type that is numeric.
 *
 * @param  The type numeric of the range object.
 */
public sealed interface Range {
    record Byte(byte min, byte max) implements Range {
        public Byte(byte value) {
            this(value, value);
        }

        public boolean inRange(byte value) {
            return value >= min && value <= max;
        }
    }

    record Short(short min, short max) implements Range {
        public Short(short value) {
            this(value, value);
        }

        public boolean inRange(short value) {
            return value >= min && value <= max;
        }
    }

    record Int(int min, int max) implements Range {
        public Int(int value) {
            this(value, value);
        }

        public boolean inRange(int value) {
            return value >= min && value <= max;
        }
    }

    record Long(long min, long max) implements Range {
        public Long(long value) {
            this(value, value);
        }

        public boolean inRange(long value) {
            return value >= min && value <= max;
        }
    }

    record Float(float min, float max) implements Range {
        public Float(float value) {
            this(value, value);
        }

        public boolean inRange(float value) {
            return value >= min && value <= max;
        }
    }

    record Double(double min, double max) implements Range {
        public Double(double value) {
            this(value, value);
        }

        public boolean inRange(double value) {
            return value >= min && value <= max;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy