de.pewpewproject.lasertag.lasertaggame.state.server.implementation.MusicalChairsState   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A reset() 0 4 1
A getPlayerOverallScore(UUID) 0 3 1
A setPlayerOverallScore(UUID,long) 0 3 1
1
package de.pewpewproject.lasertag.lasertaggame.state.server.implementation;
2
3
import de.pewpewproject.lasertag.lasertaggame.state.server.IMusicalChairsState;
4
5
import java.util.Map;
6
import java.util.Optional;
7
import java.util.UUID;
8
import java.util.concurrent.ConcurrentHashMap;
9
10
/**
11
 * Implementation of IMusicalChairsState for the lasertag game.
12
 *
13
 * @author Étienne Muser
14
 */
15
public class MusicalChairsState implements IMusicalChairsState {
16
17
    /**
18
     * Map mapping every player's uuid to the overall score they achieved
19
     *     key: The players uuid
20
     *     value: The overall score the player achieved
21
     */
22
    private final Map<UUID, Long> playerOverallScoreMap = new ConcurrentHashMap<>();
23
24
    @Override
25
    public void setPlayerOverallScore(UUID playerUuid, long newScore) {
26
        playerOverallScoreMap.put(playerUuid, newScore);
27
    }
28
29
    @Override
30
    public long getPlayerOverallScore(UUID playerUuid) {
31
        return Optional.ofNullable(playerOverallScoreMap.get(playerUuid)).orElse(0L);
32
    }
33
34
    @Override
35
    public void reset() {
36
37
        playerOverallScoreMap.clear();
38
    }
39
}
40