001 package sysModel.classFile.constantPool;
002
003 import java.util.ArrayList;
004 import java.util.Collection;
005
006 /**
007 * Constant pool.
008 *
009 * @author Mathias Ricken
010 */
011 public class ConstantPool extends ArrayList<APoolInfo> {
012 /**
013 * Constructs an empty constant pool with the specified initial capacity.
014 *
015 * @param initialCapacity the initial capacity of the constant pool.
016 *
017 * @throws IllegalArgumentException if the specified initial capacity is negative
018 */
019 public ConstantPool(int initialCapacity) {
020 super(initialCapacity);
021 }
022
023 /**
024 * Constructs an empty constant pool with an initial capacity of ten.
025 */
026 public ConstantPool() {
027 }
028
029 /**
030 * Constructs a constant pool containing the elements of the specified collection, in the order they are returned
031 * by the collection's iterator. The <tt>ConstantPool</tt> instance has an initial capacity of 110% the size of
032 * the specified collection.
033 *
034 * @param aPoolInfos the collection whose elements are to be placed into this constant pool.
035 *
036 * @throws NullPointerException if the specified collection is null.
037 */
038 public ConstantPool(Collection<? extends APoolInfo> aPoolInfos) {
039 super(aPoolInfos);
040 }
041
042 /**
043 * Return the index of the pool item in the pool.
044 *
045 * @param item item
046 *
047 * @return index
048 */
049 public short indexOf(APoolInfo item) {
050 for(int i = 0; i < size(); i++) {
051 if (item == get(i)) {
052 return (short)i;
053 }
054 }
055 throw new AssertionError("Item not in pool: "+item.toStringVerbose());
056 }
057 }