Class DotName

  • All Implemented Interfaces:
    java.lang.Comparable<DotName>

    public final class DotName
    extends java.lang.Object
    implements java.lang.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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  DotName.IndexState  
    • Constructor Summary

      Constructors 
      Constructor Description
      DotName​(DotName prefix, java.lang.String local, boolean noDots, boolean innerClass)  
    • 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 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, java.lang.String localName)
      Constructs a componentized DotName.
      static DotName createComponentized​(DotName prefix, java.lang.String localName, boolean innerClass)
      Constructs a componentized DotName.
      static DotName createSimple​(java.lang.String name)
      Constructs a simple DotName which stores the string in it's entirety.
      private static boolean crossEquals​(DotName simple, DotName comp)  
      boolean equals​(java.lang.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 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 ('$").
      java.lang.String local()
      Returns the local portion of this DotName.
      private int nextChar​(DotName.IndexState state, DotName name)  
      java.lang.String packagePrefix()
      Returns the package portion of this DotName.
      DotName prefix()
      Returns the parent prefix for this DotName or null if there is none.
      private void stripPackage​(java.lang.StringBuilder builder)  
      java.lang.String toString()
      Returns the regular fully qualifier class name.
      java.lang.String toString​(char delim)  
      java.lang.String withoutPackagePrefix()
      Returns the portion of this DotName that does not contain a package prefix.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • JAVA_NAME

        static final DotName JAVA_NAME
      • JAVA_LANG_NAME

        static final DotName JAVA_LANG_NAME
      • OBJECT_NAME

        static final DotName OBJECT_NAME
      • ENUM_NAME

        static final DotName ENUM_NAME
      • RECORD_NAME

        static final DotName RECORD_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 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,
                                                  java.lang.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 one
        localName - the local non-null portion of this name, which does not contain '.'
        Returns:
        a componentized DotName.
      • createComponentized

        public static DotName createComponentized​(DotName prefix,
                                                  java.lang.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 one
        localName - 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 java.lang.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 java.lang.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
      • stripPackage

        private void stripPackage​(java.lang.StringBuilder builder)
      • packagePrefix

        public java.lang.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 java.lang.String toString()
        Returns the regular fully qualifier class name.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The fully qualified class name
      • toString

        public java.lang.String toString​(char delim)
      • 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 this DotName. Whether or not a DotName is componentized has no impact on the calculated hash code.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code representing this object
        See Also:
        Object.hashCode()
      • compareTo

        public 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. If this DotName is lesser, a negative value is returned. If greater, a positive value is returned. If equal, zero is returned.
        Specified by:
        compareTo in interface java.lang.Comparable<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​(java.lang.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 class java.lang.Object
        Parameters:
        o - the DotName object to compare to
        Returns:
        true if equal, false if not
        See Also:
        Object.equals(Object)
      • crossEquals

        private static boolean crossEquals​(DotName simple,
                                           DotName comp)