package ru.samsu.mj.collection;

import ru.samsu.mj.board.Board;

import java.util.Collection;

public class SortedBoardCollection {
    static SortedBoardCollection valueOf(Collection<Board> boardCollection) {
        throw new UnsupportedOperationException();
    }

    public Board theLeast() {
        throw new UnsupportedOperationException();
    }

    public Board theMost() {
        throw new UnsupportedOperationException();
    }

    public BoardCollection closestAbove(Board board) {
        throw new UnsupportedOperationException();
    }
}

@@ -62,378 +62,2478 @@
 rd;%0A
-%0Aimport java.util.Collection;%0A%0Apublic class SortedBoardCollection %7B%0A    static SortedBoardCollection valueOf(Collection%3CBoard%3E boardCollection) %7B%0A        throw new UnsupportedOperationException();%0A    %7D%0A%0A    public Board theLeast() %7B%0A        throw new UnsupportedOperationException();%0A    %7D%0A%0A    public 
+import ru.samsu.mj.board.PartialComparison;%0A%0Aimport java.util.*;%0A%0Apublic class SortedBoardCollection %7B%0A    private final Map%3CBoard, BoardCollection%3E MAP;%0A    private final Board THE_LEAST_BOARD;%0A%0A    private SortedBoardCollection(Map%3CBoard, BoardCollection%3E map, Board theLeastBoard) %7B%0A        MAP = map;%0A        THE_LEAST_BOARD = theLeastBoard;%0A    %7D%0A%0A    static SortedBoardCollection valueOf(Collection%3CBoard%3E boardCollection) %7B%0A        Map%3CBoard, BoardCollection%3E map = new HashMap%3C%3E();%0A        Board theLeastBoard = null;%0A        Set%3CBoard%3E buffer = new HashSet%3C%3E();%0A%0A        // Initialization.%0A        for (Board board : boardCollection)%0A            if (board.isEmpty())%0A                theLeastBoard = board;%0A            else%0A                buffer.add(board);%0A%0A        // Sorting itself.%0A        Set%3CBoard%3E lastLayer = Collections.singleton(theLeastBoard);%0A        while (!buffer.isEmpty()) %7B%0A            Set%3CBoard%3E nextLayer = nextLayer(buffer);%0A            injectMapping(map, lastLayer, nextLayer);%0A            buffer.removeAll(nextLayer);%0A            lastLayer = nextLayer;%0A        %7D%0A%0A        return new SortedBoardCollection(map, theLeastBoard);%0A    %7D%0A%0A    private static void injectMapping(Map%3CBoard, BoardCollection%3E map, Set%3CBoard%3E lastLayer, Set%3CBoard%3E nextLayer) %7B%0A        for (Board oneBoard : lastLayer) %7B%0A            Set%3CBoard%3E imageSet = new HashSet%3C%3E();// and %60oneBoard%60 is its key%0A            for (Board anotherBoard : nextLayer)%0A                if (oneBoard.partiallyCompare(anotherBoard) == PartialComparison.LESS)%0A                    imageSet.add(anotherBoard);%0A            map.put(oneBoard, BoardCollection.valueOf(imageSet));%0A        %7D%0A    %7D%0A%0A    /**%0A     * @param buffer --- the set of %60Board%60s to choose from.%0A     * @return the subset of %60
 Board
+%60s
  th
-eMost() %7B%0A        throw new UnsupportedOperationException()
+at are no greater than any other one in %60buffer%60.%0A     */%0A    private static Set%3CBoard%3E nextLayer(Set%3CBoard%3E buffer) %7B%0A        Set%3CBoard%3E result = new HashSet%3C%3E();%0A        for (Board oneBoard : buffer) %7B%0A            boolean isGreaterThanSome = false;%0A            for (Board anotherBoard : buffer) %7B%0A                if (oneBoard.partiallyCompare(anotherBoard) == PartialComparison.GREATER) %7B%0A                    isGreaterThanSome = true;%0A                    break;%0A                %7D%0A            %7D%0A            if (isGreaterThanSome)%0A                continue;%0A            result.add(oneBoard);%0A        %7D%0A        return result;%0A    %7D%0A%0A    public Board theLeast() %7B%0A        return THE_LEAST_BOARD
 ;%0A  
@@ -2604,48 +2604,28 @@
     
-throw new UnsupportedOperationException(
+return MAP.get(board
 );%0A 

Implement sorting algorithm.