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

hudson.search.CollectionSearchIndex Maven / Gradle / Ivy

package hudson.search;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * {@link SearchIndex} built on a {@link Map}.
 * 
 * @author Kohsuke Kawaguchi
 */
public abstract class CollectionSearchIndex implements SearchIndex {
    /**
     * Gets a single item that exactly matches the given key.
     */
    protected abstract SearchItem get(String key);

    /**
     * Returns all items in the map.
     * The collection can include null items.
     */
    protected abstract Collection all();

    public void find(String token, List result) {
        SearchItem p = get(token);
        if(p!=null)
            result.add(p);
    }

    public void suggest(String token, List result) {
        Collection items = all();
        if(items==null)     return;
        for (SMT o : items) {
            if(o!=null && getName(o).contains(token))
                result.add(o);
        }
    }

    protected String getName(SMT o) {
        return o.getDisplayName();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy