Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2008-02-10 07:05:43 +0000
committerSergey Prigogin2008-02-10 07:05:43 +0000
commit8111176e94891e8b4d6f16d726d62c9e215375e7 (patch)
treecf9513875ad6dc42a51d49b42545132c499d6acb /core/org.eclipse.cdt.core/parser
parentd64fdf7905cba56048eb9947524069c78122f57a (diff)
downloadorg.eclipse.cdt-8111176e94891e8b4d6f16d726d62c9e215375e7.tar.gz
org.eclipse.cdt-8111176e94891e8b4d6f16d726d62c9e215375e7.tar.xz
org.eclipse.cdt-8111176e94891e8b4d6f16d726d62c9e215375e7.zip
Added toString method and generics.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/HashTable.java50
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ObjectMap.java76
2 files changed, 77 insertions, 49 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/HashTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/HashTable.java
index ee4e4c1dacc..b757a3d7ead 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/HashTable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/HashTable.java
@@ -25,7 +25,7 @@ public class HashTable implements Cloneable{
return currEntry == -1;
}
- final public int size(){
+ final public int size() {
return currEntry + 1;
}
@@ -47,20 +47,20 @@ public class HashTable implements Cloneable{
}
}
- public Object clone(){
+ public Object clone() {
HashTable newTable = null;
try {
newTable = (HashTable) super.clone();
- } catch ( CloneNotSupportedException e ) {
+ } catch (CloneNotSupportedException e) {
//shouldn't happen because object supports clone.
return null;
}
int size = capacity();
- if( hashTable != null ){
- newTable.hashTable = new int[ size*2 ];
- newTable.nextTable = new int[ size ];
+ if (hashTable != null) {
+ newTable.hashTable = new int[size * 2];
+ newTable.nextTable = new int[size];
System.arraycopy(hashTable, 0, newTable.hashTable, 0, hashTable.length);
System.arraycopy(nextTable, 0, newTable.nextTable, 0, nextTable.length);
}
@@ -79,7 +79,7 @@ public class HashTable implements Cloneable{
if (hashTable == null)
return;
- for( int i = 0; i < capacity(); i++ ){
+ for (int i = 0; i < capacity(); i++) {
hashTable[2*i] = 0;
hashTable[2*i+1] = 0;
nextTable[i] = 0;
@@ -90,11 +90,11 @@ public class HashTable implements Cloneable{
return;
// clear the table (don't call clear() or else the subclasses stuff will be cleared too)
- for( int i = 0; i < capacity(); i++ ){
+ for (int i = 0; i < capacity(); i++) {
hashTable[2*i] = 0;
hashTable[2*i+1] = 0;
nextTable[i] = 0;
- }
+ }
// Need to rehash everything
for (int i = 0; i <= currEntry; ++i) {
linkIntoHashTable(i, hash(i));
@@ -128,7 +128,7 @@ public class HashTable implements Cloneable{
// need to link
int j = hashTable[hash] - 1;
while (nextTable[j] != 0) {
-// if(nextTable[j] - 1 == j) {
+// if (nextTable[j] - 1 == j) {
// break;
// }
j = nextTable[j] - 1;
@@ -144,15 +144,15 @@ public class HashTable implements Cloneable{
}
protected void removeEntry(int i, int hash) {
- if (nextTable == null){
+ if (nextTable == null) {
--currEntry;
return;
}
// Remove the hash entry
- if (hashTable[hash] == i + 1)
+ if (hashTable[hash] == i + 1) {
hashTable[hash] = nextTable[i];
- else {
+ } else {
// find entry pointing to me
int j = hashTable[hash] - 1;
while (nextTable[j] != 0 && nextTable[j] != i + 1)
@@ -165,13 +165,15 @@ public class HashTable implements Cloneable{
System.arraycopy(nextTable, i + 1, nextTable, i, currEntry - i);
// adjust hash and next entries for things that moved
- for (int j = 0; j < hashTable.length; ++j)
+ for (int j = 0; j < hashTable.length; ++j) {
if (hashTable[j] > i + 1)
--hashTable[j];
+ }
- for (int j = 0; j < nextTable.length; ++j)
+ for (int j = 0; j < nextTable.length; ++j) {
if (nextTable[j] > i + 1)
--nextTable[j];
+ }
}
// last entry is now free
@@ -179,21 +181,21 @@ public class HashTable implements Cloneable{
--currEntry;
}
- final public void sort( Comparator c ) {
- if( size() > 1 ){
- quickSort( c, 0, size() - 1 );
+ final public void sort(Comparator<Object> c) {
+ if (size() > 1) {
+ quickSort(c, 0, size() - 1);
rehash();
}
}
- final private void quickSort( Comparator c, int p, int r ){
- if( p < r ){
- int q = partition( c, p, r );
- if( p < q ) quickSort( c, p, q );
- if( ++q < r ) quickSort( c, q, r );
+ final private void quickSort(Comparator<Object> c, int p, int r) {
+ if (p < r) {
+ int q = partition(c, p, r);
+ if (p < q) quickSort(c, p, q);
+ if (++q < r) quickSort(c, q, r);
}
}
- protected int partition( Comparator c, int p, int r ) {
+ protected int partition(Comparator<Object> c, int p, int r) {
throw new UnsupportedOperationException();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ObjectMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ObjectMap.java
index 8c7aef575c6..b91e7c2a951 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ObjectMap.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ObjectMap.java
@@ -23,29 +23,29 @@ import java.util.List;
* @author aniefer
*/
public class ObjectMap extends ObjectTable {
- public static final ObjectMap EMPTY_MAP = new ObjectMap( 0 ){
- public Object clone() { return this; }
- public List toList() { return Collections.EMPTY_LIST; }
- public Object put( Object key, Object value ) { throw new UnsupportedOperationException(); }
+ public static final ObjectMap EMPTY_MAP = new ObjectMap(0) {
+ public Object clone() { return this; }
+ public List<Object> toList() { return Collections.emptyList(); }
+ public Object put(Object key, Object value) { throw new UnsupportedOperationException(); }
};
private Object[] valueTable;
public ObjectMap(int initialSize) {
- super( initialSize );
- valueTable = new Object[ capacity() ];
+ super(initialSize);
+ valueTable = new Object[capacity()];
}
- public Object clone(){
+ public Object clone() {
ObjectMap newMap = (ObjectMap) super.clone();
- newMap.valueTable = new Object[ capacity() ];
+ newMap.valueTable = new Object[capacity()];
System.arraycopy(valueTable, 0, newMap.valueTable, 0, valueTable.length);
return newMap;
}
- final public void clear(){
+ final public void clear() {
super.clear();
- for( int i = 0; i < valueTable.length; i++ ){
+ for(int i = 0; i < valueTable.length; i++) {
valueTable[i] = null;
}
}
@@ -54,7 +54,7 @@ public class ObjectMap extends ObjectTable {
Object[] oldValueTable = valueTable;
valueTable = new Object[size];
System.arraycopy(oldValueTable, 0, valueTable, 0, oldValueTable.length);
- super.resize( size );
+ super.resize(size);
}
public Object put(Object key, Object value) {
@@ -71,15 +71,15 @@ public class ObjectMap extends ObjectTable {
return null;
}
- final public Object getAt( int i ){
- if( i < 0 || i > currEntry )
+ final public Object getAt(int i) {
+ if (i < 0 || i > currEntry)
return null;
return valueTable[i];
}
- final public Object remove( Object key ) {
- if( key == null )
+ final public Object remove(Object key) {
+ if (key == null)
return null;
int i = lookup(key);
if (i < 0)
@@ -101,18 +101,24 @@ public class ObjectMap extends ObjectTable {
super.removeEntry(i);
}
- protected int partition( Comparator c, int p, int r ){
- Object x = keyTable[ p ];
+ @Override
+ protected int partition(Comparator<Object> c, int p, int r) {
+ Object x = keyTable[p];
Object temp = null;
int i = p;
int j = r;
- while( true ){
- while( c.compare( keyTable[ j ], x ) > 0 ){ j--; }
- if( i < j )
- while( c.compare( keyTable[ i ], x ) < 0 ){ i++; }
+ while (true) {
+ while (c.compare(keyTable[j], x) > 0) {
+ j--;
+ }
+ if (i < j) {
+ while (c.compare(keyTable[i], x) < 0) {
+ i++;
+ }
+ }
- if( i < j ){
+ if (i < j) {
temp = keyTable[j];
keyTable[j] = keyTable[i];
keyTable[i] = temp;
@@ -126,9 +132,29 @@ public class ObjectMap extends ObjectTable {
}
}
- public Object [] valueArray(){
- Object [] vals = new Object[ size() ];
- System.arraycopy( valueTable, 0, vals, 0, vals.length );
+ public Object[] valueArray() {
+ Object[] vals = new Object[size()];
+ System.arraycopy(valueTable, 0, vals, 0, vals.length);
return vals;
}
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < size(); i++) {
+ Object key = keyAt(i);
+ if (key != null) {
+ if (sb.length() == 0) {
+ sb.append("{");
+ } else {
+ sb.append(", ");
+ }
+ Object value = valueTable[i];
+ sb.append(String.valueOf(key));
+ sb.append(": ");
+ sb.append(String.valueOf(value));
+ }
+ }
+ sb.append("}");
+ return sb.toString();
+ }
}

Back to the top