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

hudson.search.CollectionSearchIndex Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2009 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * 
 *    Kohsuke Kawaguchi
 *
 *
 *******************************************************************************/ 

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