Logging the sorted result.

This commit is contained in:
aminecmi 2021-10-30 15:21:28 +02:00
parent 5fe4fe2cec
commit 1e29bd41e9
2 changed files with 29 additions and 1 deletions

View File

@ -3,6 +3,8 @@ package fr.aminelouveaau.cartes.model;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;
public class Card { public class Card {
private final Shape shape; private final Shape shape;
private final Number number; private final Number number;
@ -20,4 +22,22 @@ public class Card {
public Number getNumber() { public Number getNumber() {
return number; 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());
}
} }

View File

@ -4,6 +4,8 @@ import fr.aminelouveaau.cartes.model.Card;
import fr.aminelouveaau.cartes.model.Number; import fr.aminelouveaau.cartes.model.Number;
import fr.aminelouveaau.cartes.model.Shape; import fr.aminelouveaau.cartes.model.Shape;
import fr.aminelouveaau.cartes.model.api.SortingResult; 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.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -15,6 +17,9 @@ import java.util.stream.Collectors;
@Service @Service
public class GameService { public class GameService {
private final Logger logger = LoggerFactory.getLogger(GameService.class);
@Value("${cards.hand.number}") @Value("${cards.hand.number}")
private Integer cardHandNumber; private Integer cardHandNumber;
@ -74,10 +79,13 @@ public class GameService {
} }
public SortingResult sortHand(List<Card> hand) { public SortingResult sortHand(List<Card> hand) {
List<Card> 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( return new SortingResult(
shapeOrder, shapeOrder,
numberOrder, numberOrder,
hand.stream().sorted((o1, o2) -> comparator.compare(o1, o2)).collect(Collectors.toList()) sortedHand
); );
} }
} }