public final class DotName extends Object implements Comparable<DotName>
DotName represents a dot separated name, typically a Java package or a Java class.
It has two possible variants. A simple wrapper based variant allows for fast construction
(it simply wraps the specified name string). Whereas, a componentized variant represents
one or more String components that, when combined with a dot character, assemble the
full name. The intention of the componentized variant is that the String components
can be reused to offer memory efficiency. This reuse is common in Java where packages
and classes follow a tree structure.
Both the simple and componentized variants are considered semantically equivalent if they
refer to the same logical name. More specifically, the equals and hashCode
methods return the same values for the same semantic name regardless of the variant used.
Which variant to use when depends on the specific performance and overhead objectives
of the specific use pattern.
Simple names are cheap to construct (just an additional wrapper object), so are ideal for
temporary use, like looking for an entry in a Map. Componentized names however require
that they be split in advance, and so require some additional time to construct. However, the memory
benefits of reusing component strings make them desirable when stored in a longer term area
such as in a Java data structure.
| Modifier and Type | Field and Description |
|---|---|
static DotName |
ENUM_NAME |
static DotName |
OBJECT_NAME |
static DotName |
RECORD_NAME |
static DotName |
STRING_NAME |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(DotName other)
Compares a
DotName to another DotName and returns whether this DotName
is lesser than, greater than, or equal to the specified DotName. |
static DotName |
createComponentized(DotName prefix,
String localName)
Constructs a componentized
DotName. |
static DotName |
createComponentized(DotName prefix,
String localName,
boolean innerClass)
Constructs a componentized
DotName. |
static DotName |
createSimple(Class<?> clazz)
Constructs a simple
DotName which stores the name of given class in its entirety. |
static DotName |
createSimple(String name)
Constructs a simple
DotName which stores the string in its entirety. |
boolean |
equals(Object o)
Compares a
DotName to another DotName and returns true
if they represent the same underlying semantic name. |
int |
hashCode()
Returns a hash code which is based on the semantic representation of this
DotName. |
boolean |
isComponentized()
Returns whether this
DotName is a componentized variant. |
boolean |
isInner()
Returns whether the local portion of a componentized
DotName is separated
by an inner class style delimiter ('$'). |
String |
local()
Returns the local portion of this
DotName. |
String |
packagePrefix()
Returns the package portion of this
DotName. |
DotName |
packagePrefixName()
Returns the package portion of this
DotName. |
DotName |
prefix()
Returns the parent prefix for this
DotName or null if there is none. |
String |
toString()
Returns the regular fully qualifier class name.
|
String |
toString(char delim) |
String |
withoutPackagePrefix()
Returns the portion of this
DotName that does not contain a package prefix. |
public static final DotName OBJECT_NAME
public static final DotName ENUM_NAME
public static final DotName RECORD_NAME
public static final DotName STRING_NAME
public static DotName createSimple(String name)
DotName which stores the string in its entirety. This variant is ideal
for temporary usage, such as looking up an entry in a Map or an index.name - a fully qualified name (with dots); must not be nullDotName that wraps given name; never nullpublic static DotName createSimple(Class<?> clazz)
DotName which stores the name of given class in its entirety.
This variant is ideal for temporary usage, such as looking up an entry in a Map
or an index.
This method is a shortcut for DotName.createSimple(clazz.getName()).
clazz - a class whose fully qualified name is returned; must not be nullDotName that wraps the name of given clazz; never nullpublic static DotName createComponentized(DotName prefix, String localName)
DotName. Such DotName refers to
a parent prefix (or null if there is no further prefix) in addition
to a local name that has no dot separator. The fully qualified name this
DotName represents is constructed by recursing all parent prefixes
and joining all local names with the '.' character.prefix - another DotName that is the portion of the final name to the left of localName; may be
null if there is no prefixlocalName - the local portion of this name; must not be null and must not contain '.'DotName; never nullpublic static DotName createComponentized(DotName prefix, String localName, boolean innerClass)
DotName. Such DotName refers to
a parent prefix (or null if there is no further prefix) in addition
to a local name that has no dot separator. The fully qualified name this
DotName represents is constructed by recursing all parent prefixes
and joining all local names with the '.' character.prefix - another DotName that is the portion of the final name to the left of localName; may be
null if there is no prefixlocalName - the local portion of this name; must not be null and must not contain '.'innerClass - whether the localName is an inner class style name, which is joined to the prefix using
'$' instead of '.'DotName; never nullpublic DotName prefix()
DotName or null if there is none.
Simple DotName variants never have a prefix.DotName; may be nullpublic String local()
DotName. In simple variants,
the entire fully qualified string is returned. In componentized variants,
just the rightmost portion not including a separator (either '.'
or '$') is returned.
Use withoutPackagePrefix() instead of this method if the
desired value is the part of the string (including '$' signs
if present) after the rightmost '.' delimiter.
DotName; never nullpublic String withoutPackagePrefix()
DotName that does not contain a package prefix.
In the case of an inner class syntax name, the '$' portion is included in
the return value.public String packagePrefix()
DotName.null if this DotName has no package prefixpublic DotName packagePrefixName()
DotName. This is a DotName-returning
variant of packagePrefix().null if this DotName has no package prefixpublic boolean isComponentized()
DotName is a componentized variant.true if it is componentized, false if it is a simple DotNamepublic boolean isInner()
DotName is separated
by an inner class style delimiter ('$'). The result is undefined when this
DotName is not componentized.
This should not be used to test whether the name truly refers to an inner class,
only that the dollar sign delimits the value. Java class names are allowed to contain
'$' signs, so the local value could simply be a fragment of a class name,
and not an actual inner class. The correct way to determine whether a name refers
to an actual inner class is to look up a ClassInfo in the index and examine
the nesting type like so:
index.getClassByName(name).nestingType() != TOP_LEVEL;
true if local is an inner class style delimited name, false otherwisepublic String toString()
public String toString(char delim)
public int hashCode()
DotName.
Whether a DotName is componentized has no impact on the calculated hash code.
In other words, a componentized DotName and a simple DotName that
represent the same fully qualified name have the same hash code.
hashCode in class ObjectObject.hashCode()public int compareTo(DotName other)
DotName to another DotName and returns whether this DotName
is lesser than, greater than, or equal to the specified DotName. If this DotName is lesser,
a negative value is returned. If greater, a positive value is returned. If equal, zero is returned.compareTo in interface Comparable<DotName>other - the DotName to compare toComparable.compareTo(Object)public boolean equals(Object o)
DotName to another DotName and returns true
if they represent the same underlying semantic name. In other words, whether a
name is componentized or simple has no bearing on the comparison.equals in class Objecto - the DotName object to compare toObject.equals(Object)Copyright © 2018–2022. All rights reserved.