0

私は独自の Hash クラスを作成し、それを使用して (String, LinkedList(String)) ペアを (K,V) ペアとして格納しました。プログラムを呼び出してハッシュを埋めると、反復子で ArrayOutOfBoundsException がスローされます。配列を必要以上に大きくしようとしましたが、それでも同じエラーが発生します。エラーがスローされる行は「nodes[j++] = n;」です。

abstract class IteratorHelper<E> implements Iterator<E> {
    public DictionaryNode<K,V>[] nodes;
    protected int index;
    protected long modCheck;

    public IteratorHelper() {
        nodes = new DictionaryNode[currentSize];
        index = 0;
        int j = 0;
        modCheck = modCounter;
        System.out.println("int currentSize = " + currentSize);
        System.out.println("int tableSize = " + tableSize);
        for(int i=0; i<tableSize; i++)
            for(DictionaryNode n : list[i]) {
                System.out.println("int j = " + j);
                System.out.println("DictionaryNode key at nodes[" + j + "] = " + n.key);
                nodes[j++] = n;
            }
        nodes = (DictionaryNode<K,V>[]) Sorter.quickSort(nodes);
    }

    public boolean hasNext() {
        if(modCheck != modCounter)
            throw new ConcurrentModificationException();
        return index < currentSize;
    }

    public abstract E next();

    public void remove() {
        throw new UnsupportedOperationException();
    }

}

class KeyIteratorHelper<K> extends IteratorHelper<K> {

    public KeyIteratorHelper() {
        super();
    }

    public K next() {
        return (K) nodes[index++].key;
    }
}

class ValueIteratorHelper<V> extends IteratorHelper<V> {

    public ValueIteratorHelper() {
        super();
    }

    public V next() {
        return (V) nodes[index++].value;
    }
}

}

4

0 に答える 0