org.eclipse.internal.xtend.util
Class QualifiedName

java.lang.Object
  extended by org.eclipse.internal.xtend.util.QualifiedName

public final class QualifiedName
extends java.lang.Object

A memory efficient structure to store qualified names composed of String segments which are (optionally) separated by a delimiter. QualifiedNames must be constructed through one its create methods. The structure uses String pooling to store the single segments. Further it maintains a pool of QualifiedName instances itself, so that each QualifiedName exists only once.

Author:
Karsten Thoms

Field Summary
protected static org.eclipse.internal.xtend.util.QualifiedName.QualifiedNameCache CACHE
           
protected  int hash
           
protected  java.lang.String[] segments
           
protected  java.lang.ref.WeakReference<java.lang.String> toString
           
 
Constructor Summary
protected QualifiedName(java.lang.String[] segments, int hashCode)
          Constructor
 
Method Summary
 QualifiedName append(QualifiedName t)
          Append another Identifier to this instance
static QualifiedName create(java.lang.String segment)
          Factory method.
static QualifiedName create(java.lang.String[] segments)
          Factory method.
static QualifiedName create(java.lang.String segments, java.lang.String delimiter)
          Factory method.
 java.lang.String getFirstSegment()
           
 java.lang.String getLastSegment()
           
 java.lang.String getSegment(int index)
           
 int getSegmentCount()
           
 int hashCode()
          Note that there's no override of Object.equals(Object) because all instances are interned and therefore there's at most one possible instance for sequence of segments.
 java.lang.String toString()
          Returns a canonical String representation of this.
 java.lang.String toString(java.lang.String delimiter)
          Returns a canonical String representation of this using the specified delimiter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

hash

protected final int hash

segments

protected java.lang.String[] segments

toString

protected java.lang.ref.WeakReference<java.lang.String> toString

CACHE

protected static final org.eclipse.internal.xtend.util.QualifiedName.QualifiedNameCache CACHE
Constructor Detail

QualifiedName

protected QualifiedName(java.lang.String[] segments,
                        int hashCode)
Constructor

Parameters:
segments - Segments of the Identifier.
delimiter - A delimiter string for the construction of a String representation with toString(). Can be null.
Method Detail

append

public QualifiedName append(QualifiedName t)
Append another Identifier to this instance

Parameters:
t - An identifier.
Returns:
Will return this extended by the segments of t

toString

public java.lang.String toString()
Returns a canonical String representation of this.

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String delimiter)
Returns a canonical String representation of this using the specified delimiter. This method will perform less than toString(), since the result cannot be cached.

Parameters:
delimiter - A delimiter to insert between segments.

getSegmentCount

public int getSegmentCount()

getSegment

public java.lang.String getSegment(int index)

getLastSegment

public java.lang.String getLastSegment()

getFirstSegment

public java.lang.String getFirstSegment()

hashCode

public int hashCode()
Note that there's no override of Object.equals(Object) because all instances are interned and therefore there's at most one possible instance for sequence of segments.

Overrides:
hashCode in class java.lang.Object

create

public static QualifiedName create(java.lang.String[] segments)
Factory method.

Parameters:
segments - segments the segments of the to-be-created qualified name.
Returns:
a QualifiedName. When the factory method was already invoked with the same arguments the same instance as the previous call will be returned.

create

public static QualifiedName create(java.lang.String segment)
Factory method. A name with a single segment.

Parameters:
segment - The string segment of the qualified name.
Returns:
a QualifiedName. When the factory method was already invoked with the same arguments the same instance as the previous call will be returned.

create

public static QualifiedName create(java.lang.String segments,
                                   java.lang.String delimiter)
Factory method. A name separated by a delimiter.

Parameters:
segments - The string segment of the qualified name.
delimiter - The delimiter which separates the segments.
Returns:
a QualifiedName. When the factory method was already invoked with the same arguments the same instance as the previous call will be returned.