From ebb3d32ea8086d1314c737046f308ddab5244a33 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 19 Mar 2013 23:14:55 +0100 Subject: [PATCH] Removed deprecated core.enums package --- .../AbstractCachingLabeledEnumResolver.java | 139 ------------------ .../enums/AbstractGenericLabeledEnum.java | 55 ------- .../core/enums/AbstractLabeledEnum.java | 77 ---------- .../core/enums/LabeledEnum.java | 96 ------------ .../core/enums/LabeledEnumResolver.java | 71 --------- .../core/enums/LetterCodedLabeledEnum.java | 66 --------- .../core/enums/ShortCodedLabeledEnum.java | 63 -------- .../core/enums/StaticLabeledEnum.java | 103 ------------- .../core/enums/StaticLabeledEnumResolver.java | 75 ---------- .../core/enums/StringCodedLabeledEnum.java | 67 --------- .../core/enums/package-info.java | 9 -- 11 files changed, 821 deletions(-) delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/AbstractCachingLabeledEnumResolver.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/AbstractGenericLabeledEnum.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/AbstractLabeledEnum.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/LabeledEnum.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/LabeledEnumResolver.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/LetterCodedLabeledEnum.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/ShortCodedLabeledEnum.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/StaticLabeledEnum.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/StaticLabeledEnumResolver.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/StringCodedLabeledEnum.java delete mode 100644 spring-core/src/main/java/org/springframework/core/enums/package-info.java diff --git a/spring-core/src/main/java/org/springframework/core/enums/AbstractCachingLabeledEnumResolver.java b/spring-core/src/main/java/org/springframework/core/enums/AbstractCachingLabeledEnumResolver.java deleted file mode 100644 index 4a278f92eb..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/AbstractCachingLabeledEnumResolver.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.util.Assert; -import org.springframework.util.CachingMapDecorator; -import org.springframework.util.ClassUtils; - -/** - * Abstract base class for {@link LabeledEnumResolver} implementations, - * caching all retrieved {@link LabeledEnum} instances. - * - *

Subclasses need to implement the template method - * {@link #findLabeledEnums(Class)}. - * - * @author Keith Donald - * @author Juergen Hoeller - * @since 1.2.2 - * @see #findLabeledEnums(Class) - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -public abstract class AbstractCachingLabeledEnumResolver implements LabeledEnumResolver { - - protected transient final Log logger = LogFactory.getLog(getClass()); - - private final LabeledEnumCache labeledEnumCache = new LabeledEnumCache(); - - - public Set getLabeledEnumSet(Class type) throws IllegalArgumentException { - return new TreeSet(getLabeledEnumMap(type).values()); - } - - public Map getLabeledEnumMap(Class type) throws IllegalArgumentException { - Assert.notNull(type, "No type specified"); - return this.labeledEnumCache.get(type); - } - - public LabeledEnum getLabeledEnumByCode(Class type, Comparable code) throws IllegalArgumentException { - Assert.notNull(code, "No enum code specified"); - Map typeEnums = getLabeledEnumMap(type); - LabeledEnum codedEnum = typeEnums.get(code); - if (codedEnum == null) { - throw new IllegalArgumentException( - "No enumeration with code '" + code + "'" + " of type [" + type.getName() + - "] exists: this is likely a configuration error. " + - "Make sure the code value matches a valid instance's code property!"); - } - return codedEnum; - } - - public LabeledEnum getLabeledEnumByLabel(Class type, String label) throws IllegalArgumentException { - Map typeEnums = getLabeledEnumMap(type); - for (LabeledEnum value : typeEnums.values()) { - if (value.getLabel().equalsIgnoreCase(label)) { - return value; - } - } - throw new IllegalArgumentException( - "No enumeration with label '" + label + "' of type [" + type + - "] exists: this is likely a configuration error. " + - "Make sure the label string matches a valid instance's label property!"); - } - - - /** - * Template method to be implemented by subclasses. - * Supposed to find all LabeledEnum instances for the given type. - * @param type the enum type - * @return the Set of LabeledEnum instances - * @see org.springframework.core.enums.LabeledEnum - */ - protected abstract Set findLabeledEnums(Class type); - - - /** - * Inner cache class that implements lazy building of LabeledEnum Maps. - */ - @SuppressWarnings("serial") - private class LabeledEnumCache extends CachingMapDecorator> { - - public LabeledEnumCache() { - super(true); - } - - @Override - protected Map create(Class key) { - Set typeEnums = findLabeledEnums(key); - if (typeEnums == null || typeEnums.isEmpty()) { - throw new IllegalArgumentException( - "Unsupported labeled enumeration type '" + key + "': " + - "make sure you've properly defined this enumeration! " + - "If it is static, are the class and its fields public/static/final?"); - } - Map typeEnumMap = new HashMap(typeEnums.size()); - for (LabeledEnum labeledEnum : typeEnums) { - typeEnumMap.put(labeledEnum.getCode(), labeledEnum); - } - return Collections.unmodifiableMap(typeEnumMap); - } - - @Override - protected boolean useWeakValue(Class key, Map value) { - if (!ClassUtils.isCacheSafe(key, AbstractCachingLabeledEnumResolver.this.getClass().getClassLoader())) { - if (logger != null && logger.isDebugEnabled()) { - logger.debug("Not strongly caching class [" + key.getName() + "] because it is not cache-safe"); - } - return true; - } - else { - return false; - } - } - } - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/AbstractGenericLabeledEnum.java b/spring-core/src/main/java/org/springframework/core/enums/AbstractGenericLabeledEnum.java deleted file mode 100644 index cee9535cee..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/AbstractGenericLabeledEnum.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -/** - * Base class for labeled enum instances that aren't static. - * - * @author Keith Donald - * @since 1.2.6 - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -@SuppressWarnings("serial") -public abstract class AbstractGenericLabeledEnum extends AbstractLabeledEnum { - - /** - * A descriptive label for the enum. - */ - private final String label; - - - /** - * Create a new StaticLabeledEnum instance. - * @param label the label; if {@code null}), the enum's code - * will be used as label - */ - protected AbstractGenericLabeledEnum(String label) { - this.label = label; - } - - - public String getLabel() { - if (this.label != null) { - return label; - } - else { - return getCode().toString(); - } - } - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/AbstractLabeledEnum.java b/spring-core/src/main/java/org/springframework/core/enums/AbstractLabeledEnum.java deleted file mode 100644 index 3c2860f74b..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/AbstractLabeledEnum.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -/** - * Abstract base superclass for LabeledEnum implementations. - * - * @author Keith Donald - * @author Juergen Hoeller - * @author Sam Brannen - * @since 1.2.2 - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -@SuppressWarnings("serial") -public abstract class AbstractLabeledEnum implements LabeledEnum { - - /** - * Create a new AbstractLabeledEnum instance. - */ - protected AbstractLabeledEnum() { - } - - public Class getType() { - // Could be coded as getClass().isAnonymousClass() on JDK 1.5 - boolean isAnonymous = (getClass().getDeclaringClass() == null && getClass().getName().indexOf('$') != -1); - return (isAnonymous ? getClass().getSuperclass() : getClass()); - } - - public int compareTo(Object obj) { - if (!(obj instanceof LabeledEnum)) { - throw new ClassCastException("You may only compare LabeledEnums"); - } - LabeledEnum that = (LabeledEnum) obj; - if (!this.getType().equals(that.getType())) { - throw new ClassCastException("You may only compare LabeledEnums of the same type"); - } - return this.getCode().compareTo(that.getCode()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof LabeledEnum)) { - return false; - } - LabeledEnum other = (LabeledEnum) obj; - return (this.getType().equals(other.getType()) && this.getCode().equals(other.getCode())); - } - - @Override - public int hashCode() { - return (getType().hashCode() * 29 + getCode().hashCode()); - } - - @Override - public String toString() { - return getLabel(); - } - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/LabeledEnum.java b/spring-core/src/main/java/org/springframework/core/enums/LabeledEnum.java deleted file mode 100644 index dc2325bfac..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/LabeledEnum.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -import java.io.Serializable; -import java.util.Comparator; - -import org.springframework.util.comparator.CompoundComparator; -import org.springframework.util.comparator.NullSafeComparator; - -/** - * An interface for objects that represent a labeled enumeration. - * Each such enum instance has the following characteristics: - * - *

- * - * @author Keith Donald - * @since 1.2.2 - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -public interface LabeledEnum extends Comparable, Serializable { - - /** - * Return this enumeration's type. - */ - Class getType(); - - /** - * Return this enumeration's code. - *

Each code should be unique within enumerations of the same type. - */ - Comparable getCode(); - - /** - * Return a descriptive, optional label. - */ - String getLabel(); - - - // Constants for standard enum ordering (Comparator implementations) - - /** - * Shared Comparator instance that sorts enumerations by {@code CODE_ORDER}. - */ - Comparator CODE_ORDER = new Comparator() { - public int compare(Object o1, Object o2) { - Comparable c1 = ((LabeledEnum) o1).getCode(); - Comparable c2 = ((LabeledEnum) o2).getCode(); - return c1.compareTo(c2); - } - }; - - /** - * Shared Comparator instance that sorts enumerations by {@code LABEL_ORDER}. - */ - Comparator LABEL_ORDER = new Comparator() { - public int compare(Object o1, Object o2) { - LabeledEnum e1 = (LabeledEnum) o1; - LabeledEnum e2 = (LabeledEnum) o2; - Comparator comp = new NullSafeComparator(String.CASE_INSENSITIVE_ORDER, true); - return comp.compare(e1.getLabel(), e2.getLabel()); - } - }; - - /** - * Shared Comparator instance that sorts enumerations by {@code LABEL_ORDER}, - * then {@code CODE_ORDER}. - */ - Comparator DEFAULT_ORDER = - new CompoundComparator(new Comparator[] { LABEL_ORDER, CODE_ORDER }); - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/LabeledEnumResolver.java b/spring-core/src/main/java/org/springframework/core/enums/LabeledEnumResolver.java deleted file mode 100644 index 7b374a70b0..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/LabeledEnumResolver.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -import java.util.Map; -import java.util.Set; - -/** - * Interface for looking up {@code LabeledEnum} instances. - * - * @author Keith Donald - * @author Juergen Hoeller - * @since 1.2.2 - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -public interface LabeledEnumResolver { - - /** - * Return a set of enumerations of a particular type. Each element in the - * set should be an instance of LabeledEnum. - * @param type the enum type - * @return a set of localized enumeration instances for the provided type - * @throws IllegalArgumentException if the type is not supported - */ - public Set getLabeledEnumSet(Class type) throws IllegalArgumentException; - - /** - * Return a map of enumerations of a particular type. Each element in the - * map should be a key/value pair, where the key is the enum code, and the - * value is the {@code LabeledEnum} instance. - * @param type the enum type - * @return a Map of localized enumeration instances, - * with enum code as key and {@code LabeledEnum} instance as value - * @throws IllegalArgumentException if the type is not supported - */ - public Map getLabeledEnumMap(Class type) throws IllegalArgumentException; - - /** - * Resolve a single {@code LabeledEnum} by its identifying code. - * @param type the enum type - * @param code the enum code - * @return the enum - * @throws IllegalArgumentException if the code did not map to a valid instance - */ - public LabeledEnum getLabeledEnumByCode(Class type, Comparable code) throws IllegalArgumentException; - - /** - * Resolve a single {@code LabeledEnum} by its identifying code. - * @param type the enum type - * @param label the enum label - * @return the enum - * @throws IllegalArgumentException if the label did not map to a valid instance - */ - public LabeledEnum getLabeledEnumByLabel(Class type, String label) throws IllegalArgumentException; - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/LetterCodedLabeledEnum.java b/spring-core/src/main/java/org/springframework/core/enums/LetterCodedLabeledEnum.java deleted file mode 100644 index cb70971aab..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/LetterCodedLabeledEnum.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -import org.springframework.util.Assert; - -/** - * Implementation of LabeledEnum which uses a letter as the code type. - * - *

Should almost always be subclassed, but for some simple situations it may be - * used directly. Note that you will not be able to use unique type-based functionality - * like {@code LabeledEnumResolver.getLabeledEnumSet(type)} in this case. - * - * @author Keith Donald - * @since 1.2.2 - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -@SuppressWarnings("serial") -public class LetterCodedLabeledEnum extends AbstractGenericLabeledEnum { - - /** - * The unique code of this enum. - */ - private final Character code; - - - /** - * Create a new LetterCodedLabeledEnum instance. - * @param code the letter code - * @param label the label (can be {@code null}) - */ - public LetterCodedLabeledEnum(char code, String label) { - super(label); - Assert.isTrue(Character.isLetter(code), - "The code '" + code + "' is invalid: it must be a letter"); - this.code = new Character(code); - } - - - public Comparable getCode() { - return code; - } - - /** - * Return the letter code of this LabeledEnum instance. - */ - public char getLetterCode() { - return ((Character) getCode()).charValue(); - } - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/ShortCodedLabeledEnum.java b/spring-core/src/main/java/org/springframework/core/enums/ShortCodedLabeledEnum.java deleted file mode 100644 index 27a78d1c66..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/ShortCodedLabeledEnum.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -/** - * Implementation of LabeledEnum which uses Short as the code type. - * - *

Should almost always be subclassed, but for some simple situations it may be - * used directly. Note that you will not be able to use unique type-based functionality - * like {@code LabeledEnumResolver.getLabeledEnumSet(type)} in this case. - * - * @author Keith Donald - * @since 1.2.2 - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -public class ShortCodedLabeledEnum extends AbstractGenericLabeledEnum { - - private static final long serialVersionUID = 1L; - - /** - * The unique code of this enum. - */ - private final Short code; - - - /** - * Create a new ShortCodedLabeledEnum instance. - * @param code the short code - * @param label the label (can be {@code null}) - */ - public ShortCodedLabeledEnum(int code, String label) { - super(label); - this.code = new Short((short) code); - } - - - public Comparable getCode() { - return code; - } - - /** - * Return the short code of this LabeledEnum instance. - */ - public short getShortCode() { - return ((Short) getCode()).shortValue(); - } - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/StaticLabeledEnum.java b/spring-core/src/main/java/org/springframework/core/enums/StaticLabeledEnum.java deleted file mode 100644 index e6440cc3b6..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/StaticLabeledEnum.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -/** - * Base class for static type-safe labeled enum instances. - * - * Usage example: - * - *

- * public class FlowSessionStatus extends StaticLabeledEnum {
- *
- *     // public static final instances!
- *     public static FlowSessionStatus CREATED = new FlowSessionStatus(0, "Created");
- *     public static FlowSessionStatus ACTIVE = new FlowSessionStatus(1, "Active");
- *     public static FlowSessionStatus PAUSED = new FlowSessionStatus(2, "Paused");
- *     public static FlowSessionStatus SUSPENDED = new FlowSessionStatus(3, "Suspended");
- *     public static FlowSessionStatus ENDED = new FlowSessionStatus(4, "Ended");
- *
- *     // private constructor!
- *     private FlowSessionStatus(int code, String label) {
- *         super(code, label);
- *     }
- *
- *     // custom behavior
- * }
- * - * @author Keith Donald - * @since 1.2.6 - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -@SuppressWarnings("serial") -public abstract class StaticLabeledEnum extends AbstractLabeledEnum { - - /** - * The unique code of the enum. - */ - private final Short code; - - /** - * A descriptive label for the enum. - */ - private final transient String label; - - - /** - * Create a new StaticLabeledEnum instance. - * @param code the short code - * @param label the label (can be {@code null}) - */ - protected StaticLabeledEnum(int code, String label) { - this.code = new Short((short) code); - if (label != null) { - this.label = label; - } - else { - this.label = this.code.toString(); - } - } - - public Comparable getCode() { - return code; - } - - public String getLabel() { - return label; - } - - /** - * Return the code of this LabeledEnum instance as a short. - */ - public short shortValue() { - return ((Number) getCode()).shortValue(); - } - - - //--------------------------------------------------------------------- - // Serialization support - //--------------------------------------------------------------------- - - /** - * Return the resolved type safe static enum instance. - */ - protected Object readResolve() { - return StaticLabeledEnumResolver.instance().getLabeledEnumByCode(getType(), getCode()); - } - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/StaticLabeledEnumResolver.java b/spring-core/src/main/java/org/springframework/core/enums/StaticLabeledEnumResolver.java deleted file mode 100644 index 3d9f78a402..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/StaticLabeledEnumResolver.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.Set; -import java.util.TreeSet; - -import org.springframework.util.Assert; - -/** - * {@link LabeledEnumResolver} that resolves statically defined enumerations. - * Static implies all enum instances were defined within Java code, - * implementing the type-safe enum pattern. - * - * @author Keith Donald - * @author Juergen Hoeller - * @since 1.2.2 - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -public class StaticLabeledEnumResolver extends AbstractCachingLabeledEnumResolver { - - /** - * Shared {@code StaticLabeledEnumResolver} singleton instance. - */ - private static final StaticLabeledEnumResolver INSTANCE = new StaticLabeledEnumResolver(); - - - /** - * Return the shared {@code StaticLabeledEnumResolver} singleton instance. - * Mainly for resolving unique StaticLabeledEnum references on deserialization. - * @see StaticLabeledEnum - */ - public static StaticLabeledEnumResolver instance() { - return INSTANCE; - } - - - @Override - protected Set findLabeledEnums(Class type) { - Set typeEnums = new TreeSet(); - for (Field field : type.getFields()) { - if (Modifier.isStatic(field.getModifiers()) && Modifier.isPublic(field.getModifiers())) { - if (type.isAssignableFrom(field.getType())) { - try { - Object value = field.get(null); - Assert.isTrue(value instanceof LabeledEnum, "Field value must be a LabeledEnum instance"); - typeEnums.add((LabeledEnum) value); - } - catch (IllegalAccessException ex) { - logger.warn("Unable to access field value: " + field, ex); - } - } - } - } - return typeEnums; - } - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/StringCodedLabeledEnum.java b/spring-core/src/main/java/org/springframework/core/enums/StringCodedLabeledEnum.java deleted file mode 100644 index d0a936effd..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/StringCodedLabeledEnum.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed 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.springframework.core.enums; - -import org.springframework.util.Assert; - -/** - * Implementation of LabeledEnum which uses a String as the code type. - * - *

Should almost always be subclassed, but for some simple situations it may be - * used directly. Note that you will not be able to use unique type-based - * functionality like {@code LabeledEnumResolver.getLabeledEnumSet(type)} in this case. - * - * @author Keith Donald - * @author Juergen Hoeller - * @since 1.2.2 - * @see org.springframework.core.enums.LabeledEnumResolver#getLabeledEnumSet(Class) - * @deprecated as of Spring 3.0, in favor of Java 5 enums. - */ -@Deprecated -@SuppressWarnings("serial") -public class StringCodedLabeledEnum extends AbstractGenericLabeledEnum { - - /** - * The unique code of this enum. - */ - private final String code; - - - /** - * Create a new StringCodedLabeledEnum instance. - * @param code the String code - * @param label the label (can be {@code null}) - */ - public StringCodedLabeledEnum(String code, String label) { - super(label); - Assert.notNull(code, "'code' must not be null"); - this.code = code; - } - - - public Comparable getCode() { - return this.code; - } - - /** - * Return the String code of this LabeledEnum instance. - */ - public String getStringCode() { - return (String) getCode(); - } - -} diff --git a/spring-core/src/main/java/org/springframework/core/enums/package-info.java b/spring-core/src/main/java/org/springframework/core/enums/package-info.java deleted file mode 100644 index ac72053871..0000000000 --- a/spring-core/src/main/java/org/springframework/core/enums/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ - -/** - * - * Interfaces and classes for type-safe enum support on JDK >= 1.3. - * This enum abstraction support codes and labels. - * - */ -package org.springframework.core.enums; -