♻️ Make the move set an actual Set

pull/4/head
Alexis Drai 2 years ago
parent e9c468fdc8
commit 70873539c7

@ -18,6 +18,7 @@ import org.bson.types.ObjectId;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class PokemongCodec extends GenericCodec<Pokemong> {
@ -133,15 +134,15 @@ public class PokemongCodec extends GenericCodec<Pokemong> {
.collect(Collectors.toList());
pokemong.setTypes(types);
List<PokemongMove> moveSet = document.getList("moveSet", Document.class)
.stream()
.map(pokemongMoveDoc -> {
Set<PokemongMove> moveSet = document.getList("moveSet", Document.class)
.stream()
.map(pokemongMoveDoc -> {
PokemongMove move = new PokemongMove();
move.setId(((ObjectId) pokemongMoveDoc.get("_id")).toString());
move.setName(pokemongMoveDoc.getString("name"));
return move;
})
.collect(Collectors.toList());
.collect(Collectors.toSet());
pokemong.setMoveSet(moveSet);
return pokemong;

@ -7,6 +7,7 @@ import org.bson.types.ObjectId;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.Set;
public class Pokemong extends GenericEntity {
public static final String COLLECTION_NAME = "pokemongs";
@ -25,7 +26,7 @@ public class Pokemong extends GenericEntity {
/**
* pokemong.moveSet: [{_id: ObjectId, name: String}]
*/
private List<PokemongMove> moveSet;
private Set<PokemongMove> moveSet;
public Pokemong() {}
@ -95,11 +96,11 @@ public class Pokemong extends GenericEntity {
this.types = types;
}
public List<PokemongMove> getMoveSet() {
return Collections.unmodifiableList(moveSet);
public Set<PokemongMove> getMoveSet() {
return Collections.unmodifiableSet(moveSet);
}
public void setMoveSet(List<PokemongMove> moveSet) {
public void setMoveSet(Set<PokemongMove> moveSet) {
this.moveSet = moveSet;
}

@ -13,6 +13,7 @@ import jakarta.inject.Inject;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Set;
@ApplicationScoped
public class PokemongService extends GenericService<Pokemong> {
@ -83,7 +84,7 @@ public class PokemongService extends GenericService<Pokemong> {
throw new NonValidEntityException("pokemong types was null or empty or had more than 2 types");
}
List<PokemongMove> moveSet = pokemong.getMoveSet();
Set<PokemongMove> moveSet = pokemong.getMoveSet();
if (moveSet == null
|| moveSet.size() == 0
|| moveSet.size() > 4)

Loading…
Cancel
Save