|
|
|
@ -27,7 +27,7 @@ public class PokemongCodec extends GenericCodec<Pokemong> {
|
|
|
|
|
|
|
|
|
|
public PokemongCodec() {
|
|
|
|
|
this.documentCodec = MongoClientSettings.getDefaultCodecRegistry()
|
|
|
|
|
.get(Document.class);
|
|
|
|
|
.get(Document.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -42,8 +42,8 @@ public class PokemongCodec extends GenericCodec<Pokemong> {
|
|
|
|
|
|
|
|
|
|
doc.put("dob",
|
|
|
|
|
Date.from(pokemong.getDob()
|
|
|
|
|
.atStartOfDay(ZoneId.systemDefault())
|
|
|
|
|
.toInstant()));
|
|
|
|
|
.atStartOfDay(ZoneId.systemDefault())
|
|
|
|
|
.toInstant()));
|
|
|
|
|
|
|
|
|
|
doc.put("level", pokemong.getLevel());
|
|
|
|
|
|
|
|
|
@ -52,9 +52,9 @@ public class PokemongCodec extends GenericCodec<Pokemong> {
|
|
|
|
|
doc.put("evoStage", pokemong.getEvoStage());
|
|
|
|
|
|
|
|
|
|
List<String> evoTrack = pokemong.getEvoTrack()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(Enum::name)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
.stream()
|
|
|
|
|
.map(Enum::name)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
doc.put("evoTrack", evoTrack);
|
|
|
|
|
|
|
|
|
|
if (pokemong.getTrainer() != null) {
|
|
|
|
@ -62,36 +62,36 @@ public class PokemongCodec extends GenericCodec<Pokemong> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Document> types = pokemong.getTypes()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(type -> {
|
|
|
|
|
Document typeDoc = new Document();
|
|
|
|
|
typeDoc.put("name",
|
|
|
|
|
type.getName()
|
|
|
|
|
.name());
|
|
|
|
|
List<String> weakAgainst = type.getWeakAgainst()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(Enum::name)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
typeDoc.put("weakAgainst", weakAgainst);
|
|
|
|
|
List<String> effectiveAgainst = type.getEffectiveAgainst()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(Enum::name)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
typeDoc.put("effectiveAgainst", effectiveAgainst);
|
|
|
|
|
return typeDoc;
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
.stream()
|
|
|
|
|
.map(type -> {
|
|
|
|
|
Document typeDoc = new Document();
|
|
|
|
|
typeDoc.put("name",
|
|
|
|
|
type.getName()
|
|
|
|
|
.name());
|
|
|
|
|
List<String> weakAgainst = type.getWeakAgainst()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(Enum::name)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
typeDoc.put("weakAgainst", weakAgainst);
|
|
|
|
|
List<String> effectiveAgainst = type.getEffectiveAgainst()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(Enum::name)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
typeDoc.put("effectiveAgainst", effectiveAgainst);
|
|
|
|
|
return typeDoc;
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
doc.put("types", types);
|
|
|
|
|
|
|
|
|
|
List<Document> moveSetDocs = pokemong.getMoveSet()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(move -> {
|
|
|
|
|
Document moveDoc = new Document();
|
|
|
|
|
moveDoc.put("_id", new ObjectId(move.getId()));
|
|
|
|
|
moveDoc.put("name", move.getName());
|
|
|
|
|
return moveDoc;
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
.stream()
|
|
|
|
|
.map(move -> {
|
|
|
|
|
Document moveDoc = new Document();
|
|
|
|
|
moveDoc.put("_id", new ObjectId(move.getId()));
|
|
|
|
|
moveDoc.put("name", move.getName());
|
|
|
|
|
return moveDoc;
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
doc.put("moveSet", moveSetDocs);
|
|
|
|
|
|
|
|
|
|
documentCodec.encode(writer, doc, encoderContext);
|
|
|
|
@ -118,7 +118,7 @@ public class PokemongCodec extends GenericCodec<Pokemong> {
|
|
|
|
|
Pokemong pokemong = new Pokemong();
|
|
|
|
|
|
|
|
|
|
pokemong.setId(document.getObjectId("_id")
|
|
|
|
|
.toString());
|
|
|
|
|
.toString());
|
|
|
|
|
|
|
|
|
|
pokemong.setSchemaVersion(document.getInteger("schemaVersion"));
|
|
|
|
|
|
|
|
|
@ -127,8 +127,8 @@ public class PokemongCodec extends GenericCodec<Pokemong> {
|
|
|
|
|
Date dob = document.getDate("dob");
|
|
|
|
|
if (dob != null) {
|
|
|
|
|
pokemong.setDob(dob.toInstant()
|
|
|
|
|
.atZone(ZoneId.systemDefault())
|
|
|
|
|
.toLocalDate());
|
|
|
|
|
.atZone(ZoneId.systemDefault())
|
|
|
|
|
.toLocalDate());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pokemong.setLevel(document.getInteger("level"));
|
|
|
|
@ -138,9 +138,9 @@ public class PokemongCodec extends GenericCodec<Pokemong> {
|
|
|
|
|
pokemong.setEvoStage(document.getInteger("evoStage"));
|
|
|
|
|
|
|
|
|
|
List<PokemongName> evoTrack = document.getList("evoTrack", String.class)
|
|
|
|
|
.stream()
|
|
|
|
|
.map(PokemongName::valueOf)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
.stream()
|
|
|
|
|
.map(PokemongName::valueOf)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
pokemong.setEvoTrack(evoTrack);
|
|
|
|
|
|
|
|
|
|
ObjectId trainerId = document.getObjectId("trainer");
|
|
|
|
@ -149,20 +149,20 @@ public class PokemongCodec extends GenericCodec<Pokemong> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set<Type> types = document.getList("types", Document.class)
|
|
|
|
|
.stream()
|
|
|
|
|
.map(TypeCodecUtil::extractType)
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
.stream()
|
|
|
|
|
.map(TypeCodecUtil::extractType)
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
pokemong.setTypes(types);
|
|
|
|
|
|
|
|
|
|
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.toSet());
|
|
|
|
|
.stream()
|
|
|
|
|
.map(pokemongMoveDoc -> {
|
|
|
|
|
PokemongMove move = new PokemongMove();
|
|
|
|
|
move.setId(((ObjectId) pokemongMoveDoc.get("_id")).toString());
|
|
|
|
|
move.setName(pokemongMoveDoc.getString("name"));
|
|
|
|
|
return move;
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
pokemong.setMoveSet(moveSet);
|
|
|
|
|
|
|
|
|
|
return pokemong;
|
|
|
|
|