⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 argument.java

📁 纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统
💻 JAVA
字号:
/*
 * $Id: Argument.java,v 1.1 2003/11/25 11:52:57 epr Exp $
 */

package org.jnode.shell.help;

import java.util.List;
import javax.naming.NameNotFoundException;
import org.jnode.shell.ShellUtils;

/**
 * @author qades
 */
public class Argument extends CommandLineElement {

	public static final boolean SINGLE = false;
	public static final boolean MULTI = true;

	private final boolean multi;

	public Argument(String name, String description, boolean multi) {
		super(name, description);
		this.multi = multi;
	}

	public Argument(String name, String description) {
		this(name, description, SINGLE);
	}

	public boolean isMulti() {
		return multi;
	}

	public String format() {
		return "<" + getName() + ">" + (isMulti() ? " ..." : "");
	}

	public void describe(Help help) {
		help.describeArgument(this);
	}

	// Command line completion
	private String[] values = new String[0];
	private boolean satisfied = false;

	public String complete(String partial) {
		// No completion per default
		return partial;
	}

	protected String complete(String partial, List list) {
		if( list.size() == 0 )	// none found
			return partial;

		if( list.size() == 1 )
			return (String)list.get(0) + " ";

		// list matching
		String[] result = (String[]) list.toArray(new String[list.size()/*ToDo: remove this ugly workaround*/]);
		list(result);

		// return the common part, i.e. complete as much as possible
		return common(result);
	}

	protected final void setValue(String value) {
		if (isMulti()) {
			String[] values = new String[this.values.length + 1];
			System.arraycopy(this.values, 0, values, 0, this.values.length);
			values[this.values.length] = value;
			this.values = values;
		} else {
			this.values = new String[] { value };
		}
		setSatisfied(!isMulti());
	}

	public final String getValue(ParsedArguments args) {
		String[] result = getValues(args);
		if( (result == null) || (result.length == 0) )
			return null;
		return result[0];
	}

        public final String[] getValues(ParsedArguments args) {
		return args.getValues(this);
	}

	final String[] getValues() {
		return values;
	}

	protected final void clear() {
		this.values = new String[0];
		setSatisfied(false);
	}

	protected final void setSatisfied(boolean satisfied) {
		this.satisfied = satisfied;
	}

	public final boolean isSatisfied() {
		return satisfied;
	}

	protected String common(String[] items) {
		if (items.length == 0)
			return "";
		String result = items[0];
		for (int i = 1; i < items.length; i++) {
			while (!items[i].startsWith(result)) // shorten the result until it matches
				result = result.substring(0, result.length() - 1);
		}
		return result;
	}

	public void list(String[] items) {
		try {
			ShellUtils.getShellManager().getCurrentShell().list(items);
		} catch (NameNotFoundException ex) {
			// should not happen!
			System.err.println("No list available");
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -