OSDN Git Service

modify implicit/explicit modifiers.
[mikutoga/TogaGem.git] / src / main / java / jp / sfjp / mikutoga / pmd / RigidShapeType.java
1 /*
2  * rigid shape 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>0x00:球
18  * <li>0x01:箱
19  * <li>0x02:カプセル
20  * </ul>
21  */
22 public enum RigidShapeType {
23
24     /** 球。 */
25     SPHERE(0x00),
26     /** 箱。 */
27     BOX(0x01),
28     /** カプセル。 */
29     CAPSULE(0x02),
30     ;
31
32     private static final ResourceBundle.Control NOFALLBACK;
33     private static final String FAMILY_NAME =
34             "jp.sfjp.mikutoga.pmd.resources.RigidShapeTypeName";
35
36     static{
37         List<String> rbforms = ResourceBundle.Control.FORMAT_DEFAULT;
38         NOFALLBACK = ResourceBundle.Control.getNoFallbackControl(rbforms);
39
40         String name = SPHERE.getClass().getPackage().getName();
41         assert FAMILY_NAME.startsWith(name);
42     }
43
44
45     private final byte encoded;
46
47     /**
48      * コンストラクタ。
49      * @param code 符号化int値
50      */
51     RigidShapeType(int code){
52         this((byte)code);
53         return;
54     }
55
56     /**
57      * コンストラクタ。
58      * @param code 符号化byte値
59      */
60     RigidShapeType(byte code){
61         this.encoded = code;
62         return;
63     }
64
65     /**
66      * byte値からデコードする。
67      * @param code byte値
68      * @return デコードされた列挙子。該当するものがなければnull
69      */
70     public static RigidShapeType decode(byte code){
71         RigidShapeType result = null;
72
73         for(RigidShapeType type : values()){
74             if(type.encode() == code){
75                 result = type;
76                 break;
77             }
78         }
79
80         return result;
81     }
82
83     /**
84      * byte値にエンコードする。
85      * @return byte値
86      */
87     public byte encode(){
88         return this.encoded;
89     }
90
91     /**
92      * デフォルトロケールでの表示名を返す。
93      * @return 表示名
94      */
95     public String getGuiName(){
96         Locale locale = Locale.getDefault();
97         assert locale != null;
98         return getGuiName(locale);
99     }
100
101     /**
102      * ロケールに準じた表示名を返す。
103      * @param locale ロケール。nullならデフォルトロケールと解釈される。
104      * @return 表示名
105      */
106     public String getGuiName(Locale locale){
107         if(locale == null) return getGuiName();
108         ResourceBundle rb =
109                 ResourceBundle.getBundle(FAMILY_NAME, locale, NOFALLBACK);
110         String key = name();
111         String result = rb.getString(key);
112         return result;
113     }
114
115 }