Class DotName
- java.lang.Object
-
- org.jboss.jandex.DotName
-
- All Implemented Interfaces:
java.lang.Comparable<DotName>
public final class DotName extends java.lang.Object implements java.lang.Comparable<DotName>
ADotName
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 moreString
components that, when combined with a dot character, assemble the full name. The intention of the componentized variant is that theString
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
andhashCode
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.
-
-
Field Summary
Fields Modifier and Type Field Description static DotName
BOOLEAN_CLASS_NAME
static DotName
BYTE_CLASS_NAME
static DotName
CHARACTER_CLASS_NAME
static DotName
CLASS_NAME
private boolean
componentized
static DotName
DOUBLE_CLASS_NAME
static DotName
ENUM_NAME
static DotName
FLOAT_CLASS_NAME
private int
hash
static DotName
INHERITED_NAME
private boolean
innerClass
static DotName
INTEGER_CLASS_NAME
(package private) static DotName
JAVA_LANG_ANNOTATION_NAME
(package private) static DotName
JAVA_LANG_NAME
(package private) static DotName
JAVA_NAME
private java.lang.String
local
static DotName
LONG_CLASS_NAME
static DotName
OBJECT_NAME
private DotName
prefix
static DotName
RECORD_NAME
static DotName
REPEATABLE_NAME
static DotName
RETENTION_NAME
static DotName
SHORT_CLASS_NAME
static DotName
STRING_NAME
static DotName
VOID_CLASS_NAME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
buildString(char delim, java.lang.StringBuilder builder)
int
compareTo(DotName other)
Compares aDotName
to anotherDotName
and returns whether thisDotName
is lesser than, greater than, or equal to the specified DotName.private static int
componentizedCompare(DotName[] a, DotName[] b)
private static boolean
componentizedEquals(DotName a, DotName b)
static DotName
createComponentized(DotName prefix, java.lang.String localName)
Constructs a componentizedDotName
.static DotName
createComponentized(DotName prefix, java.lang.String localName, boolean innerClass)
Constructs a componentizedDotName
.static DotName
createSimple(java.lang.Class<?> clazz)
Constructs a simpleDotName
which stores the name of given class in its entirety.static DotName
createSimple(java.lang.String name)
Constructs a simpleDotName
which stores the string in its entirety.boolean
equals(java.lang.Object o)
Compares aDotName
to anotherDotName
and returnstrue
if they represent the same underlying semantic name.private static DotName[]
flatten(DotName name)
int
hashCode()
Returns a hash code which is based on the semantic representation of thisDotName
.boolean
isComponentized()
Returns whether thisDotName
is a componentized variant.boolean
isInner()
Returns whether the local portion of a componentizedDotName
is separated by an inner class style delimiter ('$'
).java.lang.String
local()
Returns the local portion of thisDotName
.java.lang.String
packagePrefix()
Returns the package portion of thisDotName
.DotName
packagePrefixName()
Returns the package portion of thisDotName
.DotName
prefix()
Returns the parent prefix for thisDotName
ornull
if there is none.private void
stripPackage(java.lang.StringBuilder builder)
java.lang.String
toString()
Returns the regular binary class name.java.lang.String
toString(char delim)
Returns the regular binary class name wheredelim
is used as a package separator.java.lang.String
withoutPackagePrefix()
Returns the portion of thisDotName
that does not contain a package prefix.
-
-
-
Field Detail
-
JAVA_NAME
static final DotName JAVA_NAME
-
JAVA_LANG_NAME
static final DotName JAVA_LANG_NAME
-
JAVA_LANG_ANNOTATION_NAME
static final DotName JAVA_LANG_ANNOTATION_NAME
-
OBJECT_NAME
public static final DotName OBJECT_NAME
-
CLASS_NAME
public static final DotName CLASS_NAME
-
ENUM_NAME
public static final DotName ENUM_NAME
-
RECORD_NAME
public static final DotName RECORD_NAME
-
STRING_NAME
public static final DotName STRING_NAME
-
BOOLEAN_CLASS_NAME
public static final DotName BOOLEAN_CLASS_NAME
-
BYTE_CLASS_NAME
public static final DotName BYTE_CLASS_NAME
-
SHORT_CLASS_NAME
public static final DotName SHORT_CLASS_NAME
-
INTEGER_CLASS_NAME
public static final DotName INTEGER_CLASS_NAME
-
LONG_CLASS_NAME
public static final DotName LONG_CLASS_NAME
-
FLOAT_CLASS_NAME
public static final DotName FLOAT_CLASS_NAME
-
DOUBLE_CLASS_NAME
public static final DotName DOUBLE_CLASS_NAME
-
CHARACTER_CLASS_NAME
public static final DotName CHARACTER_CLASS_NAME
-
VOID_CLASS_NAME
public static final DotName VOID_CLASS_NAME
-
INHERITED_NAME
public static final DotName INHERITED_NAME
-
REPEATABLE_NAME
public static final DotName REPEATABLE_NAME
-
RETENTION_NAME
public static final DotName RETENTION_NAME
-
prefix
private final DotName prefix
-
local
private final java.lang.String local
-
hash
private int hash
-
componentized
private final boolean componentized
-
innerClass
private final boolean innerClass
-
-
Constructor Detail
-
DotName
DotName(DotName prefix, java.lang.String local, boolean noDots, boolean innerClass)
-
-
Method Detail
-
createSimple
public static DotName createSimple(java.lang.String name)
Constructs a simpleDotName
which stores the string in its entirety. This variant is ideal for temporary usage, such as looking up an entry in aMap
or an index.- Parameters:
name
- a fully qualified name (with dots); must not benull
- Returns:
- a simple
DotName
that wraps givenname
; nevernull
-
createSimple
public static DotName createSimple(java.lang.Class<?> clazz)
Constructs a simpleDotName
which stores the name of given class in its entirety. This variant is ideal for temporary usage, such as looking up an entry in aMap
or an index.This method is a shortcut for
DotName.createSimple(clazz.getName())
.- Parameters:
clazz
- a class whose fully qualified name is returned; must not benull
- Returns:
- a simple
DotName
that wraps the name of givenclazz
; nevernull
-
createComponentized
public static DotName createComponentized(DotName prefix, java.lang.String localName)
Constructs a componentizedDotName
. SuchDotName
refers to a parent prefix (ornull
if there is no further prefix) in addition to a local name that has no dot separator. The fully qualified name thisDotName
represents is constructed by recursing all parent prefixes and joining all local names with the'.'
character.- Parameters:
prefix
- anotherDotName
that is the portion of the final name to the left oflocalName
; may benull
if there is no prefixlocalName
- the local portion of this name; must not benull
and must not contain'.'
- Returns:
- a componentized
DotName
; nevernull
-
createComponentized
public static DotName createComponentized(DotName prefix, java.lang.String localName, boolean innerClass)
Constructs a componentizedDotName
. SuchDotName
refers to a parent prefix (ornull
if there is no further prefix) in addition to a local name that has no dot separator. The fully qualified name thisDotName
represents is constructed by recursing all parent prefixes and joining all local names with the'.'
character.- Parameters:
prefix
- anotherDotName
that is the portion of the final name to the left oflocalName
; may benull
if there is no prefixlocalName
- the local portion of this name; must not benull
and must not contain'.'
innerClass
- whether thelocalName
is an inner class style name, which is joined to the prefix using'$'
instead of'.'
- Returns:
- a componentized
DotName
; nevernull
-
prefix
public DotName prefix()
Returns the parent prefix for thisDotName
ornull
if there is none. SimpleDotName
variants never have a prefix.- Returns:
- the parent prefix for this
DotName
; may benull
-
local
public java.lang.String local()
Returns the local portion of thisDotName
. 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.- Returns:
- the local portion of this
DotName
; nevernull
-
withoutPackagePrefix
public java.lang.String withoutPackagePrefix()
Returns the portion of thisDotName
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 fully qualified name that does not include a package name
- Since:
- 2.1.1
-
stripPackage
private void stripPackage(java.lang.StringBuilder builder)
-
packagePrefix
public java.lang.String packagePrefix()
Returns the package portion of thisDotName
.- Returns:
- the package name or
null
if thisDotName
has no package prefix - Since:
- 2.4
-
packagePrefixName
public DotName packagePrefixName()
Returns the package portion of thisDotName
. This is aDotName
-returning variant ofpackagePrefix()
.- Returns:
- the package name or
null
if thisDotName
has no package prefix - Since:
- 3.0
-
isComponentized
public boolean isComponentized()
Returns whether thisDotName
is a componentized variant.- Returns:
true
if it is componentized,false
if it is a simpleDotName
-
isInner
public boolean isInner()
Returns whether the local portion of a componentizedDotName
is separated by an inner class style delimiter ('$'
). The result is undefined when thisDotName
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 aClassInfo
in the index and examine the nesting type like so:index.getClassByName(name).nestingType() != TOP_LEVEL;
- Returns:
true
if local is an inner class style delimited name,false
otherwise
-
toString
public java.lang.String toString()
Returns the regular binary class name.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the binary class name
-
toString
public java.lang.String toString(char delim)
Returns the regular binary class name wheredelim
is used as a package separator.- Parameters:
delim
- the package separator; typically.
, but may be e.g./
to construct a bytecode descriptor- Returns:
- the binary class name with given character used as a package separator
-
buildString
private void buildString(char delim, java.lang.StringBuilder builder)
-
hashCode
public int hashCode()
Returns a hash code which is based on the semantic representation of thisDotName
.Whether a
DotName
is componentized has no impact on the calculated hash code. In other words, a componentizedDotName
and a simpleDotName
that represent the same fully qualified name have the same hash code.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code representing this object
- See Also:
Object.hashCode()
-
equals
public boolean equals(java.lang.Object o)
Compares aDotName
to anotherDotName
and returnstrue
if they represent the same underlying semantic name. In other words, whether a name is componentized or simple has no bearing on the comparison.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- theDotName
object to compare to- Returns:
- true if equal, false if not
- See Also:
Object.equals(Object)
-
compareTo
public int compareTo(DotName other)
Compares aDotName
to anotherDotName
and returns whether thisDotName
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 interfacejava.lang.Comparable<DotName>
- Parameters:
other
- theDotName
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:
Comparable.compareTo(Object)
-
-