Use java 2 collection classes

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@937 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 6280493dc3
commit e46cf92d68
  1. 117
      jode/jode/util/SimpleSet.java

@ -18,22 +18,24 @@
*/
package jode.util;
import java.util.Dictionary;
import java.util.Enumeration;
///#ifdef JDK12
///import java.util.AbstractSet;
///import java.util.Iterator;
///#endif
public class SimpleSet
///#ifdef JDK12
/// extends AbstractSet
///#endif
implements Cloneable
public class SimpleSet extends AbstractSet implements Cloneable
{
Object[] elementObjects = new Object[2];
Object[] elementObjects;
int count = 0;
public SimpleSet() {
this(2);
}
public SimpleSet(int initialSize) {
elementObjects = new Object[initialSize];
}
public int size() {
return count;
}
@ -56,10 +58,6 @@ public class SimpleSet
return true;
}
public Enumeration elements() {
return new ArrayEnum(count, elementObjects);
}
public Object clone() {
try {
SimpleSet other = (SimpleSet) super.clone();
@ -70,94 +68,25 @@ public class SimpleSet
}
}
///#ifdef JDK12
/// public Iterator iterator() {
/// return new Iterator() {
/// int pos = 0;
///
/// public boolean hasNext() {
/// return pos < count;
/// }
///
/// public Object next() {
/// return elementObjects[pos++];
/// }
///
/// public void remove() {
/// if (pos < count)
/// System.arraycopy(elementObjects, pos,
/// elementObjects, pos-1, count - pos);
/// count--;
/// pos--;
/// }
/// };
/// }
///#else
public Iterator iterator() {
return new Iterator() {
int pos = 0;
public boolean isEmpty() {
return count == 0;
public boolean hasNext() {
return pos < count;
}
public boolean addAll(SimpleSet other) {
boolean changed = false;
for (int i=0; i < other.count; i++) {
changed |= add(other.elementObjects[i]);
}
return changed;
}
public boolean contains(Object element) {
for (int i=0; i < count; i++) {
if (elementObjects[i].equals(element))
return true;
}
return false;
public Object next() {
return elementObjects[pos++];
}
public boolean remove(Object element) {
for (int i=0; i< count; i++) {
if (elementObjects[i].equals(element)) {
public void remove() {
if (pos < count)
System.arraycopy(elementObjects, pos,
elementObjects, pos-1, count - pos);
count--;
if (i < count)
elementObjects[i] = elementObjects[count];
return true;
pos--;
}
};
}
return false;
}
public boolean retainAll(SimpleSet other) {
int low = 0;
for (int high=0; high < count; high++) {
if (other.contains(elementObjects[high]))
elementObjects[low++] = elementObjects[high];
}
if (count == low)
return false;
count = low;
return true;
}
public boolean removeAll(SimpleSet other) {
int low = 0;
for (int high=0; high < count; high++) {
if (!other.contains(elementObjects[high]))
elementObjects[low++] = elementObjects[high];
}
if (count == low)
return false;
count = low;
return true;
}
public String toString() {
StringBuffer sb = new StringBuffer("{");
String komma = "";
for (int i=0; i< count; i++) {
sb.append(komma).append(elementObjects[i].toString());
komma = ", ";
}
return sb.append("}").toString();
}
///#endif
}

Loading…
Cancel
Save