All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wikibrain.download.DumpLinkCluster Maven / Gradle / Ivy

There is a newer version: 0.9.1
Show newest version
package org.wikibrain.download;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.wikibrain.core.cmd.FileMatcher;
import org.wikibrain.core.lang.Language;

import java.util.*;

/**
 *
 * This class wraps a complex map of DumpLinkInfo, and provides iteration by language
 * so that during the download process, downloads proceed one language at a time.
 * The Iterator returns Multimaps of LinkMatchers mapped to DumpLinkInfo so that
 * the downloads can be additionally clustered by FileMatcher.
 *
 * @author Ari Weiland
 *
 */
public class DumpLinkCluster implements Iterable {

    private final Map> links = new HashMap>();

    public DumpLinkCluster() {}

    public void add(DumpLinkInfo link) {
        Language language = link.getLanguage();
        if (!links.containsKey(language)) {
            Multimap temp = HashMultimap.create();
            links.put(language, temp);
        }
        links.get(language).put(link.getLinkMatcher(), link);
    }

    public Multimap get(Language language) {
        return links.get(language);
    }

    public int size() {
        int counter = 0;
        for (Language language : this) {
            counter += this.get(language).size();
        }
        return counter;
    }

    @Override
    public Iterator iterator() {
        return links.keySet().iterator();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy