Top Description Fields Constructors Methods
com.ctc.wstx.util

public final Class ElementIdMap

extends Object
Class Inheritance
Imports
javax.xml.stream.Location

This class is a specialized type-safe linked hash map used for storing ElementId instances. ElementId instances represent both id definitions (values of element attributes that have type ID in DTD), and references (values of element attributes of type IDREF and IDREFS). These definitions and references are stored for the purpose of verifying that all referenced id values are defined, and that none are defined more than once.

Note

there are 2 somewhat distinct usage modes, by DTDValidator and by MSV-based validators. DTDs pass raw character arrays, whereas MSV-based validators operate on Strings. This is the main reason for 2 distinct sets of methods.

Field Summary

Modifier and TypeField and Description
protected static final int
DEFAULT_SIZE

Default initial table size; set so that usually it need not be expanded.

protected static final int
FILL_PCT

Let's use 80% fill factor...

protected ElementId
protected static final int
protected int
mIndexMask

Mask used to get index from hash values; equal to mBuckets.length - 1, when mBuckets.length is a power of two.

protected int
mSize

Current size (number of entries); needed to know if and when rehash.

protected int
mSizeThreshold

Limit that indicates maximum size this instance can hold before it needs to be expanded and rehashed.

protected ElementId[]
mTable

Actual hash table area

protected ElementId

Constructor Summary

AccessConstructor and Description
public
public
ElementIdMap(int initialSize)

This constructor is mainly used for testing, as it can be sized appropriately to test rehashing etc.

Method Summary

Modifier and TypeMethod and Description
public ElementId
addDefined(char[] buffer, int start, int len, int hash, Location loc, PrefixedName elemName, PrefixedName attrName)

Method called when an id definition is encountered.

public ElementId
addDefined(String idStr, Location loc, PrefixedName elemName, PrefixedName attrName)

public ElementId
addReferenced(char[] buffer, int start, int len, int hash, Location loc, PrefixedName elemName, PrefixedName attrName)

Method called when a reference to id is encountered.

public ElementId
addReferenced(String idStr, Location loc, PrefixedName elemName, PrefixedName attrName)

public static int
calcHash(char[] buffer, int start, int
Length of String; has to be at least 1 (caller guarantees this pre-condition)
len
)

Implementation of a hashing method for variable length Strings.

public static int
public ElementId
private void
rehash()

Method called when size (number of entries) of symbol table grows so big that load factor is exceeded.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_SIZEback to summary
protected static final int DEFAULT_SIZE

Default initial table size; set so that usually it need not be expanded.

FILL_PCTback to summary
protected static final int FILL_PCT

Let's use 80% fill factor...

mHeadback to summary
protected ElementId mHead
MIN_SIZEback to summary
protected static final int MIN_SIZE
mIndexMaskback to summary
protected int mIndexMask

Mask used to get index from hash values; equal to mBuckets.length - 1, when mBuckets.length is a power of two.

mSizeback to summary
protected int mSize

Current size (number of entries); needed to know if and when rehash.

mSizeThresholdback to summary
protected int mSizeThreshold

Limit that indicates maximum size this instance can hold before it needs to be expanded and rehashed. Calculated using fill factor passed in to constructor.

mTableback to summary
protected ElementId[] mTable

Actual hash table area

mTailback to summary
protected ElementId mTail

Constructor Detail

ElementIdMapback to summary
public ElementIdMap()
ElementIdMapback to summary
public ElementIdMap(int initialSize)

This constructor is mainly used for testing, as it can be sized appropriately to test rehashing etc.

Method Detail

addDefinedback to summary
public ElementId addDefined(char[] buffer, int start, int len, int hash, Location loc, PrefixedName elemName, PrefixedName attrName)

Method called when an id definition is encountered. If so, need to check if specified id entry (ref or definiton) exists. If not, need to add the definition marker. If it does exist, need to 'upgrade it', if it was a reference marker; otherwise need to just return the old entry, and expect caller to check for dups and report the error.

addDefinedback to summary
public ElementId addDefined(String idStr, Location loc, PrefixedName elemName, PrefixedName attrName)
addReferencedback to summary
public ElementId addReferenced(char[] buffer, int start, int len, int hash, Location loc, PrefixedName elemName, PrefixedName attrName)

Method called when a reference to id is encountered. If so, need to check if specified id entry (ref or definiton) exists; and if not, to add a reference marker.

addReferencedback to summary
public ElementId addReferenced(String idStr, Location loc, PrefixedName elemName, PrefixedName attrName)
calcHashback to summary
public static int calcHash(char[] buffer, int start, int len)

Implementation of a hashing method for variable length Strings. Most of the time intention is that this calculation is done by caller during parsing, not here; however, sometimes it needs to be done for parsed "String" too.

Note

identical to com.ctc.wstx.util.SymbolTable#calcHash, although not required to be.

Parameters
len:int

Length of String; has to be at least 1 (caller guarantees this pre-condition)

Annotations
@SuppressWarnings:cast
calcHashback to summary
public static int calcHash(String key)
Annotations
@SuppressWarnings:cast
getFirstUndefinedback to summary
public ElementId getFirstUndefined()
rehashback to summary
private void rehash()

Method called when size (number of entries) of symbol table grows so big that load factor is exceeded. Since size has to remain power of two, arrays will then always be doubled. Main work is really redistributing old entries into new String/Bucket entries.