Class DotName
- All Implemented Interfaces:
Comparable<DotName>
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 a 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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
(package private) static final DotName
private int
private final boolean
(package private) static final DotName
(package private) static final DotName
private final String
(package private) static final DotName
private final DotName
(package private) static final DotName
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
buildString
(char delim, StringBuilder builder) int
Compares aDotName
to anotherDotName
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
(String name) Constructs a simple DotName which stores the string in it's entirety.private static boolean
crossEquals
(DotName simple, DotName comp) boolean
Compares a DotName to another DotName and returns true if the represent the same underlying semantic name.int
hashCode()
Returns a hash code which is based on the semantic representation of thisDotName
.boolean
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 ('$").local()
Returns the local portion of this DotName.private int
nextChar
(DotName.IndexState state, DotName name) Returns the package portion of this DotName.prefix()
Returns the parent prefix for this DotName or null if there is none.private void
stripPackage
(StringBuilder builder) toString()
Returns the regular fully qualifier class name.toString
(char delim) Returns the portion of this DotName that does not contain a package prefix.
-
Field Details
-
JAVA_NAME
-
JAVA_LANG_NAME
-
OBJECT_NAME
-
ENUM_NAME
-
RECORD_NAME
-
prefix
-
local
-
hash
private int hash -
componentized
private final boolean componentized -
innerClass
private final boolean innerClass
-
-
Constructor Details
-
DotName
-
-
Method Details
-
createSimple
Constructs a simple DotName which stores the string in it's entirety. This variant is ideal for temporary usage, such as looking up an entry in a Map.- Parameters:
name
- A fully qualified non-null name (with dots)- Returns:
- a simple DotName that wraps name
-
createComponentized
Constructs a componentized DotName. Each 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 name values with the '.' character.- Parameters:
prefix
- Another DotName that is the portion to the left of localName, this may be null if there is not onelocalName
- the local non-null portion of this name, which does not contain '.'- Returns:
- a componentized DotName.
-
createComponentized
Constructs a componentized DotName. Each 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 consructed by recursing all parent prefixes and joining all local name values with the '.' character.- Parameters:
prefix
- Another DotName that is the portion to the left of localName, this may be null if there is not onelocalName
- the local non-null portion of this name, which does not contain '.'innerClass
- whether or not this localName is an inner class style name, requiring '$' vs '.'- Returns:
- a componentized DotName.
-
prefix
Returns the parent prefix for this DotName or null if there is none. Simple DotName variants never have a prefix.- Returns:
- the parent prefix for this DotName
-
local
Returns the local portion of this DotName. In simple variants, the entire fully qualified string is returned. In componentized variants, just the right most portion not including a separator (either . or $) is returned.Use
withoutPackagePrefix()
instead of this method if the desired value is simply the right most portion (including dollar signs if present) after a '.' delimiter.- Returns:
- the non-null local portion of this DotName
-
withoutPackagePrefix
Returns the portion of this 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.- Returns:
- the portion of the name that is not package prefixed
- Since:
- 2.1.1
-
stripPackage
-
packagePrefix
Returns the package portion of this DotName.- Returns:
- the package name or null if this
DotName
has no package prefix - Since:
- 2.4
-
isComponentized
public boolean isComponentized()Returns whether this DotName is a componentized variant.- Returns:
- true if it is componentized, false if it is a simple DotName
-
isInner
public boolean isInner()Returns whether the local portion of a componentized DotName is separated by an inner class style delimiter ('$"). 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 dollar 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 or not a name refers to an actual inner class is to lookup a ClassInfo in the index and call and examine the nesting type like so:index.get(name).nestingType() != TOP_LEVEL;
- Returns:
- true if local is an inner class style delimited name, false otherwise
-
toString
Returns the regular fully qualifier class name. -
toString
-
buildString
-
hashCode
public int hashCode()Returns a hash code which is based on the semantic representation of thisDotName
. Whether or not aDotName
is componentized has no impact on the calculated hash code. -
compareTo
Compares aDotName
to anotherDotName
and returns whether this DotName is lesser than, greater than, or equal to the specified DotName. If thisDotName
is lesser, a negative value is returned. If greater, a positive value is returned. If equal, zero is returned.- Specified by:
compareTo
in interfaceComparable<DotName>
- Parameters:
other
- the DotName to compare to- Returns:
- a negative number if this is less than the specified object, a positive if greater, and zero if equal
- See Also:
-
equals
Compares a DotName to another DotName and returns true if the represent the same underlying semantic name. In other words, whether or not a name is componentized or simple has no bearing on the comparison. -
crossEquals
-
nextChar
-