package org.forkalsrud.album.exif;

import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;


public class SearchResults extends EntryWithChildren<SearchEntry> {

    protected HashMap<File, SearchEntry> dupes = new HashMap<File, SearchEntry>();
    Comparator<SearchEntry> sort = (e1, e2) -> Integer.valueOf(e2.score).compareTo(e1.score);


    protected SearchResults(DirectoryEntry root) {
        super(root);
        this.next = root.next;
        this.prev = root.prev;
        this.parent = root.parent;
    }

    public void addMatch(Entry entry) {

        File path = entry.getPath();
        SearchEntry existing = dupes.get(path);
        if (existing == null) {
            existing = new SearchEntry(this, entry);
            dupes.put(path, existing);
            children.add(existing);
        } else {
            existing.addScore();
        }
    }

    public void sort() {
        Collections.sort(children, sort);
    }

    

}
