public class ClassAliasPool extends Object implements ClassLookup
| Modifier and Type | Field and Description |
|---|---|
static ClassAliasPool |
CLASS_ALIASES |
| Modifier and Type | Method and Description |
|---|---|
static void |
a(Class<?>... classes) |
static void |
a(Class<?> clazz) |
void |
addAlias(Class<?>... classes)
Adds one or more classes to the class lookup.
|
void |
addAlias(Class<?> clazz,
@NotNull String names)
Adds a class to the class lookup with one or more specified aliases.
|
CharSequence |
applyAlias(CharSequence name)
Applies an alias transformation to the given class name if an alias exists.
|
void |
clean()
Removes classes from the lookup which are not loaded by the default class loaders.
|
@NotNull Class<?> |
forName(@NotNull CharSequence name)
Looks up and returns the Class object associated with the given class name.
|
String |
nameFor(Class<?> clazz)
Retrieves the alias for the given class.
|
void |
removePackage(String pkgName) |
void |
resetResolutionFailures()
A method to reset previous resolution failures so they may be reattempted, e.g.
|
protected static boolean |
testPackage(String pkgName,
Class<?> clazz) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitwrap, wrappublic static final ClassAliasPool CLASS_ALIASES
public static void a(Class<?> clazz)
public void clean()
@NotNull public @NotNull Class<?> forName(@NotNull @NotNull CharSequence name) throws ClassNotFoundRuntimeException
ClassLookupforName in interface ClassLookupname - The fully qualified name of the desired class.ClassNotFoundRuntimeException - If the class cannot be located.public void resetResolutionFailures()
public String nameFor(Class<?> clazz) throws IllegalArgumentException
ClassLookupnameFor in interface ClassLookupclazz - The class to retrieve the alias for.IllegalArgumentException - If this method is used on a lambda function.public void removePackage(String pkgName)
public void addAlias(@NotNull
Class<?>... classes)
ClassLookupaddAlias in interface ClassLookupclasses - The classes to be added to the class lookup.public void addAlias(Class<?> clazz, @NotNull @NotNull String names)
ClassLookupaddAlias in interface ClassLookupclazz - The class to be added to the class lookup.names - A single alias or a comma-separated string of aliases for the class.public CharSequence applyAlias(CharSequence name)
ClassLookupThis method first looks up the provided class name in the internal alias mappings. If a direct match is found, it returns the corresponding class name as registered in the alias. If no direct match is found, it attempts to find a match using a case-insensitive search. This dual-step lookup ensures that aliases can be effectively used regardless of case sensitivity. If after both steps no alias is found, the method returns the original class name, ensuring that the operation is always safe and will not result in a loss of reference.
Usage of this method can significantly reduce the verbosity of class references in scenarios where short, memorable aliases are preferred over full class names. It is particularly useful in configuration files, dynamic class loading scenarios, or any context where class names are used as strings and brevity or clarity is desired.
applyAlias in interface ClassLookupname - The CharSequence representing the class name or alias to be transformed.null or an invalid class name.for how aliases are added to the pool.public static void a(Class<?>... classes)
Copyright © 2024. All rights reserved.