4 * License : The MIT License
5 * Copyright(c) 2009 olyutorskii
8 package jp.sfjp.jindolf.config;
10 import java.util.Arrays;
11 import java.util.Collection;
12 import java.util.EnumSet;
13 import java.util.List;
14 import jp.sfjp.jindolf.ResourceManager;
19 * <p>1オプションは複数の別名を持ちうる。
21 * <p>1引数を持つオプションと持たないオプションは区別される。
23 public enum CmdOption {
26 OPT_HELP("-help", "-h", "--help", "-?"),
28 OPT_VERSION("-version"),
30 OPT_BOLDMETAL("-boldMetal"),
32 OPT_GEOMETRY("-geometry"),
34 OPT_VMINFO("-vminfo"),
36 OPT_CONSOLELOG("-consolelog"),
38 OPT_INITFONT("-initfont"),
40 OPT_ANTIALIAS("-antialias"),
42 OPT_FRACTIONAL("-fractional"),
44 OPT_CONFDIR("-confdir"),
46 OPT_NOCONF("-noconfdir"),
50 private static final Collection<CmdOption> OPTS_INDEPENDENT =
59 private static final Collection<CmdOption> OPTS_BOOLEAN =
65 private static final String RES_DIR = "resources";
66 private static final String RES_HELPTEXT = RES_DIR + "/help.txt";
69 private final List<String> nameList;
75 * @param names オプション名の一覧
77 private CmdOption(String ... names){
78 assert names.length > 0;
79 this.nameList = Arrays.asList(names);
85 * ヘルプメッセージ(オプションの説明)を返す。
89 public static String getHelpText(){
90 String helpText = ResourceManager.getTextFile(RES_HELPTEXT);
97 * @param arg 個別のコマンドライン引数
98 * @return 合致したEnum。どれとも合致しなければnull
100 public static CmdOption parseCmdOption(String arg){
101 for(CmdOption option : values()){
102 if(option.matches(arg)) return option;
109 * 任意のオプション文字列がこのオプションに合致するか判定する。
111 * @param option ハイフンの付いたオプション文字列
114 public boolean matches(String option){
115 boolean result = this.nameList.contains(option);
120 * 単体で意味をなすオプションか判定する。
122 * @return 単体で意味をなすならtrue
124 public boolean isIndepOption(){
125 boolean result = OPTS_INDEPENDENT.contains(this);
130 * 真偽指定を一つ必要とするオプションか判定する。
132 * @return 真偽指定を一つ必要とするオプションならtrue
134 public boolean isBooleanOption(){
135 boolean result = OPTS_BOOLEAN.contains(this);
142 * <p>オプション別名が複数指定されている場合は最初のオプション名
147 public String toString(){
148 String result = this.nameList.get(0);