Logging the sorted result.
This commit is contained in:
parent
5fe4fe2cec
commit
1e29bd41e9
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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<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(
|
||||
shapeOrder,
|
||||
numberOrder,
|
||||
hand.stream().sorted((o1, o2) -> comparator.compare(o1, o2)).collect(Collectors.toList())
|
||||
sortedHand
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user