Merge remote-tracking branch 'origin/master'

This commit is contained in:
Felix Cravic 2020-12-11 22:07:00 +01:00
commit e9dd1a1366
7 changed files with 173 additions and 49 deletions

View File

@ -0,0 +1,18 @@
package net.minestom.server.utils.math;
public class ByteRange extends Range<Byte> {
public ByteRange(Byte minimum, Byte maximum) {
super(minimum, maximum);
}
public ByteRange(Byte value) {
super(value);
}
/** {@inheritDoc} */
@Override
public boolean isInRange(Byte value) {
return value >= this.getMinimum() && value <= this.getMaximum();
}
}

View File

@ -0,0 +1,18 @@
package net.minestom.server.utils.math;
public class DoubleRange extends Range<Double> {
public DoubleRange(Double minimum, Double maximum) {
super(minimum, maximum);
}
public DoubleRange(Double value) {
super(value);
}
/** {@inheritDoc} */
@Override
public boolean isInRange(Double value) {
return value >= this.getMinimum() && value <= this.getMaximum();
}
}

View File

@ -1,32 +1,19 @@
package net.minestom.server.utils.math;
public class FloatRange {
public class FloatRange extends Range<Float> {
private float min, max;
public FloatRange(Float minimum, Float maximum) {
super(minimum, maximum);
}
public FloatRange(float min, float max) {
this.min = min;
this.max = max;
}
public FloatRange(Float value) {
super(value);
}
public FloatRange(float value) {
this(value, value);
}
public float getMin() {
return min;
}
public void setMin(float min) {
this.min = min;
}
public float getMax() {
return max;
}
public void setMax(float max) {
this.max = max;
}
/** {@inheritDoc} */
@Override
public boolean isInRange(Float value) {
return value >= this.getMinimum() && value <= this.getMaximum();
}
}

View File

@ -1,31 +1,19 @@
package net.minestom.server.utils.math;
public class IntRange {
public class IntRange extends Range<Integer> {
private int min, max;
public IntRange(Integer minimum, Integer maximum) {
super(minimum, maximum);
}
public IntRange(int min, int max) {
this.min = min;
this.max = max;
}
public IntRange(Integer value) {
super(value);
}
public IntRange(int value) {
this(value, value);
}
/** {@inheritDoc} */
@Override
public boolean isInRange(Integer value) {
return value >= this.getMinimum() && value <= this.getMaximum();
public int getMin() {
return min;
}
public void setMin(int min) {
this.min = min;
}
public int getMax() {
return max;
}
public void setMax(int max) {
this.max = max;
}
}
}

View File

@ -0,0 +1,18 @@
package net.minestom.server.utils.math;
public class LongRange extends Range<Long> {
public LongRange(Long minimum, Long maximum) {
super(minimum, maximum);
}
public LongRange(Long value) {
super(value);
}
/** {@inheritDoc} */
@Override
public boolean isInRange(Long value) {
return value >= this.getMinimum() && value <= this.getMaximum();
}
}

View File

@ -0,0 +1,77 @@
package net.minestom.server.utils.math;
/**
* Represents the base for any data type that is numeric.
*
* @param <T> The type numeric of the range object.
*/
public abstract class Range<T> {
private T minimum;
private T maximum;
/**
* Constructs a new {@link Range} with a {@code minimum} and a {@code maximum} value.
*
* @param minimum The minimum of the range.
* @param maximum The maximum of the range.
*/
public Range(T minimum, T maximum) {
this.minimum = minimum;
this.maximum = maximum;
}
/**
* Constructs a new {@link Range} with the {@code value}.
*
* @param value The value of the range.
*/
public Range(T value) {
this(value, value);
}
/**
* Retrieves the minimum value of the range.
*
* @return The range's minimum value.
*/
public T getMinimum() {
return this.minimum;
}
/**
* Changes the minimum value of the range.
*
* @param minimum The new minimum value.
*/
public void setMinimum(T minimum) {
this.minimum = minimum;
}
/**
* Retrieves the maximum value of the range.
*
* @return The range's maximum value.
*/
public T getMaximum() {
return this.maximum;
}
/**
* Changes the maximum value of the range.
*
* @param maximum The new maximum value.
*/
public void setMaximum(T maximum) {
this.maximum = maximum;
}
/**
* Whether the given {@code value} is in range of the minimum and the maximum.
*
* @param value The value to be checked.
* @return {@code true} if the value in the range of {@code minimum} and {@code maximum},
* otherwise {@code false}.
*/
public abstract boolean isInRange(T value);
}

View File

@ -0,0 +1,18 @@
package net.minestom.server.utils.math;
public class ShortRange extends Range<Short> {
public ShortRange(Short minimum, Short maximum) {
super(minimum, maximum);
}
public ShortRange(Short value) {
super(value);
}
/** {@inheritDoc} */
@Override
public boolean isInRange(Short value) {
return value >= this.getMinimum() && value <= this.getMaximum();
}
}