@@ -0,0 +1,2680 @@
+package ru.apermyakov.testtask;%0A%0Aimport java.util.Arrays;%0Aimport java.util.stream.Collectors;%0A%0A/**%0A* Class for check move of figure.%0A*%0A* @author apermyakov%0A* @version 1.0%0A* @since 23.10.2017%0A*/%0Apublic class Checker %7B%0A%0A%09/**%0A%09* Initial source cell of figure.%0A%09*/%0A    private Cell source;%0A%0A%09/**%0A%09* Initial destination cell of figure.%0A%09*/%0A    private Cell dist;%0A%0A%09/**%0A%09* Initial array of exist figures.%0A%09*/%0A    private Figure%5B%5D existFigures;%0A%0A%09/**%0A%09* Initial figure.%0A%09*/%0A    private Figure figure;%0A%0A%09/**%0A%09* Initial index of figure in array of all figures.%0A%09*/%0A    private int index;%0A%0A%09/**%0A%09* Design checker.%0A%09*%0A%09* @param existFigures array of exist figures%0A%09* @param source source cell of figure%0A%09* @param dist destination cell of figure%0A%09*/%0A    public Checker(Figure%5B%5D existFigures, Cell source, Cell dist) %7B%0A        this.existFigures = existFigures;%0A        this.source = source;%0A        this.dist = dist;%0A    %7D%0A%0A%09/**%0A     * Method for check existence of figure.%0A     *%0A     * @return exist or not%0A     * @since 23.10.2017%0A     */%0A    public boolean checkFigure() %7B%0A        boolean result = Arrays.stream(this.existFigures).anyMatch(i -%3E i.position.getX() == this.source.getX() && i.position.getY() == this.source.getY());%0A        if (result) %7B //Check cell existence%0A            this.figure = Arrays.stream(this.existFigures).filter(i -%3E i.position.getX() == this.source.getX() && i.position.getY() == this.source.getY()).findFirst().get();%0A            this.index = Arrays.stream(this.existFigures).collect(Collectors.toList()).indexOf(this.figure);%0A        %7D%0A        return result;%0A    %7D%0A%0A%09/**%0A     * Method for check possibility of figure move.%0A     *%0A     * @return possible or not%0A     * @since 23.10.2017%0A     */%0A    public boolean checkMove() %7B%0A        return Arrays.stream(this.figure.possibleMoves()).anyMatch(i -%3E this.dist.getX() == i.getX() && this.dist.getY() == i.getY());%0A    %7D%0A%0A%09/**%0A     * Method for check way of figure.%0A     *%0A     * @return free or not%0A     * @since 23.10.2017%0A     */%0A    public boolean checkWay() %7B%0A        boolean result = Arrays.stream(this.figure.way(this.dist)).noneMatch(i -%3E Arrays.stream(this.existFigures).anyMatch(n -%3E i.getX() == n.position.getX() && i.getY() == n.position.getY()));%0A        return (result %7C%7C figure.getClass().toString().equals(%22class ru.apermyakov.testtask.Horse%22));%0A    %7D%0A%0A%09/**%0A     * Method for get index of figure.%0A     *%0A     * @return figure's index%0A     * @since 23.10.2017%0A     */%0A    public int getIndex() %7B%0A        return this.index;%0A    %7D%0A%0A%09/**%0A     * Method for get figure.%0A     *%0A     * @return figure%0A     * @since 23.10.2017%0A     */%0A    public Figure getFigure() %7B%0A        return this.figure;%0A    %7D%0A%7D%0A

Task 24257