Class DotName
- java.lang.Object
-
- org.jboss.jandex.DotName
-
- All Implemented Interfaces:
Comparable<DotName>
public final class DotName extends Object implements Comparable<DotName>
A 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 methodInternal that when combined with a dot character, assemble the full name. The intention of the componentized variant is that the String methodInternal 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 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.
- Author:
- Jason T. Greene
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(DotName other)
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.boolean
equals(Object o)
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
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
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.
-
-
-
Method Detail
-
createSimple
public static DotName createSimple(String name)
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
public static DotName createComponentized(DotName prefix, String localName)
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
public static DotName createComponentized(DotName prefix, String localName, boolean innerClass)
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
public 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
public String 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
public String 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
-
packagePrefix
public String 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
public String toString()
Returns the regular fully qualifier class name.
-
toString
public String toString(char delim)
-
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.- Overrides:
hashCode
in classObject
- Returns:
- a hash code representing this object
- See Also:
Object.hashCode()
-
compareTo
public int compareTo(DotName other)
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:
Comparable.compareTo(Object)
-
equals
public boolean equals(Object o)
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.- Overrides:
equals
in classObject
- Parameters:
o
- the DotName object to compare to- Returns:
- true if equal, false if not
- See Also:
Object.equals(Object)
-
-