Class RateLimit<K>

java.lang.Object
net.guizhanss.guizhanlib.common.RateLimit<K>
Type Parameters:
K - The type of key.

public final class RateLimit<K> extends Object
This package provides rate limit feature.
Author:
ybw0014
  • Constructor Summary

    Constructors
    Constructor
    Description
    RateLimit(long time, int visits)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(K key)
    Increases the times of visits by 1.
    boolean
    add(K key, int visits)
    Increases the times of visits.
    int
    Get the overall limit of visits.
    int
    Get remaining times of visits
    int
    getUsed(K key)
    Get the used visits.
    void
    reset(K key)
    Reset rate limit

    Methods inherited from class java.lang.Object

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

    • RateLimit

      public RateLimit(long time, int visits)
      Constructor.
      Parameters:
      time - Time period in milliseconds.
      visits - The limit times of visits.
  • Method Details

    • getLimit

      public int getLimit()
      Get the overall limit of visits.
      Returns:
      The overall limit of visits.
    • getUsed

      public int getUsed(K key)
      Get the used visits.
      Parameters:
      key - The query key.
      Returns:
      Used times of visits.
    • getRemaining

      public int getRemaining(K key)
      Get remaining times of visits
      Parameters:
      key - The query key.
      Returns:
      Remaining times of visits
    • add

      public boolean add(K key, int visits)
      Increases the times of visits.
      Parameters:
      key - The query key.
      visits - The times of visits
      Returns:
      Whether the action succeeds.
    • add

      public boolean add(K key)
      Increases the times of visits by 1.
      Parameters:
      key - The query key.
      Returns:
      Whether the action succeeds.
    • reset

      public void reset(K key)
      Reset rate limit
      Parameters:
      key - The query key.