FileDocCategorySizeDatePackage
IConstantCollection.javaAPI DocAndroid 1.5 API6631Wed May 06 22:41:16 BST 2009com.vladium.jcd.cls

IConstantCollection

public interface IConstantCollection implements Cloneable, com.vladium.jcd.compiler.IClassFormatOutput
An abstraction of constant pool in .class format. This interface disallows any pool mutation that invalidates already existing pool indices.
author
(C) 2001, Vlad Roubtsov

Fields Summary
Constructors Summary
Methods Summary
public voidaccept(IClassDefVisitor visitor, java.lang.Object ctx)

public intadd(CONSTANT_info constant)
Appends 'constant' to the end of the collection. No duplicate checks are made.

param
constant new constant [may not be null; input unchecked]
return
the pool index of the newly added entry [always positive]

public java.lang.Objectclone()

public intfind(int type, com.vladium.jcd.cls.IConstantCollection$IConstantComparator comparator)
Searches the pool for a matching constant of given type with equality semantics expressed by 'comparator'. This method guarantees that when comparator.equals(c) is called c.type() is 'type'. The cost is O(pool size). When multiple matches exist, the location of the first one found will be returned (chosen in some indeterministic way).

param
type type of constants to filter by [not validated]
param
comparator [may not be null]
return
index of the first found entry [-1 if not found]
throws
IllegalArgumentException if 'comparator' is null

public intfindCONSTANT_Utf8(java.lang.String value)
Convenience method that can lookup CONSTANT_Utf8 entries in O(1) time on average. Note that .class format does not guarantee that all such entries are not duplicated in the pool. When multiple matches exist, the location of the first one found will be returned (chosen in some indeterministic way).

param
value string value on which to match [may not be null]
return
index of the first found entry [-1 if not found]
throws
IllegalArgumentException if 'value' is null

public CONSTANT_infoget(int index)
Returns a CONSTANT_info at a given pool index. Note that 'index' is 1-based [the way an index would be embedded in bytecode instructions]. Note that because CONSTANT_Long and CONSTANT_Double entries occupy two consequitive index slots certain index values inside the valid range can be invalid; use {@link #iterator()} to iterate only over valid entries in a transparent fashion.

param
index constant pool index [must be in [1, size()] range]
return
CONSTANT_info constant pool entry at this index [never null]
throws
IllegalStateException if an attempt is made to reference an invalid slot index
throws
IndexOutOfBoundsException if an attempt is made to reference a slot outside of the valid range

public com.vladium.jcd.cls.IConstantCollection$IConstantIteratoriterator()
Returns a fail-fast iterator over all valid entries in the pool. The resulting object would be invalidated by simultaneous mutation to the underlying collection pool.

return
IConstantIterator iterator over all entries in the collection [never null]

public CONSTANT_infoset(int index, CONSTANT_info constant)
Replaces an existing constant pool entry. A replacement can be made only for a constant of the same width as the constant currently occupying the slot.

param
index constant pool index [must be in [1, size()] range]
param
constant new entry to set [may not be null; input unchecked]
return
CONSTANT_info previous contents at this pool index [never null]
throws
IllegalArgumentException if the new constant's width is different from the current entry's
throws
IllegalStateException if an attempt is made to reference an invalid slot index [see {@link #get(int)}]
throws
IndexOutOfBoundsException if an attempt is made to reference a slot outside of the valid range

public intsize()
Returns the number of CONSTANT_info entries in this collection.

return
the number of constants in this pool [can be 0]