4 * License : The MIT License
5 * Copyright(c) 2009 olyutorskii
8 package jp.sourceforge.jindolf;
10 import java.io.IOException;
11 import java.util.LinkedList;
12 import java.util.List;
17 public enum CmdOption{
20 OPT_HELP("help", "h", "-help", "?"),
22 OPT_VERSION("version"),
24 OPT_BOLDMETAL("boldMetal"),
26 OPT_NOSPLASH("nosplash"),
28 OPT_GEOMETRY("geometry"),
32 OPT_CONSOLELOG("consolelog"),
34 OPT_INITFONT("initfont"),
36 OPT_ANTIALIAS("antialias"),
38 OPT_FRACTIONAL("fractional"),
40 OPT_CONFDIR("confdir"),
42 OPT_NOCONF("noconfdir"),
46 private final List<String> nameList = new LinkedList<String>();
51 * @param names 頭のハイフンを除いたオプション名の一覧
53 private CmdOption(CharSequence ... names){
54 if(names == null) throw new NullPointerException();
55 if(names.length <= 0) throw new IllegalArgumentException();
57 for(CharSequence name : names){
58 if(name == null) throw new NullPointerException();
59 this.nameList.add(name.toString().intern());
68 * @param seq ハイフン付きオプション名
69 * @return 合致したEnum。どれとも合致しなければnull
71 public static CmdOption parseCmdOption(CharSequence seq){
72 for(CmdOption option : values()){
73 if(option.matchHyphened(seq)) return option;
81 * @return 単体で意味をなすならtrue
83 public static boolean isIndepOption(CmdOption option){
101 * 真偽指定を一つ必要とするオプションか判定する。
102 * @param option オプション
103 * @return 真偽指定を一つ必要とするオプションならtrue
105 public static boolean isBooleanOption(CmdOption option){
118 * ヘルプメッセージ(オプションの説明)を返す。
121 public static CharSequence getHelpText(){
122 CharSequence helpText;
125 helpText = Jindolf.loadResourceText("resources/help.txt");
126 }catch(IOException e){
134 * 頭のハイフンを除いたオプション名を返す。
135 * オプション名が複数指定されていた場合は最初のオプション名
139 public String toString(){
140 return this.nameList.get(0);
144 * 頭のハイフンが付いたオプション名を返す。
145 * オプション名が複数指定されていた場合は最初のオプション名
148 public String toHyphened(){
149 return "-" + toString();
153 * 任意のオプション文字列がこのオプションに合致するか判定する。
154 * @param option ハイフンの付いたオプション文字列
157 public boolean matchHyphened(CharSequence option){
158 if(option == null) return false;
160 for(String name : this.nameList){
161 String hyphened = "-" + name;
162 if(hyphened.equals(option.toString())) return true;