KickJava   Java API By Example, From Geeks To Geeks.

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


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 String 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
26  * functionality like <code>LabeledEnumResolver.getLabeledEnumSet(type) in this case.
27  *
28  * @author Keith Donald
29  * @since 1.2.2
30  * @see org.springframework.core.enums.LabeledEnumResolver#getLabeledEnumSet(Class)
31  */

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

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

45     public StringCodedLabeledEnum(String JavaDoc code, String JavaDoc label) {
46         super(label);
47         Assert.hasText(code, "'code' must not be empty");
48         this.code = code;
49     }
50
51
52     public Comparable JavaDoc getCode() {
53         return code;
54     }
55
56     /**
57      * Return the String code of this LabeledEnum instance.
58      */

59     public String JavaDoc getStringCode() {
60         return (String JavaDoc) getCode();
61     }
62
63 }
64
Popular Tags