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

de.undercouch.citeproc.ListItemDataProvider Maven / Gradle / Ivy

package de.undercouch.citeproc;

import de.undercouch.citeproc.csl.CSLItemData;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Provides item data from a given list
 * @author Michel Kraemer
 */
public class ListItemDataProvider implements ItemDataProvider {
    /**
     * The items that this provider holds
     */
    protected final Map items;

    /**
     * Creates a data provider that serves items from the given array
     * @param items the items to serve
     */
    public ListItemDataProvider(CSLItemData... items) {
        this(Arrays.asList(items));
    }

    /**
     * Creates a data provider that serves items from the given list
     * @param items the items to serve
     */
    public ListItemDataProvider(List items) {
        Map is = new LinkedHashMap<>();
        for (CSLItemData i : items) {
            is.put(i.getId(), i);
        }
        this.items = is;
    }

    @Override
    public CSLItemData retrieveItem(String id) {
        return items.get(id);
    }

    @Override
    public Collection getIds() {
        return Collections.unmodifiableSet(items.keySet());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy