harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r440871 [2/2] - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/reflect/
Date Wed, 06 Sep 2006 21:08:44 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/reflect/ProxyNameAndTypeCache.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/reflect/ProxyNameAndTypeCache.java?view=diff&rev=440871&r1=440870&r2=440871
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/reflect/ProxyNameAndTypeCache.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/reflect/ProxyNameAndTypeCache.java
Wed Sep  6 14:08:44 2006
@@ -15,82 +15,89 @@
 
 package org.apache.harmony.luni.internal.reflect;
 
-
 class ProxyNameAndTypeCache {
-	int[][] keyTable;
+    int[][] keyTable;
 
-	int[] valueTable;
+    int[] valueTable;
 
-	int elementSize;
+    int elementSize;
 
-	int threshold;
+    int threshold;
 
-	ProxyNameAndTypeCache(int initialCapacity) {
-		if (initialCapacity < 13)
-			initialCapacity = 13;
-		this.elementSize = 0;
-		this.threshold = (int) (initialCapacity * 0.66f);
-		this.keyTable = new int[initialCapacity][];
-		this.valueTable = new int[initialCapacity];
-	}
-
-	int get(int[] key) {
-		int index = hashCode(key);
-		while (keyTable[index] != null) {
-			if (keyTable[index][0] == key[0] && keyTable[index][1] == key[1])
-				return valueTable[index];
-			index = (index + 1) % keyTable.length;
-		}
-		return -1;
-	}
-
-	int hashCode(int[] key) {
-		return (key[0] + key[1]) % keyTable.length;
-	}
-
-	int put(int[] key, int value) {
-		int index = hashCode(key);
-		while (keyTable[index] != null) {
-			if (keyTable[index][0] == key[0] && keyTable[index][1] == key[1])
-				return valueTable[index] = value;
-			index = (index + 1) % keyTable.length;
-		}
-		keyTable[index] = key;
-		valueTable[index] = value;
-
-		// assumes the threshold is never equal to the size of the table
-		if (++elementSize > threshold)
-			rehash();
-		return value;
-	}
-
-	private void rehash() {
-		ProxyNameAndTypeCache newHashtable = new ProxyNameAndTypeCache(
-				keyTable.length * 2);
-		for (int i = keyTable.length; --i >= 0;)
-			if (keyTable[i] != null)
-				newHashtable.put(keyTable[i], valueTable[i]);
-
-		this.keyTable = newHashtable.keyTable;
-		this.valueTable = newHashtable.valueTable;
-		this.threshold = newHashtable.threshold;
-	}
-
-	int size() {
-		return elementSize;
-	}
-
-	public String toString() {
-		int max = size();
-		StringBuffer buf = new StringBuffer();
-		buf.append("{");
-		for (int i = 0; i < max; ++i) {
-			if (keyTable[i] != null)
-				buf.append(keyTable[i]).append("->").append(valueTable[i]);
-			if (i < max)
-				buf.append(", ");
-		}
-		buf.append("}");
-		return buf.toString();
-	}
+    ProxyNameAndTypeCache(int initialCapacity) {
+        if (initialCapacity < 13) {
+            initialCapacity = 13;
+        }
+        this.elementSize = 0;
+        this.threshold = (int) (initialCapacity * 0.66f);
+        this.keyTable = new int[initialCapacity][];
+        this.valueTable = new int[initialCapacity];
+    }
+
+    int get(int[] key) {
+        int index = hashCode(key);
+        while (keyTable[index] != null) {
+            if (keyTable[index][0] == key[0] && keyTable[index][1] == key[1]) {
+                return valueTable[index];
+            }
+            index = (index + 1) % keyTable.length;
+        }
+        return -1;
+    }
+
+    int hashCode(int[] key) {
+        return (key[0] + key[1]) % keyTable.length;
+    }
+
+    int put(int[] key, int value) {
+        int index = hashCode(key);
+        while (keyTable[index] != null) {
+            if (keyTable[index][0] == key[0] && keyTable[index][1] == key[1]) {
+                return valueTable[index] = value;
+            }
+            index = (index + 1) % keyTable.length;
+        }
+        keyTable[index] = key;
+        valueTable[index] = value;
+
+        // assumes the threshold is never equal to the size of the table
+        if (++elementSize > threshold) {
+            rehash();
+        }
+        return value;
+    }
+
+    private void rehash() {
+        ProxyNameAndTypeCache newHashtable = new ProxyNameAndTypeCache(keyTable.length *
2);
+        for (int i = keyTable.length; --i >= 0;) {
+            if (keyTable[i] != null) {
+                newHashtable.put(keyTable[i], valueTable[i]);
+            }
+        }
+
+        this.keyTable = newHashtable.keyTable;
+        this.valueTable = newHashtable.valueTable;
+        this.threshold = newHashtable.threshold;
+    }
+
+    int size() {
+        return elementSize;
+    }
+
+    @Override
+    public String toString() {
+        int max = size();
+        StringBuilder buf = new StringBuilder();
+        buf.append("{");
+        for (int i = 0; i < max; ++i) {
+            if (keyTable[i] != null) {
+                buf.append(keyTable[i]).append("->").append(valueTable[i]);
+            }
+            if (i < max) {
+                buf.append(", ");
+            }
+        }
+        buf.append("}");
+        return buf.toString();
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/reflect/ProxyObjectCache.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/reflect/ProxyObjectCache.java?view=diff&rev=440871&r1=440870&r2=440871
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/reflect/ProxyObjectCache.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/reflect/ProxyObjectCache.java
Wed Sep  6 14:08:44 2006
@@ -15,82 +15,89 @@
 
 package org.apache.harmony.luni.internal.reflect;
 
-
 class ProxyObjectCache {
-	Object keyTable[];
+    Object keyTable[];
 
-	int valueTable[];
+    int valueTable[];
 
-	int elementSize;
+    int elementSize;
 
-	int threshold;
+    int threshold;
 
-	ProxyObjectCache(int initialCapacity) {
-		if (initialCapacity < 13)
-			initialCapacity = 13;
-		this.elementSize = 0;
-		this.threshold = (int) (initialCapacity * 0.66f);
-		this.keyTable = new Object[initialCapacity];
-		this.valueTable = new int[initialCapacity];
-	}
-
-	int get(Object key) {
-		int index = hashCode(key);
-		while (keyTable[index] != null) {
-			if (keyTable[index].equals(key))
-				return valueTable[index];
-			index = (index + 1) % keyTable.length;
-		}
-		return -1;
-	}
-
-	int hashCode(Object key) {
-		return (key.hashCode() & 0x7FFFFFFF) % keyTable.length;
-	}
-
-	int put(Object key, int value) {
-		int index = hashCode(key);
-		while (keyTable[index] != null) {
-			if (keyTable[index].equals(key))
-				return valueTable[index] = value;
-			index = (index + 1) % keyTable.length;
-		}
-		keyTable[index] = key;
-		valueTable[index] = value;
-
-		// assumes the threshold is never equal to the size of the table
-		if (++elementSize > threshold)
-			rehash();
-		return value;
-	}
-
-	private void rehash() {
-		ProxyObjectCache newHashtable = new ProxyObjectCache(
-				keyTable.length * 2);
-		for (int i = keyTable.length; --i >= 0;)
-			if (keyTable[i] != null)
-				newHashtable.put(keyTable[i], valueTable[i]);
-
-		this.keyTable = newHashtable.keyTable;
-		this.valueTable = newHashtable.valueTable;
-		this.threshold = newHashtable.threshold;
-	}
-
-	int size() {
-		return elementSize;
-	}
-
-	public String toString() {
-		int max = size();
-		StringBuffer buf = new StringBuffer();
-		buf.append("{");
-		for (int i = 0; i < max; ++i) {
-			if (keyTable[i] != null)
-				buf.append(keyTable[i]).append("->").append(valueTable[i]);
-			if (i < max)
-				buf.append(", ");
-		}
-		buf.append("}");
-		return buf.toString();
-	}
+    ProxyObjectCache(int initialCapacity) {
+        if (initialCapacity < 13) {
+            initialCapacity = 13;
+        }
+        this.elementSize = 0;
+        this.threshold = (int) (initialCapacity * 0.66f);
+        this.keyTable = new Object[initialCapacity];
+        this.valueTable = new int[initialCapacity];
+    }
+
+    int get(Object key) {
+        int index = hashCode(key);
+        while (keyTable[index] != null) {
+            if (keyTable[index].equals(key)) {
+                return valueTable[index];
+            }
+            index = (index + 1) % keyTable.length;
+        }
+        return -1;
+    }
+
+    int hashCode(Object key) {
+        return (key.hashCode() & 0x7FFFFFFF) % keyTable.length;
+    }
+
+    int put(Object key, int value) {
+        int index = hashCode(key);
+        while (keyTable[index] != null) {
+            if (keyTable[index].equals(key)) {
+                return valueTable[index] = value;
+            }
+            index = (index + 1) % keyTable.length;
+        }
+        keyTable[index] = key;
+        valueTable[index] = value;
+
+        // assumes the threshold is never equal to the size of the table
+        if (++elementSize > threshold) {
+            rehash();
+        }
+        return value;
+    }
+
+    private void rehash() {
+        ProxyObjectCache newHashtable = new ProxyObjectCache(keyTable.length * 2);
+        for (int i = keyTable.length; --i >= 0;) {
+            if (keyTable[i] != null) {
+                newHashtable.put(keyTable[i], valueTable[i]);
+            }
+        }
+
+        this.keyTable = newHashtable.keyTable;
+        this.valueTable = newHashtable.valueTable;
+        this.threshold = newHashtable.threshold;
+    }
+
+    int size() {
+        return elementSize;
+    }
+
+    @Override
+    public String toString() {
+        int max = size();
+        StringBuilder buf = new StringBuilder();
+        buf.append("{");
+        for (int i = 0; i < max; ++i) {
+            if (keyTable[i] != null) {
+                buf.append(keyTable[i]).append("->").append(valueTable[i]);
+            }
+            if (i < max) {
+                buf.append(", ");
+            }
+        }
+        buf.append("}");
+        return buf.toString();
+    }
 }



Mime
View raw message