Interface Leaderboard

All Known Implementing Classes:
SkipListLeaderboard

public interface Leaderboard
Created by 0da on 08.06.2023 20:45; (ノ◕ヮ◕)ノ*:・゚✧
Main interface of that "library". Describes required methods for any implementation of leaderboard.
  • Method Summary

    Modifier and Type
    Method
    Description
    around(long target, int up, int down, boolean desc)
    Method takes slice around position of a specific target.
    Method returns current best implementation of leaderboard for average usage.
    find(long target)
    Method finds entry row of specified target.
    void
    remove(long target)
    Method removes entry with specified target from leaderboard.
    int
    Method returns current amounts of entries un that leaderboard.
    slice(int from, int limit)
    Method calculates and returns slice of current situation in leaderboard.
    slice(int from, int limit, boolean desc)
    Method calculates and returns slice of current situation in leaderboard.
    void
    update(long target, long score)
    Method to update (or insert new) score for specified target in that leaderboard.
    default void
    updateAll(Map<Long,Long> entries)
    Method for updating multiple entries at once.
  • Method Details

    • size

      int size()
      Method returns current amounts of entries un that leaderboard.
      Returns:
      current amounts of entries un that leaderboard.
    • slice

      List<LeaderboardRow> slice(int from, int limit, boolean desc)
      Method calculates and returns slice of current situation in leaderboard.
      Parameters:
      from - place that will be start of slice inclusive. Minimal meaningful value is 1, because minimal value of LeaderboardRow.place() is 1.
      limit - maximum amount of entries in result.
      desc - this flags determinants 'direction' of a slice. If this value is true then result will contain values in descending order [from, f - 1, f - 2, ...], else [f, f + 1, from + 2, ...].
      Returns:
      new list with result for specified arguments, maximum length is limit and first value (if not empty) with place from.
    • slice

      default List<LeaderboardRow> slice(int from, int limit)
      Method calculates and returns slice of current situation in leaderboard. Shorthand of method slice(int, int, boolean), alternative code:
      
        var slice = leaderboard.slice(from, limit, false);
       
      Parameters:
      from - place that will be start of slice inclusive. Minimal meaningful value is 1, because minimal value of LeaderboardRow.place() is 1.
      limit - maximum amount of entries in result.
      Returns:
      new list with result for specified arguments, maximum length is limit and first value (if not empty) with place from. Order of returned values is [from, from + 1, from + 2, ...].
      See Also:
    • find

      Optional<LeaderboardRow> find(long target)
      Method finds entry row of specified target.
      Parameters:
      target - id of target that you need to acquire.
      Returns:
      valid row of a target if that target is present into that leaderboard.
    • around

      List<LeaderboardRow> around(long target, int up, int down, boolean desc)
      Method takes slice around position of a specific target.
      Parameters:
      target - id of the target around which slice will be made.
      up - amount of entries that will be taken before target.
      down - amount of entries that will be taken after target.
      desc - this flags determinants 'direction' of a slice. If this value is true then result will contain values in descending order [..., t + 1, t + 2, target, t - 1, t - 2, ...], else [..., t - 1, t - 2, target, t + 1, t + 2, ...].
      Returns:
      new list with result for specified arguments.
    • update

      void update(long target, long score)
      Method to update (or insert new) score for specified target in that leaderboard.
      Parameters:
      target - id of a target to update.
      score - new score to associate with that target.
      See Also:
    • updateAll

      default void updateAll(Map<Long,Long> entries)
      Method for updating multiple entries at once. Default implementation:
      
       for (var entry : entries.entrySet()) {
           update(entry.getKey(), entry.getValue());
       }
       
      Parameters:
      entries - map of entries where key is target and value - new score.
      See Also:
    • remove

      void remove(long target)
      Method removes entry with specified target from leaderboard. All entries after removed must adjust their positions.
      Parameters:
      target - target which must be removed.
    • create

      static Leaderboard create()
      Method returns current best implementation of leaderboard for average usage.
      Returns:
      current best implementation of leaderboard for average usage. At this moment its SkipListLeaderboard.