public final class RenameHandler
extends java.lang.Object
This handles type and enum constant renames. For example, use as follows:
RenameHandler.INSTANCE.renamedType("org.joda.OldName", NewName.class); RenameHandler.INSTANCE.renamedEnum("CORRECT", Status.VALID); RenameHandler.INSTANCE.renamedEnum("INCORRECT", Status.INVALID);The recommended usage is to edit the static singleton before using other classes. Editing a static is acceptable because renames are driven by bytecode which is static.
This class is thread-safe with concurrent caches.
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.ConcurrentHashMap<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.Enum<?>>> |
enumRenames
The enum renames.
|
static RenameHandler |
INSTANCE
A mutable global instance.
|
private java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Class<?>> |
typeRenames
The type renames.
|
Modifier | Constructor and Description |
---|---|
private |
RenameHandler()
Restricted constructor.
|
Modifier and Type | Method and Description |
---|---|
static RenameHandler |
create()
Creates an instance.
|
java.util.Map<java.lang.String,java.lang.Enum<?>> |
getEnumRenames(java.lang.Class<?> type)
Gets the map of renamed for an enum type.
|
java.util.Set<java.lang.Class<?>> |
getEnumTypesWithRenames()
Gets the set of enum types that have renames.
|
java.util.Map<java.lang.String,java.lang.Class<?>> |
getTypeRenames()
Gets the map of renamed types.
|
(package private) java.lang.Class<?> |
loadType(java.lang.String fullName)
Loads a type avoiding nulls
|
<T extends java.lang.Enum<T>> |
lookupEnum(java.lang.Class<T> type,
java.lang.String name)
Lookup an enum from a name, handling renames.
|
java.lang.Class<?> |
lookupType(java.lang.String name)
Lookup a type from a name, handling renames.
|
void |
renamedEnum(java.lang.String oldName,
java.lang.Enum<?> currentValue)
Register the fact that an enum constant was renamed.
|
void |
renamedType(java.lang.String oldName,
java.lang.Class<?> currentValue)
Register the fact that a type was renamed.
|
java.lang.String |
toString() |
public static final RenameHandler INSTANCE
private final java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Class<?>> typeRenames
private final java.util.concurrent.ConcurrentHashMap<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.Enum<?>>> enumRenames
public static RenameHandler create()
This is not normally used as the preferred option is to edit the singleton.
public void renamedType(java.lang.String oldName, java.lang.Class<?> currentValue)
oldName
- the old name of the type including the package name, not nullcurrentValue
- the current type, not nullpublic java.util.Map<java.lang.String,java.lang.Class<?>> getTypeRenames()
An empty map is returned if there are no renames.
public java.lang.Class<?> lookupType(java.lang.String name) throws java.lang.ClassNotFoundException
name
- the name of the type to lookup, not nulljava.lang.ClassNotFoundException
- if the name is not a valid typejava.lang.Class<?> loadType(java.lang.String fullName) throws java.lang.ClassNotFoundException
fullName
- the full class namejava.lang.ClassNotFoundException
- if the class is not foundpublic void renamedEnum(java.lang.String oldName, java.lang.Enum<?> currentValue)
oldName
- the old name of the enum constant, not nullcurrentValue
- the current enum constant, not nullpublic java.util.Set<java.lang.Class<?>> getEnumTypesWithRenames()
An empty set is returned if there are no renames.
public java.util.Map<java.lang.String,java.lang.Enum<?>> getEnumRenames(java.lang.Class<?> type)
An empty map is returned if there are no renames.
type
- the enum type, not nullpublic <T extends java.lang.Enum<T>> T lookupEnum(java.lang.Class<T> type, java.lang.String name)
T
- the type of the desired enumtype
- the enum type, not nullname
- the name of the enum to lookup, not nulljava.lang.IllegalArgumentException
- if the name is not a valid enum constantpublic java.lang.String toString()
toString
in class java.lang.Object