From 70873539c7f231b4171421519017fb9c5724f0b2 Mon Sep 17 00:00:00 2001 From: "alexis.drai@etu.uca.fr" Date: Sat, 27 May 2023 19:30:05 +0200 Subject: [PATCH] :recycle: Make the move set an actual Set --- .../java/fr/uca/iut/codecs/pokemong/PokemongCodec.java | 9 +++++---- src/main/java/fr/uca/iut/entities/Pokemong.java | 9 +++++---- src/main/java/fr/uca/iut/services/PokemongService.java | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/uca/iut/codecs/pokemong/PokemongCodec.java b/src/main/java/fr/uca/iut/codecs/pokemong/PokemongCodec.java index 0b4b948..fe1fb18 100644 --- a/src/main/java/fr/uca/iut/codecs/pokemong/PokemongCodec.java +++ b/src/main/java/fr/uca/iut/codecs/pokemong/PokemongCodec.java @@ -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 { @@ -133,15 +134,15 @@ public class PokemongCodec extends GenericCodec { .collect(Collectors.toList()); pokemong.setTypes(types); - List moveSet = document.getList("moveSet", Document.class) - .stream() - .map(pokemongMoveDoc -> { + Set 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; diff --git a/src/main/java/fr/uca/iut/entities/Pokemong.java b/src/main/java/fr/uca/iut/entities/Pokemong.java index 4d08a1f..f44732a 100644 --- a/src/main/java/fr/uca/iut/entities/Pokemong.java +++ b/src/main/java/fr/uca/iut/entities/Pokemong.java @@ -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 moveSet; + private Set moveSet; public Pokemong() {} @@ -95,11 +96,11 @@ public class Pokemong extends GenericEntity { this.types = types; } - public List getMoveSet() { - return Collections.unmodifiableList(moveSet); + public Set getMoveSet() { + return Collections.unmodifiableSet(moveSet); } - public void setMoveSet(List moveSet) { + public void setMoveSet(Set moveSet) { this.moveSet = moveSet; } diff --git a/src/main/java/fr/uca/iut/services/PokemongService.java b/src/main/java/fr/uca/iut/services/PokemongService.java index 0836776..9b51cd0 100644 --- a/src/main/java/fr/uca/iut/services/PokemongService.java +++ b/src/main/java/fr/uca/iut/services/PokemongService.java @@ -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 { @@ -83,7 +84,7 @@ public class PokemongService extends GenericService { throw new NonValidEntityException("pokemong types was null or empty or had more than 2 types"); } - List moveSet = pokemong.getMoveSet(); + Set moveSet = pokemong.getMoveSet(); if (moveSet == null || moveSet.size() == 0 || moveSet.size() > 4)