player-storage

Library for managing the storage of players.

View the Project on GitHub akifev/player-storage

Player Storage

This is a library for managing the storage of players with the ability to add or update, delete, get a rank, and roll back.

Table Of Contents

Overview

This library contains the thread-safe class PlayerStorage which implements Storage interface.

Operations

Class PlayerStorage implements the following methods.

registerPlayerResult

Adds a player with a rating or updates a player rating, if one has been already added.

@Synchronized
fun registerPlayerResult(playerName: String, playerRating: Int): Boolean

Note: This method is marked as @Synchronized.

unregisterPlayer

Deletes the player from the storage.

@Synchronized
fun unregisterPlayer(playerName: String): Boolean

Note: This method is marked as @Synchronized.

getPlayerRank

Returns player rank. Rank is a position in the rating table.

fun getPlayerRank(playerName: String): Int?

rollback

Rolls the last [step] registerPlayerResult or unregisterPlayer invocations back.

@Synchronized
fun rollback(step: Int): Boolean

Note: This method is marked as @Synchronized.

Using in your project

The library published to JitPack repository.

Maven

Step 1. Add the JitPack repository to your build file.

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Step 2. Add the dependency.

<dependency>
    <groupId>com.github.akifev</groupId>
    <artifactId>player-storage</artifactId>
    <version>2.0</version>
</dependency>

Gradle

Step 1. Add the JitPack repository to your build file.

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency.

dependencies {
        implementation 'com.github.akifev:player-storage:2.0'
}

Performance

JMH Benchmark

Here is the relation of average operation execution time to the quantity of players added to the storage.

Quantity of players 14 62 1022 8190 65534  
registerPlayerResult 307 510 1079 1984 4156 ns/op
unregisterPlayer 313 585 1123 1974 4385 ns/op
getPlayerRank 135 239 544 1104 2328 ns/op
rollback 58 50 59 31 9 ns/op