From 1e29bd41e9f85f8f65cab2c0a54e6c27ef0f670e Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sat, 30 Oct 2021 15:21:28 +0200 Subject: [PATCH] Logging the sorted result. --- .../fr/aminelouveaau/cartes/model/Card.java | 20 +++++++++++++++++++ .../cartes/service/GameService.java | 10 +++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/aminelouveaau/cartes/model/Card.java b/src/main/java/fr/aminelouveaau/cartes/model/Card.java index 84416c3..1896b1e 100644 --- a/src/main/java/fr/aminelouveaau/cartes/model/Card.java +++ b/src/main/java/fr/aminelouveaau/cartes/model/Card.java @@ -3,6 +3,8 @@ package fr.aminelouveaau.cartes.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; + public class Card { private final Shape shape; private final Number number; @@ -20,4 +22,22 @@ public class Card { public Number getNumber() { return number; } + + @Override + public String toString() { + return number + " of " + shape; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Card card = (Card) o; + return getShape() == card.getShape() && getNumber() == card.getNumber(); + } + + @Override + public int hashCode() { + return Objects.hash(getShape(), getNumber()); + } } diff --git a/src/main/java/fr/aminelouveaau/cartes/service/GameService.java b/src/main/java/fr/aminelouveaau/cartes/service/GameService.java index 4bc5d87..b10f91e 100644 --- a/src/main/java/fr/aminelouveaau/cartes/service/GameService.java +++ b/src/main/java/fr/aminelouveaau/cartes/service/GameService.java @@ -4,6 +4,8 @@ import fr.aminelouveaau.cartes.model.Card; import fr.aminelouveaau.cartes.model.Number; import fr.aminelouveaau.cartes.model.Shape; import fr.aminelouveaau.cartes.model.api.SortingResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -15,6 +17,9 @@ import java.util.stream.Collectors; @Service public class GameService { + private final Logger logger = LoggerFactory.getLogger(GameService.class); + + @Value("${cards.hand.number}") private Integer cardHandNumber; @@ -74,10 +79,13 @@ public class GameService { } public SortingResult sortHand(List hand) { + List sortedHand = hand.stream().sorted((o1, o2) -> comparator.compare(o1, o2)).collect(Collectors.toList()); + logger.info("Hand : " + hand); + logger.info("Sorted hand : " + sortedHand); return new SortingResult( shapeOrder, numberOrder, - hand.stream().sorted((o1, o2) -> comparator.compare(o1, o2)).collect(Collectors.toList()) + sortedHand ); } }