class BaselineTopologyHistory implements Serializable {
    /** */
    private static final long serialVersionUID = 0L;

    /** */
    private static final String METASTORE_BLT_HIST_PREFIX = "bltHist-";

    /** */
    private final Queue<BaselineTopologyHistoryItem> bufferedForStore =
        new ConcurrentLinkedQueue<>();

    /** */
    private final List<BaselineTopologyHistoryItem> hist = new ArrayList<>();

    /** */
    void restoreHistory(ReadOnlyMetastorage metastorage, int lastId) throws IgniteCheckedException {<FILL_FUNCTION_BODY>}

    /** */
    BaselineTopologyHistory tailFrom(int id) {
        BaselineTopologyHistory tail = new BaselineTopologyHistory();

        for (BaselineTopologyHistoryItem item : hist) {
            if (item.id() >= id)
                tail.hist.add(item);
        }

        return tail;
    }

    /** */
    void writeHistoryItem(ReadWriteMetastorage metastorage, BaselineTopologyHistoryItem histItem)
        throws IgniteCheckedException {
        if (histItem == null)
            return;

        hist.add(histItem);

        metastorage.write(METASTORE_BLT_HIST_PREFIX + histItem.id(), histItem);
    }

    /** */
    void removeHistory(ReadWriteMetastorage metastorage) throws IgniteCheckedException {
        if (hist.isEmpty())
            return;

        for (BaselineTopologyHistoryItem histItem : hist)
            metastorage.remove(METASTORE_BLT_HIST_PREFIX + histItem.id());

        hist.clear();
    }

    /** */
    boolean isCompatibleWith(BaselineTopology blt) {
        BaselineTopologyHistoryItem histBlt = hist.get(blt.id());

        return histBlt.branchingHistory().contains(blt.branchingPointHash());
    }

    /** */
    boolean isEmpty() {
        return hist.isEmpty();
    }

    /** */
    void bufferHistoryItemForStore(BaselineTopologyHistoryItem histItem) {
        hist.add(histItem);

        bufferedForStore.add(histItem);
    }

    /** */
    public List<BaselineTopologyHistoryItem> history() {
        return Collections.unmodifiableList(hist);
    }

    /** */
    void flushHistoryItems(ReadWriteMetastorage metastorage) throws IgniteCheckedException {
        while (!bufferedForStore.isEmpty()) {
            BaselineTopologyHistoryItem item = bufferedForStore.remove();

            metastorage.write(METASTORE_BLT_HIST_PREFIX + item.id(), item);
        }
    }
}

        for (int i = 0; i < lastId; i++) {
            BaselineTopologyHistoryItem histItem = (BaselineTopologyHistoryItem)metastorage.read(METASTORE_BLT_HIST_PREFIX + i);

            if (histItem != null)
                hist.add(histItem);
            else
                throw new IgniteCheckedException("Restoring of BaselineTopology history has failed, " +
                    "expected history item not found for id=" + i
                );
        }
    
<no_super_class>