/* * Return the char array that is in this set and that is equals to the given char array. * Return null if not found. */ public char[] get(char[] array) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length; int index = (CharOperation.hashCode(array) & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { char[] referent; if (CharOperation.equals(array, referent = (char[]) currentValue.get())) { return referent; } if (++index == valuesLength) { index = 0; } } return null; }
public String toString() { StringBuffer buffer = new StringBuffer("{"); // $NON-NLS-1$ for (int i = 0, length = this.values.length; i < length; i++) { HashableWeakReference value = this.values[i]; if (value != null) { char[] ref = (char[]) value.get(); if (ref != null) { buffer.append('\"'); buffer.append(ref); buffer.append("\", "); // $NON-NLS-1$ } } } buffer.append("}"); // $NON-NLS-1$ return buffer.toString(); }
private void addValue(HashableWeakReference value) { char[] array = (char[]) value.get(); if (array == null) return; int valuesLength = this.values.length; int index = (value.hashCode & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { if (CharOperation.equals(array, (char[]) currentValue.get())) { return; } if (++index == valuesLength) { index = 0; } } this.values[index] = value; // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); }
/* * Adds the given char array to this set. * If a char array that is equals to the given char array already exists, do nothing. * Returns the existing char array or the new char array if not found. */ public char[] add(char[] array) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length, index = (CharOperation.hashCode(array) & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { char[] referent; if (CharOperation.equals(array, referent = (char[]) currentValue.get())) { return referent; } if (++index == valuesLength) { index = 0; } } this.values[index] = new HashableWeakReference(array, this.referenceQueue); // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); return array; }