KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.springframework.util.Assert;
20
21 /**
22  * Implementation of LabeledEnum which uses a letter as the code type.
23  *
24  * <p>Should almost always be subclassed, but for some simple situations it may be
25  * used directly. Note that you will not be able to use unique type-based functionality
26  * like <code>LabeledEnumResolver.getLabeledEnumSet(type)</code> in this case.
27  *
28  * @author Keith Donald
29  * @since 1.2.2
30  */

31 public class LetterCodedLabeledEnum extends AbstractGenericLabeledEnum {
32
33     /**
34      * The unique code of this enum.
35      */

36     private final Character JavaDoc code;
37
38
39     /**
40      * Create a new LetterCodedLabeledEnum instance.
41      * @param code the letter code
42      * @param label the label (can be <code>null</code>)
43      */

44     public LetterCodedLabeledEnum(char code, String JavaDoc label) {
45         super(label);
46         Assert.isTrue(Character.isLetter(code),
47                 "The code '" + code + "' is invalid: it must be a letter");
48         this.code = new Character JavaDoc(code);
49     }
50
51     
52     public Comparable JavaDoc getCode() {
53         return code;
54     }
55
56     /**
57      * Return the letter code of this LabeledEnum instance.
58      */

59     public char getLetterCode() {
60         return ((Character JavaDoc) getCode()).charValue();
61     }
62
63 }
64
Popular Tags