Top Description Inners Fields Constructors Methods
org.jboss.jandex

pack-priv abstract Class StrongInternPool<E>

extends Object
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Known Direct Subclasses
org.jboss.jandex.StrongInternPool.ByteArrayInternPool, org.jboss.jandex.StrongInternPool.StringInternPool, org.jboss.jandex.StrongInternPool.TypeInternPool, org.jboss.jandex.StrongInternPool.TypeArrayInternPool, org.jboss.jandex.StrongInternPool.MethodInternPool, org.jboss.jandex.StrongInternPool.FieldInternPool, org.jboss.jandex.StrongInternPool.RecordComponentInternPool
Imports
java.io.IOException, .Serializable, java.util.Arrays, .ConcurrentModificationException, .Iterator, .NoSuchElementException

A strong intern pool. The pool acts as a set where the first stored entry can be retrieved. This can be used to conserve memory by eliminating duplicate objects (those that are equal but have different identity). It however holds strong references to every item in the pool, so it must be cleared to allow for GC.

Note

It is very important to use a smaller load factor than you normally would for HashSet, since the implementation is open-addressed with linear probing. With a 50% load-factor a get is expected to return in only 2 probes. However, a 90% load-factor is expected to return in around 50 probes.

Author
Jason T. Greene

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private class
public class
private static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final int
DEFAULT_CAPACITY

Same default as HashMap, must be a power of 2

private static final float
DEFAULT_LOAD_FACTOR

67%, just like IdentityHashMap

private final Class<E>
elementType

The class of values that may be present in table.

private transient StrongInternPool<E>.Index
index

Cache for an index

private final float
loadFactor

The user defined load factor which defines when to resize

private static final int
MAXIMUM_CAPACITY

MAX_INT - 1

private transient int
modCount

Counter used to detect changes made outside of an iterator

private static final Object
NULL

Marks null keys.

private static final long
serialVersionUID

Serialization ID

private transient int
size

The current number of key-value pairs

private transient Object[]
table

The open-addressed table

Must be Object[] instead of E[] to allow storing the NULL marker.

private transient int
threshold

The next resize

Constructor Summary

AccessConstructor and Description
pack-priv
StrongInternPool(Class<E> elementType, int initialCapacity, float loadFactor)

pack-priv
StrongInternPool(Class<E> elementType, int initialCapacity)

pack-priv
StrongInternPool(Class<E> elementType)

Method Summary

Modifier and TypeMethod and Description
public void
public StrongInternPool<E>
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public boolean
pack-priv boolean
eq(Object o1, Object o2)

pack-priv abstract boolean
equality(E o1, E o2)

pack-priv static StrongInternPool<byte[]>
pack-priv static StrongInternPool<FieldInternal>
pack-priv static StrongInternPool<MethodInternal>
pack-priv static StrongInternPool<RecordComponentInternal>
pack-priv static StrongInternPool<String>
pack-priv static StrongInternPool<Type[]>
pack-priv static StrongInternPool<Type>
pack-priv int
pack-priv abstract int
hashCode(E o)

private static int
index(int hashCode, int length)

public StrongInternPool<E>.Index
private void
init(int initialCapacity, float loadFactor)

public E

Returns:

the one true unique object (equal to entry)
intern
(E
the object to internalize
entry
)

Internalizes the specified object by always returning the first ever stored.

public boolean
public Iterator<E>
private static <K> K
maskNull(K key)

pack-priv boolean
private int
nextIndex(int index, int length)

private int
offset(Object entry)

public void
private void
putForCreate(E entry)

private void
private void
relocate(int start)

public boolean
private void
resize(int from)

public int
size()

public Object[]

Returns:

an array containing elements in this set along with randomly placed nulls,
toInternalArray
()

Advanced method that returns the internal table.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private static <K> K
unmaskNull(K key)

private void
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

DEFAULT_CAPACITYback to summary
private static final int DEFAULT_CAPACITY

