Class Incrementor

java.lang.Object
org.hipparchus.util.Incrementor

public class Incrementor extends Object
Utility that increments a counter until a maximum is reached, at which point, the instance will by default throw a MathIllegalStateException. However, the user is able to override this behaviour by defining a custom callback, in order to e.g. select which exception must be thrown.
  • Constructor Details Link icon

  • Method Details Link icon

    • withCount Link icon

      public Incrementor withCount(int value)
      Creates a new instance and set the counter to the given value.
      Parameters:
      value - Value of the counter.
      Returns:
      a new instance.
    • withMaximalCount Link icon

      public Incrementor withMaximalCount(int max)
      Creates a new instance with a given maximal count. The counter is reset to 0.
      Parameters:
      max - Maximal count.
      Returns:
      a new instance.
      Throws:
      MathIllegalArgumentException - if max is negative.
    • withCallback Link icon

      Creates a new instance with a given callback. The counter is reset to 0.
      Parameters:
      cb - Callback to be called at counter exhaustion.
      Returns:
      a new instance.
    • getMaximalCount Link icon

      public int getMaximalCount()
      Gets the upper limit of the counter.
      Returns:
      the counter upper limit.
    • getCount Link icon

      public int getCount()
      Gets the current count.
      Returns:
      the current count.
    • canIncrement Link icon

      public boolean canIncrement()
      Checks whether incrementing the counter nTimes is allowed.
      Returns:
      false if calling increment() will trigger a MathIllegalStateException, true otherwise.
    • canIncrement Link icon

      public boolean canIncrement(int nTimes)
      Checks whether incrementing the counter several times is allowed.
      Parameters:
      nTimes - Number of increments.
      Returns:
      false if calling increment(nTimes) would call the callback true otherwise.
      Throws:
      MathIllegalArgumentException - if nTimes is negative.
    • increment Link icon

      public void increment(int nTimes)
      Performs multiple increments.
      Parameters:
      nTimes - Number of increments.
      Throws:
      MathIllegalArgumentException - if nTimes is negative.
      See Also:
    • increment Link icon

      public void increment()
      Adds the increment value to the current iteration count. At counter exhaustion, this method will call the trigger method of the callback object passed to the withCallback(MaxCountExceededCallback) method.
      See Also:
    • reset Link icon

      public void reset()
      Resets the counter to 0.