KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > core > enums > ShortCodedLabeledEnum


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.core.enums;
18
19 /**
20  * Implementation of LabeledEnum which uses Short as the code type.
21  *
22  * <p>Should almost always be subclassed, but for some simple situations it may be
23  * used directly. Note that you will not be able to use unique type-based functionality
24  * like <code>LabeledEnumResolver.getLabeledEnumSet(type)</code> in this case.
25  *
26  * @author Keith Donald
27  * @since 1.2.2
28  */

29 public class ShortCodedLabeledEnum extends AbstractGenericLabeledEnum {
30
31     /**
32      * The unique code of this enum.
33      */

34     private final Short JavaDoc code;
35
36
37     /**
38      * Create a new ShortCodedLabeledEnum instance.
39      * @param code the short code
40      * @param label the label (can be <code>null</code>)
41      */

42     public ShortCodedLabeledEnum(int code, String JavaDoc label) {
43         super(label);
44         this.code = new Short JavaDoc((short) code);
45     }
46
47     
48     public Comparable JavaDoc getCode() {
49         return code;
50     }
51
52     /**
53      * Return the short code of this LabeledEnum instance.
54      */

55     public short getShortCode() {
56         return ((Short JavaDoc) getCode()).shortValue();
57     }
58
59 }
60
Popular Tags