Same default as HashMap, must be a power of 2

DEFAULT_LOAD_FACTORback to summary
private static final float DEFAULT_LOAD_FACTOR

67%, just like IdentityHashMap

elementTypeback to summary
private final Class<E> elementType

The class of values that may be present in table.

indexback to summary
private transient StrongInternPool<E>.Index index

Cache for an index

loadFactorback to summary
private final float loadFactor

The user defined load factor which defines when to resize

MAXIMUM_CAPACITYback to summary
private static final int MAXIMUM_CAPACITY

MAX_INT - 1

modCountback to summary
private transient int modCount

Counter used to detect changes made outside of an iterator

NULLback to summary
private static final Object NULL

Marks null keys.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization ID

sizeback to summary
private transient int size

The current number of key-value pairs

tableback to summary
private transient Object[] table

The open-addressed table

Must be Object[] instead of E[] to allow storing the NULL marker.

thresholdback to summary
private transient int threshold

The next resize

Constructor Detail

StrongInternPoolback to summary
pack-priv StrongInternPool(Class<E> elementType, int initialCapacity, float loadFactor)
StrongInternPoolback to summary
pack-priv StrongInternPool(Class<E> elementType, int initialCapacity)
StrongInternPoolback to summary
pack-priv StrongInternPool(Class<E> elementType)

Method Detail

clearback to summary
public void clear()
cloneback to summary
public StrongInternPool<E> clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:StrongInternPool<E>

a clone of this instance.

Annotations
@SuppressWarnings:unchecked
containsback to summary
public boolean contains(Object entry)
eqback to summary
pack-priv boolean eq(Object o1, Object o2)
Annotations
@SuppressWarnings:unchecked
equalityback to summary
pack-priv abstract boolean equality(E o1, E o2)
forByteArraysback to summary
pack-priv static StrongInternPool<byte[]> forByteArrays()
forFieldsback to summary
pack-priv static StrongInternPool<FieldInternal> forFields()
forMethodsback to summary
pack-priv static StrongInternPool<MethodInternal> forMethods()
forRecordComponentsback to summary
pack-priv static StrongInternPool<RecordComponentInternal> forRecordComponents()
forStringsback to summary
pack-priv static StrongInternPool<String> forStrings()
forTypeArraysback to summary
pack-priv static StrongInternPool<Type[]> forTypeArrays()
forTypesback to summary
pack-priv static StrongInternPool<Type> forTypes()
hashback to summary
pack-priv int hash(Object o)
Annotations
@SuppressWarnings:unchecked
hashCodeback to summary
pack-priv abstract int hashCode(E o)
indexback to summary
private static int index(int hashCode, int length)
indexback to summary
public StrongInternPool<E>.Index index()
initback to summary
private void init(int initialCapacity, float loadFactor)
internback to summary
public E intern(E entry)

Internalizes the specified object by always returning the first ever stored. Equal objects with different identity (aka duplicates) can be eliminated with this method.

Parameters
entry:E

the object to internalize

Returns:E

the one true unique object (equal to entry)

Annotations
@SuppressWarnings:unchecked
isEmptyback to summary
public boolean isEmpty()
iteratorback to summary
public Iterator<E> iterator()
maskNullback to summary
private static <K> K maskNull(K key)
Annotations
@SuppressWarnings:unchecked
mayContainback to summary
pack-priv boolean mayContain(Object o)
nextIndexback to summary
private int nextIndex(int index, int length)
offsetback to summary
private int offset(Object entry)
printDebugStatsback to summary
public void printDebugStats()
putForCreateback to summary
private void putForCreate(E entry)
readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
Annotations
@SuppressWarnings:unchecked
relocateback to summary
private void relocate(int start)
removeback to summary
public boolean remove(Object o)
resizeback to summary
private void resize(int from)
sizeback to summary
public int size()
toInternalArrayback to summary
public Object[] toInternalArray()

