org.eclipse.internal.xtend.util
Class QualifiedNameWithDelimiter

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

public final class QualifiedNameWithDelimiter
extends java.lang.Object

A memory efficient structure to store qualified names composed of string segments separated by '/'. A QualifiedName 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.


Nested Class Summary
protected static class QualifiedNameWithDelimiter.QualifiedNameCache
          A cached pool of weakly referenced qualified names.
protected static class QualifiedNameWithDelimiter.StringCache
          A cached pool of weakly referenced strings.
 
Field Summary
protected static QualifiedNameWithDelimiter.QualifiedNameCache CACHE
          The cached pool for the qualified name instances.
protected static QualifiedNameWithDelimiter EMPTY
          The qualified name instance corresponding to "/".
protected static java.lang.String[] EMPTY_ARRAY
          The instance used to represent no segments.
protected static QualifiedNameWithDelimiter EMPTY_WITHOUT_LEADING_SLASH
          The qualified name instance corresponding to the empty string.
protected  int hashCode
          The cached hash code for this instance.
protected  java.lang.String[] segments
          The segments for this instance.
protected static char SLASH
          The segment separator character.
protected static QualifiedNameWithDelimiter.StringCache STRING_CACHE
          A cached for pool for strings.
protected  java.lang.ref.WeakReference<java.lang.String> toString
          The cached value for toString().
 
Constructor Summary
protected QualifiedNameWithDelimiter(java.lang.String[] segments, int hashCode)
          Creates an instance with the given segments and hash code.
 
Method Summary
 QualifiedNameWithDelimiter append(QualifiedNameWithDelimiter qualifiedName)
          Returns an instance with the given additional segments.
 QualifiedNameWithDelimiter append(java.lang.String segment)
          Returns an instance with the additional segment or segments, if the given segment contains '/'.
static QualifiedNameWithDelimiter create(java.lang.String... segments)
          Returns the qualified name for the given segments, splitting individual segments as appropriate.
static QualifiedNameWithDelimiter create(java.lang.String qualifiedName)
          Returns the qualified name for the argument, splitting into segments as appropriate.
static QualifiedNameWithDelimiter createWithoutLeadingSlash(java.lang.String... segments)
          Returns the qualified name for the given segments, splitting individual segments as appropriate.
 java.lang.String getFirstSegment()
          Returns the first segment of the qualified name.
 java.lang.String getLastSegment()
          Returns the last segment of the qualified name.
 java.lang.String getSegment(int index)
          Returns the specified segment of the qualified name.
 int getSegmentCount()
          Returns the number of segments in the qualified name.
 int hashCode()
          Although there is an override of hash code, there is no override of Object.equals(Object) because the static methods for creation ensure there is at most one instance created for each unique qualified name.
 boolean hasLeadingSlash()
          Returns whether the qualified name's string representation starts with a '/'.
static java.lang.String intern(char[] characters, int offset, int count)
          Returns the cached string with the given range of characters.
static java.lang.String intern(java.lang.String string)
          Returns the cached string equal to the given string.
static void main(java.lang.String[] args)
           
 boolean matches(java.lang.String qualifiedName)
          Returns true if the string representation of this qualified name is equal to the given string.
protected static int setLeadingSlash(boolean hasLeadingSlash, int hashCode)
          Returns the hash code with the appropriately swizzled high bit.
protected static java.lang.String[] split(java.lang.String[] segments)
          Splits any segment that contains a "/" and returns the composed result.
 java.lang.String toString()
          Returns a canonical string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SLASH

protected static final char SLASH
The segment separator character.

See Also:
Constant Field Values

EMPTY_ARRAY

protected static final java.lang.String[] EMPTY_ARRAY
The instance used to represent no segments.


CACHE

protected static final QualifiedNameWithDelimiter.QualifiedNameCache CACHE
The cached pool for the qualified name instances.


STRING_CACHE

protected static final QualifiedNameWithDelimiter.StringCache STRING_CACHE
A cached for pool for strings.


EMPTY_WITHOUT_LEADING_SLASH

protected static final QualifiedNameWithDelimiter EMPTY_WITHOUT_LEADING_SLASH
The qualified name instance corresponding to the empty string.


EMPTY

protected static final QualifiedNameWithDelimiter EMPTY
The qualified name instance corresponding to "/".


hashCode

protected final int hashCode
The cached hash code for this instance.


segments

protected java.lang.String[] segments
The segments for this instance.


toString

protected java.lang.ref.WeakReference<java.lang.String> toString
The cached value for toString().

Constructor Detail

QualifiedNameWithDelimiter

protected QualifiedNameWithDelimiter(java.lang.String[] segments,
                                     int hashCode)
Creates an instance with the given segments and hash code.

Method Detail

append

public QualifiedNameWithDelimiter append(QualifiedNameWithDelimiter qualifiedName)
Returns an instance with the given additional segments.


append

public QualifiedNameWithDelimiter append(java.lang.String segment)
Returns an instance with the additional segment or segments, if the given segment contains '/'.


toString

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

Overrides:
toString in class java.lang.Object

hasLeadingSlash

public boolean hasLeadingSlash()
Returns whether the qualified name's string representation starts with a '/'.


setLeadingSlash

protected static int setLeadingSlash(boolean hasLeadingSlash,
                                     int hashCode)
Returns the hash code with the appropriately swizzled high bit.


getSegmentCount

public int getSegmentCount()
Returns the number of segments in the qualified name.


getSegment

public java.lang.String getSegment(int index)
Returns the specified segment of the qualified name.


getLastSegment

public java.lang.String getLastSegment()
Returns the last segment of the qualified name.


getFirstSegment

public java.lang.String getFirstSegment()
Returns the first segment of the qualified name.


hashCode

public int hashCode()
Although there is an override of hash code, there is no override of Object.equals(Object) because the static methods for creation ensure there is at most one instance created for each unique qualified name.

Overrides:
hashCode in class java.lang.Object

matches

public boolean matches(java.lang.String qualifiedName)
Returns true if the string representation of this qualified name is equal to the given string.


intern

public static java.lang.String intern(java.lang.String string)
Returns the cached string equal to the given string. Note that the argument itself will never be added to the cache, but rather a copy of it, so it's safe to call this for a string that's a substring of a much larger string.


intern

public static java.lang.String intern(char[] characters,
                                      int offset,
                                      int count)
Returns the cached string with the given range of characters.


create

public static QualifiedNameWithDelimiter create(java.lang.String qualifiedName)
Returns the qualified name for the argument, splitting into segments as appropriate.


create

public static QualifiedNameWithDelimiter create(java.lang.String... segments)
Returns the qualified name for the given segments, splitting individual segments as appropriate. The result will have a leading slash.


createWithoutLeadingSlash

public static QualifiedNameWithDelimiter createWithoutLeadingSlash(java.lang.String... segments)
Returns the qualified name for the given segments, splitting individual segments as appropriate. The result will not have a leading slash, unless there is a leading empty string in the segments in which case that leading segment is removed and the result has a leading slash.


split

protected static java.lang.String[] split(java.lang.String[] segments)
Splits any segment that contains a "/" and returns the composed result. If no segment contains a "/", the argument is returned.


main

public static void main(java.lang.String[] args)