All Downloads are FREE. Search and download functionalities are using the official Maven repository.

au.id.jericho.lib.html.IntStringHashMap Maven / Gradle / Ivy

Go to download

Jericho HTML Parser is a java library allowing analysis and manipulation of parts of an HTML document, including server-side tags, while reproducing verbatim any unrecognised or invalid HTML.

There is a newer version: 3.4
Show newest version
// Jericho HTML Parser - Java based library for analysing and manipulating HTML
// Version 2.3
// Copyright (C) 2006 Martin Jericho
// http://sourceforge.net/projects/jerichohtml/
//
// 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=15;
	private static final float DEFAULT_LOAD_FACTOR=0.75f;
	private transient Entry[] entries; // length must always be a power of 2.
	private transient int size;
	private int threshold;
	private float loadFactor;
	private int bitmask; // always entries.length-1

	public IntStringHashMap(int initialCapacity, final float loadFactor) {
		this.loadFactor=loadFactor;
		int capacity=1;
		while (capacity=threshold) increaseCapacity();
		return null;
	}

	private void increaseCapacity() {
		final int oldCapacity=entries.length;
		final Entry[] oldEntries=entries;
		entries=new Entry[oldCapacity<<1];
		bitmask=entries.length-1;
		for (int i=0; i=0; i--) entries[i]=null;
		size=0;
	}

	public boolean containsValue(final String value) {
		if (value==null) {
			for (int i=bitmask; i>=0; i--)
				for (Entry entry=entries[i]; entry!=null; entry=entry.next)
					if (entry.value==null) return true;
		} else {
			for (int i=bitmask; i>=0; i--)
				for (Entry entry=entries[i]; entry!=null; entry=entry.next)
					if (value.equals(entry.value)) return true;
		}
		return false;
	}

	private static final class Entry {
		final int key;
		String value;
		Entry next;

		public Entry(final int key, final String value, final Entry next) {
			this.key=key;
			this.value=value;
			this.next=next;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy