package de.duehl.vocabulary.japanese.logic.symbol.kanji.test;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import de.duehl.basics.text.Text;
import de.duehl.vocabulary.japanese.logic.symbol.kanji.strokes.extract.AllFilesKanjiVgSvgPathesExtractor;
import de.duehl.vocabulary.japanese.logic.symbol.kanji.strokes.extract.data.PathWithStrokeNumber;
import de.duehl.vocabulary.japanese.logic.symbol.kanji.strokes.extract.data.PathesWithStrokeNumbers;

public class PathCommandsInAllKanjiVgSvgFilesSearcher {

    private final String dir;

    private Set<String> commands;

    public PathCommandsInAllKanjiVgSvgFilesSearcher(String dir) {
        this.dir = dir;
    }

    public void search() {
        AllFilesKanjiVgSvgPathesExtractor extractor = new AllFilesKanjiVgSvgPathesExtractor(dir);
        extractor.extract();
        List<PathesWithStrokeNumbers> pathesWithStrokeNumbersList =
                extractor.getPathesWithStrokeNumbersList();

        commands = new HashSet<>();
        for (PathesWithStrokeNumbers pathesWithStrokeNumbers : pathesWithStrokeNumbersList) {
            for (PathWithStrokeNumber path : pathesWithStrokeNumbers.getPathes()) {
                collectFromPath(path.getPath());
            }
        }

        System.out.println("Gefundene Befehle:");
        for (String command : commands) {
            System.out.println("    " + command);
        }
    }

    private void collectFromPath(String path) {
        for (String character : Text.textToCharactersListForComplexUtf8(path)) {
            if (Text.MIXED_CHARS_LIST.contains(character)) {
                commands.add(character);
            }
        }
    }

    public static void main(String[] args) {
        String dir = "c:\\TEMP\\kanjivg\\kanji";
        PathCommandsInAllKanjiVgSvgFilesSearcher searcher =
                new PathCommandsInAllKanjiVgSvgFilesSearcher(dir);
        searcher.search();
    }

}
