Class ClampedNum<T extends Comparable<T>>

java.lang.Object
net.rotgruengelb.nixienaut.math.ClampedNum<T>
Type Parameters:
T - The type of the number.

public class ClampedNum<T extends Comparable<T>> extends Object
A number that is clamped between a minimum and a maximum value.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ClampedNum(T minValue, T maxValue)
    Creates a new ClampedNum object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    adjustSet(T value)
    Sets the value and clamps it if it is out of range.
    static float
    clamp(float value, float minValue, float maxValue)
    Clamps a float value between a minimum and a maximum value.
    static int
    clamp(int value, int minValue, int maxValue)
    Clamps an integer value between a minimum and a maximum value.
    get()
    Gets the minimum value.
    Gets the maximum value.
    Gets the minimum value.
    void
    set(T value)
    Sets the value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ClampedNum

      public ClampedNum(T minValue, T maxValue)
      Creates a new ClampedNum object.
      Parameters:
      minValue - The minimum value.
      maxValue - The maximum value.
      See Also:
  • Method Details

    • clamp

      public static int clamp(int value, int minValue, int maxValue)
      Clamps an integer value between a minimum and a maximum value.
      Parameters:
      value - The value to clamp.
      minValue - The minimum value.
      maxValue - The maximum value.
      Returns:
      The clamped value.
    • clamp

      public static float clamp(float value, float minValue, float maxValue)
      Clamps a float value between a minimum and a maximum value.
      Parameters:
      value - The value to clamp.
      minValue - The minimum value.
      maxValue - The maximum value.
      Returns:
      The clamped value.
    • get

      public T get()
      Gets the minimum value.
      Returns:
      The minimum value.
    • set

      public void set(T value) throws IllegalArgumentException
      Sets the value.
      Parameters:
      value - The value to set.
      Throws:
      IllegalArgumentException - If the value is out of range.
      See Also:
    • adjustSet

      public void adjustSet(T value)
      Sets the value and clamps it if it is out of range.
      Parameters:
      value - The value to set.
      See Also:
    • getMinValue

      public T getMinValue()
      Gets the minimum value.
      Returns:
      The minimum value.
      See Also:
    • getMaxValue

      public T getMaxValue()
      Gets the maximum value.
      Returns:
      The maximum value.
      See Also: