Class Limiter

java.lang.Object
com.marcpg.libpg.util.Limiter

public class Limiter extends Object
Utility object that can be used for limiting something to a specific amount. Useful for things like warnings that should only be sent n amount of times.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Limiter(@org.jetbrains.annotations.Range(from=1L, to=2147483647L) int limit)
    Creates a new Limiter with a specific limit.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    get()
    Gets whether the counter is still under the set limit or not.
    int
    Gets the current counter, which will never be higher than the set limit.
    void
    Increments the counter by one.
    boolean
    First increments the counter by one.

    Methods inherited from class java.lang.Object

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

    • Limiter

      public Limiter(@org.jetbrains.annotations.Range(from=1L, to=2147483647L) int limit)
      Creates a new Limiter with a specific limit. The can not be 0 or less.
      Parameters:
      limit - The limit, which cannot be changed afterwards.
  • Method Details

    • increment

      public void increment()
      Increments the counter by one. If it already reached the limit, nothing happens.
    • incrementAndGet

      public boolean incrementAndGet()
      First increments the counter by one. If it already reached the limit, nothing happens. After that, it checks whether the limit is reached or not.
      Returns:
      true if the counter is still under the limit.
      false if it already reached the limit.
      See Also:
    • get

      public boolean get()
      Gets whether the counter is still under the set limit or not.
      Returns:
      true if the counter is still under the limit.
      false if it already reached the limit.
    • getCounter

      public int getCounter()
      Gets the current counter, which will never be higher than the set limit.
      Returns:
      The current counter.