package de.softwareforge.pgpsigner.jline; /* * Copyright (C) 2007 Henning P. Schmiedehausen * * See the NOTICE file distributed with this work for additional * information * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. * */ import java.util.List; import java.util.Set; import de.softwareforge.pgpsigner.key.KeyId; /** * A generic key completor that works on a set of KeyId objects. * * @author <a href="mailto:henning@schmiedehausen.org">Henning P. Schmiedehausen</a> * @version $Id$ */ public abstract class AbstractKeyCompletor { @SuppressWarnings("unchecked") protected int complete(final Set<KeyId> keySet, final String buffer, final int cursor, final List candidates) { String start = (buffer == null) ? "" : buffer; for (KeyId key : keySet) { if (key.toString().startsWith(start)) { candidates.add(key.toString()); } } if (candidates.size() == 1) { candidates.set(0, ((String) candidates.get(0)) + " "); } // the index of the completion is always from the beginning of // the buffer. return (candidates.size() == 0) ? (-1) : 0; } }