Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.jdt.internal.compiler.util;
 
 
 public final class HashtableOfPackage {
 	// to avoid using Enumerations, walk the individual tables skipping nulls
 	public char[] keyTable[];
 
 	public int elementSize// number of elements in the table
 	int threshold;
 public HashtableOfPackage() {
 	this(3); // usually not very large
 }
 public HashtableOfPackage(int size) {
 	this. = 0;
 	this. = size// size represents the expected number of elements
 	int extraRoom = (int) (size * 1.75f);
 	if (this. == extraRoom)
 		extraRoom++;
 	this. = new char[extraRoom][];
 	this. = new PackageBinding[extraRoom];
 }
 public boolean containsKey(char[] key) {
 	int length = this..length,
 		index = CharOperation.hashCode(key) % length;
 	int keyLength = key.length;
 	char[] currentKey;
 	while ((currentKey = this.[index]) != null) {
 		if (currentKey.length == keyLength && CharOperation.equals(currentKeykey))
 			return true;
 		if (++index == length) {
 			index = 0;
 		}
 	}
 	return false;
 }
 public PackageBinding get(char[] key) {
 	int length = this..length,
 		index = CharOperation.hashCode(key) % length;
 	int keyLength = key.length;
 	char[] currentKey;
 	while ((currentKey = this.[index]) != null) {
 		if (currentKey.length == keyLength && CharOperation.equals(currentKeykey))
 			return this.[index];
 		if (++index == length) {
 			index = 0;
 		}
 	}
 	return null;
 }
 public PackageBinding put(char[] keyPackageBinding value) {
 	int length = this..length,
 		index = CharOperation.hashCode(key) % length;
 	int keyLength = key.length;
 	char[] currentKey;
 	while ((currentKey = this.[index]) != null) {
 		if (currentKey.length == keyLength && CharOperation.equals(currentKeykey))
 			return this.[index] = value;
 		if (++index == length) {
 			index = 0;
 		}
 	}
 	this.[index] = key;
 	this.[index] = value;
 
 	// assumes the threshold is never equal to the size of the table
 	if (++this. > this.)
 		rehash();
 	return value;
 }
 private void rehash() {
 	HashtableOfPackage newHashtable = new HashtableOfPackage(this. * 2); // double the number of expected elements
 	char[] currentKey;
 	for (int i = this..length; --i >= 0;)
 		if ((currentKey = this.[i]) != null)
 			newHashtable.put(currentKeythis.[i]);
 
 	this. = newHashtable.keyTable;
 	this. = newHashtable.valueTable;
 	this. = newHashtable.threshold;
 }
 public int size() {
 	return this.;
 }
 public String toString() {
 	String s = ""//$NON-NLS-1$
	for (int i = 0, length = this..lengthi < lengthi++)
		if ((pkg = this.[i]) != null)
			s += pkg.toString() + "\n"//$NON-NLS-1$
	return s;
New to GrepCode? Check out our FAQ X