Package fo.nya.leaderboard
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.
Main interface of that "library". Describes required methods for any implementation of leaderboard.
-
Method Summary
Modifier and TypeMethodDescriptionaround(long target, int up, int down, boolean desc) Method takes slice around position of a specific target.static Leaderboardcreate()Method returns current best implementation of leaderboard for average usage.find(long target) Method finds entry row of specified target.voidremove(long target) Method removes entry with specified target from leaderboard.intsize()Method returns current amounts of entries un that leaderboard.default List<LeaderboardRow>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.voidupdate(long target, long score) Method to update (or insert new) score for specified target in that leaderboard.default voidMethod 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
Method calculates and returns slice of current situation in leaderboard.- Parameters:
from- place that will be start of slice inclusive. Minimal meaningful value is1, because minimal value ofLeaderboardRow.place()is 1.limit- maximum amount of entries in result.desc- this flags determinants 'direction' of a slice. If this value istruethen 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
limitand first value (if not empty) with placefrom.
-
slice
Method calculates and returns slice of current situation in leaderboard. Shorthand of methodslice(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 is1, because minimal value ofLeaderboardRow.place()is 1.limit- maximum amount of entries in result.- Returns:
- new list with result for specified arguments, maximum length is
limitand first value (if not empty) with placefrom. Order of returned values is[from, from + 1, from + 2, ...]. - See Also:
-
find
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
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 istruethen 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
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
Method returns current best implementation of leaderboard for average usage.- Returns:
- current best implementation of leaderboard for average usage. At this moment its
SkipListLeaderboard.
-