Advanced method that returns the internal table. The resulting array will contain nulls at random places that must be skipped. In addition, it will not operate correctly if a null was inserted into the set. Use at your own risk....

Returns:Object[]

an array containing elements in this set along with randomly placed nulls,

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

unmaskNullback to summary
private static <K> K unmaskNull(K key)
writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException
org.jboss.jandex back to summary

private final Class StrongInternPool.ByteArrayInternPool

extends StrongInternPool<byte[]>
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
equality(byte[] o1, byte[] o2)

Implements abstract org.jboss.jandex.StrongInternPool.equality.

pack-priv int
Inherited from org.jboss.jandex.StrongInternPool:
clearclonecontainseqforByteArraysforFieldsforMethodsforRecordComponentsforStringsforTypeArraysforTypeshashindexinternisEmptyiteratormayContainprintDebugStatsremovesizetoInternalArraytoString

Constructor Detail

ByteArrayInternPoolback to summary
pack-priv ByteArrayInternPool()

Method Detail

equalityback to summary
pack-priv boolean equality(byte[] o1, byte[] o2)

Implements abstract org.jboss.jandex.StrongInternPool.equality.

Annotations
@Override
hashCodeback to summary
pack-priv int hashCode(byte[] o)

Implements abstract org.jboss.jandex.StrongInternPool.hashCode.

Annotations
@Override
org.jboss.jandex back to summary

private final Class StrongInternPool.FieldInternPool

extends StrongInternPool<FieldInternal>
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv int
Inherited from org.jboss.jandex.StrongInternPool:
clearclonecontainseqforByteArraysforFieldsforMethodsforRecordComponentsforStringsforTypeArraysforTypeshashindexinternisEmptyiteratormayContainprintDebugStatsremovesizetoInternalArraytoString

Constructor Detail

FieldInternPoolback to summary
public FieldInternPool()

Method Detail

equalityback to summary
pack-priv boolean equality(FieldInternal o1, FieldInternal o2)

Implements abstract org.jboss.jandex.StrongInternPool.equality.

Annotations
@Override
hashCodeback to summary
pack-priv int hashCode(FieldInternal o)

Implements abstract org.jboss.jandex.StrongInternPool.hashCode.

Annotations
@Override
org.jboss.jandex back to summary

private Class StrongInternPool.IdentityHashSetIterator

