On se retrouve aujourd'hui pour la solution du précédent #KataOfTheWeek proposé par Lothaire en début de semaine !

Voici une proposition de solution en Java:

public class BerlinClock {

    public String getBerlinClockAsString(LocalTime time) {
        return computeBerlinClockFromLocalTime(time).toString();
    }

    public BerlinClockTime computeBerlinClockFromLocalTime(LocalTime time) {
        BerlinClockTime berlinClockTime = new BerlinClockTime();
        berlinClockTime.setSeconds(getSeconds(time.getSecond()));
        berlinClockTime.setTopHours(getTopHours(time.getHour()));
        berlinClockTime.setBottomHours(getBottomHours(time.getHour()));
        berlinClockTime.setTopMinutes(getTopMinutes(time.getMinute()));
        berlinClockTime.setBottomMinutes(getBottomMinutes(time.getMinute()));

        return berlinClockTime;
    }

    private String getSeconds(Integer seconds) {
        return seconds%2 == 0 ? Color.YELLOW.getCode() : Color.OFF.getCode();
    }

    private String getTopHours(Integer hours) {
        Integer nbOn = hours/5;

        IntFunction<Color> func = x -> x <= nbOn ? Color.RED : Color.OFF;
        return getRow(func, 4);
    }

    private String getBottomHours(Integer hours) {
        Integer nbOn = hours%5;

        IntFunction<Color> func = x -> x <= nbOn ? Color.RED : Color.OFF;
        return getRow(func, 4);
    }

    private String getTopMinutes(Integer minutes) {
        Integer nbOn = minutes/5;

        IntFunction<Color> func = x -> {
            if (x <= nbOn && x%3 == 0) {
                return Color.RED;
            } else if (x <= nbOn) {
                return Color.YELLOW;
            } else {
                return Color.OFF;
            }
        };
        return getRow(func, 11);
    }

    private String getBottomMinutes(Integer minutes) {
        Integer nbOn = minutes%5;

        IntFunction<Color> func = x -> x <= nbOn ? Color.YELLOW : Color.OFF;
        return getRow(func, 4);
    }


    private String getRow(IntFunction<Color> func, int totalLength) {
        return IntStream
                .range(1, totalLength+1)
                .mapToObj(func)
                .map(Color::getCode)
                .collect(Collectors.joining());
    }

}


public enum Color {
    RED("R"),
    YELLOW("Y"),
    OFF("O");

    private String code;

    Color (String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }
}

public class BerlinClockTime {

    private String seconds;
    private String topHours;
    private String bottomHours;
    private String topMinutes;
    private String bottomMinutes;

    @Override
    public String toString() {
        String firstDelimiter = "         -------\n";
        String delimiter = "-------------------------\n";

        return  firstDelimiter +
                row1element(seconds) +
                delimiter +
                row4elements(topHours) +
                delimiter +
                row4elements(bottomHours) +
                delimiter +
                row11elements(topMinutes) +
                delimiter +
                row4elements(bottomMinutes) +
                delimiter;
    }

    private String row1element(String element) {
        return "         |  " + element + "  |\n";
    }

    private String row4elements(String element) {
        return Arrays.stream(element.split(""))
                .collect(Collectors.joining("  |  ", "|  ", "  |\n"));
    }

    private String row11elements(String element) {
        return Arrays.stream(element.split(""))
                .collect(Collectors.joining("|", "| ", " |\n"));
    }


    public String getSeconds() {
        return seconds;
    }

    public String getTopHours() {
        return topHours;
    }

    public String getBottomHours() {
        return bottomHours;
    }

    public String getTopMinutes() {
        return topMinutes;
    }

    public String getBottomMinutes() {
        return bottomMinutes;
    }

    public void setSeconds(String seconds) {
        this.seconds = seconds;
    }

    public void setTopHours(String topHours) {
        this.topHours = topHours;
    }

    public void setBottomHours(String bottomHours) {
        this.bottomHours = bottomHours;
    }

    public void setTopMinutes(String topMinutes) {
        this.topMinutes = topMinutes;
    }

    public void setBottomMinutes(String bottomMinutes) {
        this.bottomMinutes = bottomMinutes;
    }
}

A bientôt pour un nouveau #KataOfTheWeek !