feat: implemented aquiring characters of random order in CharacterConfig
This commit is contained in:
@ -4,8 +4,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import uulm.teamname.marvelous.gamelibrary.Tuple;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* POJO describing the CharacterConfig as defined by the standard document.
|
||||
@ -14,7 +17,7 @@ public class CharacterConfig {
|
||||
|
||||
@NotEmpty
|
||||
@Valid
|
||||
@Size(min = 12, message = "has less than 12 characters")
|
||||
@Size(min = 24, message = "has less than 24 characters")
|
||||
public CharacterProperties[] characters;
|
||||
|
||||
@JsonIgnore private Map<String, CharacterProperties> propertyMap;
|
||||
@ -38,6 +41,18 @@ public class CharacterConfig {
|
||||
return unmodifiablePropertyMap;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Tuple<CharacterProperties[], CharacterProperties[]> getDisjointSetsOfPropertiesOfSize(int size) {
|
||||
if ((size * 2) > characters.length) {
|
||||
return null;
|
||||
} else {
|
||||
var characterList = Arrays.asList(this.characters);
|
||||
Collections.shuffle(characterList);
|
||||
return Tuple.of(characterList.subList(0, size).toArray(new CharacterProperties[0]),
|
||||
characterList.subList(size, 2 * size).toArray(new CharacterProperties[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
Reference in New Issue
Block a user