org.eclipse.internal.xtend.util
Class QualifiedNameWithDelimiter.QualifiedNameCache

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by org.eclipse.internal.xtend.util.WeakInterningHashSet<QualifiedNameWithDelimiter>
              extended by org.eclipse.internal.xtend.util.QualifiedNameWithDelimiter.QualifiedNameCache
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<QualifiedNameWithDelimiter>, java.util.Collection<QualifiedNameWithDelimiter>, java.util.Set<QualifiedNameWithDelimiter>
Enclosing class:
QualifiedNameWithDelimiter

protected static class QualifiedNameWithDelimiter.QualifiedNameCache
extends WeakInterningHashSet<QualifiedNameWithDelimiter>

A cached pool of weakly referenced qualified names. There are several ways of interning instances, all of which seek to avoid creating new objects whenever possible. This implementation provides the hash code computations for a qualified name. It's carefully designed to ensure that a qualified name's hash code is the same as that of its string representation, except for the encoding of the leading slash.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.internal.xtend.util.WeakInterningHashSet
WeakInterningHashSet.Entry<E>
 
Field Summary
protected  char[] buffer
          A buffer for character level processing.
protected static int[] POWERS_OF_31
          A cached array for the 31^n.
protected  java.lang.String[] segmentBuffer
          A buffer for buiding up string segments.
 
Fields inherited from class org.eclipse.internal.xtend.util.WeakInterningHashSet
CAPACITY_MASK, entries, MOD_COUNT_INCREMENT, modCount, NULL_BIT_INCREMENT, NULL_ENTRY, PRIME_CAPACITIES, queue, size
 
Constructor Summary
protected QualifiedNameWithDelimiter.QualifiedNameCache()
           
 
Method Summary
protected  void ensureSegmentCapacity(int segmentCount)
          Ensures that the segment buffer is give enough to hold the given number of segments.
protected static boolean equals(java.lang.String[] segments1, java.lang.String[] segments2)
          Returns true if the arrays are of the same length and have equal strings.
protected static int hashCode(boolean hasLeadingSlash, java.lang.String[] segments)
          Computes the hash code for the segments, taking into account whether there is a leading slash.
protected static int hashCode(boolean hasLeadingSlash, java.lang.String[] segments, java.lang.String segment)
          Computes the hash code for the segments along with the one additional segment, taking into account whether there is a leading slash.
protected static int hashCode(boolean hasLeadingSlash, java.lang.String[] segments1, java.lang.String[] segments2)
          Computes the hash code for the composed segments, taking into account whether there is a leading slash.
protected static int hashCode(int initialHashCode, java.lang.String[] segments)
          A helper utility for computing the hash code starting with a base code and taking the given segments into account.
 QualifiedNameWithDelimiter intern(boolean hasLeadingSlash, boolean needsCopying, boolean needsToIntern, java.lang.String[] segments)
          Interns the segments, taking into account the leading slash, copying the array when needed, and interning the segments themselves, when needed.
protected  QualifiedNameWithDelimiter intern(boolean hasLeadingSlash, java.lang.String[] segments, java.lang.String segment)
          Interns the segments along with the one additional segment, taking into account the leading slash and interning the additional segment.
protected  QualifiedNameWithDelimiter intern(boolean hasLeadingSlash, java.lang.String[] segments1, java.lang.String[] segments2)
          Interns the composed segments, taking into account the leading slash.
protected  QualifiedNameWithDelimiter intern(java.lang.String name)
          Interns the string representation of a qualified name, splitting it into appropriate segments.
protected static int powerOf31(int n)
          Returns 31^n.
 
Methods inherited from class org.eclipse.internal.xtend.util.WeakInterningHashSet
add, addEntry, cleanup, contains, createEntry, dump, ensureCapacity, equals, get, getEntry, grow, hashCode, index, intern, iterator, newEntries, nullEntry, putEntry, rehash, remove, removeEntry, size
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray
 

Field Detail

POWERS_OF_31

protected static int[] POWERS_OF_31
A cached array for the 31^n.


buffer

protected char[] buffer
A buffer for character level processing.


segmentBuffer

protected java.lang.String[] segmentBuffer
A buffer for buiding up string segments.

Constructor Detail

QualifiedNameWithDelimiter.QualifiedNameCache

protected QualifiedNameWithDelimiter.QualifiedNameCache()
Method Detail

powerOf31

protected static int powerOf31(int n)
Returns 31^n.


hashCode

protected static int hashCode(int initialHashCode,
                              java.lang.String[] segments)
A helper utility for computing the hash code starting with a base code and taking the given segments into account. * It emulates the computation done for String.hashCode().


hashCode

protected static int hashCode(boolean hasLeadingSlash,
                              java.lang.String[] segments)
Computes the hash code for the segments, taking into account whether there is a leading slash.


intern

public QualifiedNameWithDelimiter intern(boolean hasLeadingSlash,
                                         boolean needsCopying,
                                         boolean needsToIntern,
                                         java.lang.String[] segments)
Interns the segments, taking into account the leading slash, copying the array when needed, and interning the segments themselves, when needed.


hashCode

protected static int hashCode(boolean hasLeadingSlash,
                              java.lang.String[] segments,
                              java.lang.String segment)
Computes the hash code for the segments along with the one additional segment, taking into account whether there is a leading slash.


intern

protected QualifiedNameWithDelimiter intern(boolean hasLeadingSlash,
                                            java.lang.String[] segments,
                                            java.lang.String segment)
Interns the segments along with the one additional segment, taking into account the leading slash and interning the additional segment. All callers of this method will already have interned the segments.


hashCode

protected static int hashCode(boolean hasLeadingSlash,
                              java.lang.String[] segments1,
                              java.lang.String[] segments2)
Computes the hash code for the composed segments, taking into account whether there is a leading slash.


intern

protected QualifiedNameWithDelimiter intern(boolean hasLeadingSlash,
                                            java.lang.String[] segments1,
                                            java.lang.String[] segments2)
Interns the composed segments, taking into account the leading slash. All callers of this method will already have interned the segments.


intern

protected QualifiedNameWithDelimiter intern(java.lang.String name)
Interns the string representation of a qualified name, splitting it into appropriate segments.


ensureSegmentCapacity

protected void ensureSegmentCapacity(int segmentCount)
Ensures that the segment buffer is give enough to hold the given number of segments.

Parameters:
segmentCount -

equals

protected static boolean equals(java.lang.String[] segments1,
                                java.lang.String[] segments2)
Returns true if the arrays are of the same length and have equal strings.