extends Object
implements Iterator<E>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private int
private int
private boolean
private int
pack-priv Object[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public E
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentback to summary
private int current
expectedCountback to summary
private int expectedCount
hasNextback to summary
private boolean hasNext
nextback to summary
private int next
tableback to summary
pack-priv Object[] table

Constructor Detail

IdentityHashSetIteratorback to summary
private IdentityHashSetIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextback to summary
public E next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:E

the next element in the iteration

Annotations
@SuppressWarnings:unchecked
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

org.jboss.jandex back to summary

public Class StrongInternPool.Index

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private int[]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

1-based position of e in the table, or -1 if it is not present
positionOf
(E
the entry to find in the table
e
)

Returns a 1-based position of given entry in the table.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

modCountback to summary
private int modCount
offsetsback to summary
private int[] offsets

Constructor Detail

Indexback to summary
pack-priv Index()

Method Detail

positionOfback to summary
public int positionOf(E e)

Returns a 1-based position of given entry in the table. Returns -1 if the entry is not present in the table. This indeed means that this method never returns 0.

Parameters
e:E

the entry to find in the table

Returns:int

1-based position of e in the table, or -1 if it is not present

org.jboss.jandex back to summary

private final Class StrongInternPool.MethodInternPool

extends StrongInternPool<MethodInternal>
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv int
Inherited from org.jboss.jandex.StrongInternPool:
clearclonecontainseqforByteArraysforFieldsforMethodsforRecordComponentsforStringsforTypeArraysforTypeshashindexinternisEmptyiteratormayContainprintDebugStatsremovesizetoInternalArraytoString

Constructor Detail

MethodInternPoolback to summary
public MethodInternPool()

Method Detail

equalityback to summary
pack-priv boolean equality(MethodInternal o1, MethodInternal o2)

Implements abstract org.jboss.jandex.StrongInternPool.equality.

Annotations
@Override
hashCodeback to summary
pack-priv int hashCode(MethodInternal o)

Implements abstract org.jboss.jandex.StrongInternPool.hashCode.

Annotations
@Override
org.jboss.jandex back to summary

private final Class StrongInternPool.RecordComponentInternPool

extends StrongInternPool<RecordComponentInternal>
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv int
Inherited from org.jboss.jandex.StrongInternPool:
clearclonecontainseqforByteArraysforFieldsforMethodsforRecordComponentsforStringsforTypeArraysforTypeshashindexinternisEmptyiteratormayContainprintDebugStatsremovesizetoInternalArraytoString

Constructor Detail

RecordComponentInternPoolback to summary
public RecordComponentInternPool()

Method Detail

equalityback to summary
pack-priv boolean equality(RecordComponentInternal o1, RecordComponentInternal o2)

Implements abstract org.jboss.jandex.StrongInternPool.equality.

Annotations
@Override
hashCodeback to summary
pack-priv int hashCode(RecordComponentInternal o)

Implements abstract org.jboss.jandex.StrongInternPool.hashCode.

Annotations
@Override
org.jboss.jandex back to summary

private final Class StrongInternPool.StringInternPool

extends StrongInternPool<String>
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv int
Inherited from org.jboss.jandex.StrongInternPool:
clearclonecontainseqforByteArraysforFieldsforMethodsforRecordComponentsforStringsforTypeArraysforTypeshashindexinternisEmptyiteratormayContainprintDebugStatsremovesizetoInternalArraytoString

Constructor Detail

StringInternPoolback to summary
public StringInternPool()

Method Detail

equalityback to summary
pack-priv boolean equality(String o1, String o2)

Implements abstract org.jboss.jandex.StrongInternPool.equality.

Annotations
@Override
hashCodeback to summary
pack-priv int hashCode(String o)

Implements abstract org.jboss.jandex.StrongInternPool.hashCode.

Annotations
@Override
org.jboss.jandex back to summary

private final Class StrongInternPool.TypeArrayInternPool

extends StrongInternPool<Type[]>
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv int
Inherited from org.jboss.jandex.StrongInternPool:
clearclonecontainseqforByteArraysforFieldsforMethodsforRecordComponentsforStringsforTypeArraysforTypeshashindexinternisEmptyiteratormayContainprintDebugStatsremovesizetoInternalArraytoString

Constructor Detail

TypeArrayInternPoolback to summary
public TypeArrayInternPool()

Method Detail

equalityback to summary
pack-priv boolean equality(Type[] o1, Type[] o2)

Implements abstract org.jboss.jandex.StrongInternPool.equality.

Annotations
@Override
hashCodeback to summary
pack-priv int hashCode(Type[] o)

Implements abstract org.jboss.jandex.StrongInternPool.hashCode.

Annotations
@Override
org.jboss.jandex back to summary

private final Class StrongInternPool.TypeInternPool

extends StrongInternPool<Type>
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv int
Inherited from org.jboss.jandex.StrongInternPool:
clearclonecontainseqforByteArraysforFieldsforMethodsforRecordComponentsforStringsforTypeArraysforTypeshashindexinternisEmptyiteratormayContainprintDebugStatsremovesizetoInternalArraytoString

Constructor Detail

TypeInternPoolback to summary
public TypeInternPool()

Method Detail

equalityback to summary
pack-priv boolean equality(Type o1, Type o2)

Implements abstract org.jboss.jandex.StrongInternPool.equality.

Annotations
@Override
hashCodeback to summary
pack-priv int hashCode(Type o)

Implements abstract org.jboss.jandex.StrongInternPool.hashCode.

Annotations
@Override