package com.example.application.utils;
|
|
|
|
import com.example.application.data.chesscom.ChessComGame;
|
|
import com.example.application.data.entity.Player;
|
|
import org.springframework.lang.NonNull;
|
|
|
|
public class ChessComUtils {
|
|
private ChessComUtils() {}
|
|
|
|
public static String getPreparedArchiveJson(String unpreparedArchiveJson) {
|
|
return unpreparedArchiveJson
|
|
.replace("@id", "id")
|
|
.replace("end_time", "endTime")
|
|
.replace("time_class", "timeClass")
|
|
.replace("time_control", "timeControl");
|
|
}
|
|
|
|
public static String getUrlPart(Player player) {
|
|
return player.getNickname().toLowerCase();
|
|
}
|
|
|
|
public static int getResult(ChessComGame chessComGame) {
|
|
if (chessComGame.getWhite().getResult().equals("win")) {
|
|
return 1;
|
|
}
|
|
if (chessComGame.getBlack().getResult().equals("win")) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static boolean isGameBetween(@NonNull ChessComGame game, @NonNull Player player1, @NonNull Player player2) {
|
|
String white = game.getWhite().getUsername();
|
|
String black = game.getBlack().getUsername();
|
|
String name1 = player1.getNickname();
|
|
String name2 = player2.getNickname();
|
|
return (white.equals(name1) || white.equals(name2)) && (black.equals(name1) || black.equals(name2));
|
|
}
|
|
|
|
public static boolean hasValidTimeControl(ChessComGame game) {
|
|
String timeControl = game.getTimeControl();
|
|
if (timeControl != null) {
|
|
return timeControl.equals("600") || timeControl.equals("300") || timeControl.equals("180");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|