src.au.id.jericho.lib.html.IntStringHashMap Maven / Gradle / Ivy
Go to download
Jericho HTML Parser is a simple but powerful java library allowing analysis and manipulation of
parts of an HTML document, including some common server-side tags, while reproducing verbatim any
unrecognised or invalid HTML. It also provides high-level HTML form manipulation functions.
// Jericho HTML Parser - Java based library for analysing and manipulating HTML
// Version 1.5
// Copyright (C) 2004 Martin Jericho
// http://jerichohtml.sourceforge.net/
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// http://www.gnu.org/copyleft/lesser.html
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package au.id.jericho.lib.html;
import java.util.*;
/**
* This is an internal class used to efficiently map integers to strings, which is used in the CharacterEntityReference class.
*/
final class IntStringHashMap {
private static final int DEFAULT_INITIAL_CAPACITY=16;
private static final float DEFAULT_LOAD_FACTOR=0.75f;
private transient Entry[] table;
private transient int size;
private int threshold;
private float loadFactor;
public IntStringHashMap(int initialCapacity, float loadFactor) {
int capacity=1;
while (capacity=threshold) resize(2*table.length);
return null;
}
private void resize(int newCapacity) {
Entry[] oldTable=table;
int oldCapacity=oldTable.length;
Entry[] newTable=new Entry[newCapacity];
transfer(newTable);
table=newTable;
threshold=(int)(newCapacity*loadFactor);
}
private void transfer(Entry[] newTable) {
Entry[] src=table;
int newCapacity=newTable.length;
for (int j=0; j0 && (next=table[--index])==null);
}
public boolean hasNext() {
return next!=null;
}
public Entry nextEntry() {
current=next;
if (current==null) throw new NoSuchElementException();
next=current.next;
while (next==null && index>0) next=table[--index];
return current;
}
public void remove() {
throw new UnsupportedOperationException();
}
}
private class ValueIterator extends HashIterator {
public Object next() {
return nextEntry().value;
}
}
private class KeyIterator extends HashIterator {
public Object next() {
return new Integer(nextEntry().key);
}
public int nextKey() {
return nextEntry().key;
}
}
}