OSDN Git Service

pmd-plugin 3.0.1(PMD 5.0.2) 対応
[mikutoga/TogaGem.git] / src / main / java / jp / sfjp / mikutoga / pmd / MorphType.java
1 /*
2  * morph type
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.pmd;
9
10 import java.util.List;
11 import java.util.Locale;
12 import java.util.ResourceBundle;
13
14 /**
15  * モーフ種別。
16  * <ul>
17  * <li>0:base
18  * <li>1:まゆ
19  * <li>2:目
20  * <li>3:リップ
21  * <li>4:その他
22  * </ul>
23  */
24 public enum MorphType {
25
26     /** base。 */
27     BASE(0x00),
28     /** まゆ。 */
29     EYEBROW(0x01),
30     /** 目。 */
31     EYE(0x02),
32     /** リップ。 */
33     LIP(0x03),
34     /** その他。 */
35     EXTRA(0x04),
36     ;
37
38     private static final ResourceBundle.Control NOFALLBACK;
39     private static final String FAMILY_NAME =
40             "jp.sfjp.mikutoga.pmd.resources.MorphTypeName";
41
42     static{
43         List<String> rbforms = ResourceBundle.Control.FORMAT_DEFAULT;
44         NOFALLBACK = ResourceBundle.Control.getNoFallbackControl(rbforms);
45
46         String name = BASE.getClass().getPackage().getName();
47         assert FAMILY_NAME.startsWith(name);
48     }
49
50
51     private final byte encoded;
52
53     /**
54      * コンストラクタ。
55      * @param code 符号化int値
56      */
57     private MorphType(int code){
58         this((byte)code);
59         return;
60     }
61
62     /**
63      * コンストラクタ。
64      * @param code 符号化byte値
65      */
66     private MorphType(byte code){
67         this.encoded = code;
68         return;
69     }
70
71     /**
72      * byte値からデコードする。
73      * @param code byte値
74      * @return デコードされた列挙子。該当するものがなければnull
75      */
76     public static MorphType decode(byte code){
77         MorphType result = null;
78
79         for(MorphType type : values()){
80             if(type.encode() == code){
81                 result = type;
82                 break;
83             }
84         }
85
86         return result;
87     }
88
89     /**
90      * byte値にエンコードする。
91      * @return byte値
92      */
93     public byte encode(){
94         return this.encoded;
95     }
96
97     /**
98      * デフォルトロケールでの表示名を返す。
99      * @return 表示名
100      */
101     public String getGuiName(){
102         Locale locale = Locale.getDefault();
103         assert locale != null;
104         return getGuiName(locale);
105     }
106
107     /**
108      * ロケールに準じた表示名を返す。
109      * @param locale ロケール。nullならデフォルトロケールと解釈される。
110      * @return 表示名
111      */
112     public String getGuiName(Locale locale){
113         if(locale == null) return getGuiName();
114         ResourceBundle rb =
115                 ResourceBundle.getBundle(FAMILY_NAME, locale, NOFALLBACK);
116         String key = name();
117         String result = rb.getString(key);
118         return result;
119     }
120
121     /**
122      * モーフ種別がbaseか否か判定する。
123      * @return baseならtrue
124      */
125     public boolean isBase(){
126         if(this == BASE) return true;
127         return false;
128     }
129
130 }