📄 enumeratedtype.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.wicket.util.lang;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Map;import org.apache.wicket.util.concurrent.ConcurrentHashMap;import org.apache.wicket.util.string.StringValue;/** * A base class for defining enumerated types. Since this class extends StringValue, every * enumerated type subclass is a StringValue that can be manipulated, converted and displayed in * useful ways. In addition to constructing a type with the given name, lists are kept of all * enumeration values by subclass. The list of available values in the enumeration represented by a * given subclass can be retrieved by calling getValues(Class). * * @author Jonathan Locke */public abstract class EnumeratedType extends StringValue{ /** * */ private static final long serialVersionUID = 1L; /** Map of type values by class */ private static final Map valueListByClass = new ConcurrentHashMap(); /** * Constructor. * * @param name * Name of this enumerated type value */ public EnumeratedType(final String name) { super(name); // Add this object to the list of values for our subclass getValues(getClass()).add(this); } /** * Gets the enumerated type values for a given subclass of EnumeratedType. * * @param c * The enumerated type subclass to get values for * @return List of all values of the given subclass */ public static List getValues(final Class c) { // Get values for class List valueList = (List)valueListByClass.get(c.getName()); // If no list exists if (valueList == null) { // create lazily valueList = new ArrayList(); valueListByClass.put(c.getName(), valueList); } return valueList; } /** * Method to ensure that == works after deserialization * * @return object instance * @throws java.io.ObjectStreamException */ public Object readResolve() throws java.io.ObjectStreamException { EnumeratedType result = this; List values = getValues(getClass()); if (values != null) { for (Iterator i = values.iterator(); i.hasNext();) { EnumeratedType type = (EnumeratedType)i.next(); if (type.toString() != null && type.toString().equals(this.toString())) { result = type; break; } } } return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -