diff --git a/jode/configure.in b/jode/configure.in index 4410d5f..a3bc1cc 100644 --- a/jode/configure.in +++ b/jode/configure.in @@ -89,15 +89,18 @@ JODE_CHECK_CLASS(java.lang.Object, $CLASSLIB, AC_MSG_CHECKING(for collection classes) JODE_CHECK_CLASS(java.util.Set, $CLASSPATH:$CLASSLIB, - [ COLLECTIONS="java.util" ], + [ COLLECTIONS="java.util" + COLLECTIONEXTRA="java.lang" ], [ JODE_CHECK_CLASS(com.sun.java.util.collections.Set, $CLASSPATH:$CLASSLIB, - [ COLLECTIONS="com.sun.java.util.collections" ], + [ COLLECTIONS="com.sun.java.util.collections" + COLLECTIONEXTRA="com.sun.java.util.collections" ], [ AC_MSG_RESULT(no) AC_MSG_ERROR(You need the Java 1.2 collection classes in your classpath) ]) ] ) AC_MSG_RESULT($COLLECTIONS) AC_SUBST(COLLECTIONS) +AC_SUBST(COLLECTIONEXTRA) AC_MSG_CHECKING(for gnu.getopt) JODE_CHECK_CLASS(gnu.getopt.Getopt, $CLASSPATH:$CLASSLIB, @@ -136,9 +139,44 @@ jode/obfuscator/Makefile jode/swingui/Makefile jode/type/Makefile jode/util/Makefile -jode/GlobalOptions.java +jode/bytecode/BinaryInfo.java +jode/bytecode/BytecodeInfo.java +jode/bytecode/ClassInfo.java +jode/decompiler/ImportHandler.java +jode/decompiler/MethodAnalyzer.java +jode/expr/Expression.java +jode/expr/InvokeOperator.java +jode/expr/Operator.java +jode/expr/CheckNullOperator.java +jode/flow/RetBlock.java +jode/flow/InstructionContainer.java +jode/flow/LoopBlock.java +jode/flow/SequentialBlock.java +jode/flow/SlotSet.java +jode/flow/StructuredBlock.java +jode/flow/SynchronizedBlock.java +jode/flow/VariableSet.java +jode/flow/CatchBlock.java +jode/flow/IfThenElseBlock.java +jode/flow/InstructionBlock.java +jode/flow/FlowBlock.java +jode/flow/TransformExceptionHandlers.java +jode/obfuscator/TranslationTable.java +jode/obfuscator/Main.java +jode/obfuscator/FieldIdentifier.java +jode/obfuscator/Identifier.java +jode/obfuscator/NameSwapper.java +jode/obfuscator/PackageIdentifier.java +jode/obfuscator/ClassBundle.java +jode/obfuscator/ConstantAnalyzer.java +jode/obfuscator/LocalIdentifier.java +jode/obfuscator/MethodIdentifier.java +jode/obfuscator/ClassIdentifier.java jode/swingui/Main.java jode/swingui/PackagesTreeModel.java +jode/util/SimpleSet.java +jode/util/SimpleMap.java +jode/GlobalOptions.java bin/Makefile bin/jode doc/Makefile diff --git a/jode/jode/bytecode/BinaryInfo.java b/jode/jode/bytecode/BinaryInfo.java.in similarity index 97% rename from jode/jode/bytecode/BinaryInfo.java rename to jode/jode/bytecode/BinaryInfo.java.in index 258ecd8..c4ddb15 100644 --- a/jode/jode/bytecode/BinaryInfo.java +++ b/jode/jode/bytecode/BinaryInfo.java.in @@ -26,13 +26,8 @@ import java.io.IOException; import java.io.InputStream; import jode.util.SimpleMap; -///#ifdef JDK12 -///import java.util.Map; -///import java.util.Iterator; -///#else -import jode.util.Map; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Map; +import @COLLECTIONS@.Iterator; /** diff --git a/jode/jode/bytecode/BytecodeInfo.java b/jode/jode/bytecode/BytecodeInfo.java.in similarity index 99% rename from jode/jode/bytecode/BytecodeInfo.java rename to jode/jode/bytecode/BytecodeInfo.java.in index d23a296..b88699f 100644 --- a/jode/jode/bytecode/BytecodeInfo.java +++ b/jode/jode/bytecode/BytecodeInfo.java.in @@ -29,15 +29,9 @@ import java.util.Vector; import java.util.Enumeration; import java.util.NoSuchElementException; -///#ifdef JDK12 -///import java.util.Collection; -///import java.util.AbstractCollectoin; -///import java.util.Iterator; -///#else -import jode.util.Collection; -import jode.util.AbstractCollection; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.AbstractCollection; +import @COLLECTIONS@.Iterator; /** diff --git a/jode/jode/bytecode/ClassInfo.java b/jode/jode/bytecode/ClassInfo.java deleted file mode 100644 index 1a2489e..0000000 --- a/jode/jode/bytecode/ClassInfo.java +++ /dev/null @@ -1,785 +0,0 @@ -/* ClassInfo Copyright (C) 1998-1999 Jochen Hoenicke. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ - */ - -package jode.bytecode; -import jode.GlobalOptions; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Enumeration; -///#ifdef JDK12 -///import java.util.Map; -///import java.util.HashMap; -///import java.lang.ref.WeakReference; -///import java.lang.ref.ReferenceQueue; -///#else -import java.util.Hashtable; -///#endif -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -/** - * This class does represent a class similar to java.lang.Class. You - * can get the super class and the interfaces. - * - * The main difference to java.lang.Class is, that the objects are builded - * from a stream containing the .class file, and that it uses the - * Type to represent types instead of Class itself. - * - * @author Jochen Hoenicke - */ -public class ClassInfo extends BinaryInfo { - - private static SearchPath classpath; -///#ifdef JDK12 -/// private static final Map classes = new HashMap(); -/// private static final ReferenceQueue queue = new ReferenceQueue(); -///#else - private static final Hashtable classes = new Hashtable(); -///#endif - - private int status = 0; - - private boolean modified = false; - - private int modifiers = -1; - private String name; - private ClassInfo superclass; - private ClassInfo[] interfaces; - private FieldInfo[] fields; - private MethodInfo[] methods; - private InnerClassInfo[] outerClasses; - private InnerClassInfo[] innerClasses; - private InnerClassInfo[] extraClasses; - private String sourceFile; - - public final static ClassInfo javaLangObject = forName("java.lang.Object"); - - public static void setClassPath(String path) { - classpath = new SearchPath(path); -///#ifdef JDK12 -/// java.lang.ref.Reference died; -/// while ((died = queue.poll()) != null) { -/// classes.values().remove(died); -/// } -/// Iterator i = classes.values().iterator(); -/// while (i.hasNext()) { -/// ClassInfo ci = (ClassInfo) ((WeakReference)i.next()).get(); -/// if (ci == null) { -/// i.remove(); -/// continue; -/// } -///#else - Enumeration enum = classes.elements(); - while (enum.hasMoreElements()) { - ClassInfo ci = (ClassInfo) enum.nextElement(); -///#endif - ci.status = 0; - ci.superclass = null; - ci.fields = null; - ci.interfaces = null; - ci.methods = null; - ci.removeAllAttributes(); - } - } - - public static boolean exists(String name) { - return classpath.exists(name.replace('.', '/') + ".class"); - } - - public static boolean isPackage(String name) { - return classpath.isDirectory(name.replace('.', '/')); - } - - public static Enumeration getClassesAndPackages(final String packageName) { - final Enumeration enum = - classpath.listFiles(packageName.replace('.','/')); - return new Enumeration() { - public boolean hasMoreElements() { - return enum.hasMoreElements(); - } - public Object nextElement() { - String name = (String) enum.nextElement(); - if (!name.endsWith(".class")) - // This is a package - return name; - return name.substring(0, name.length()-6); - - } - }; - } - - public static ClassInfo forName(String name) { - if (name == null - || name.indexOf(';') != -1 - || name.indexOf('[') != -1 - || name.indexOf('/') != -1) - throw new IllegalArgumentException("Illegal class name: "+name); - -///#ifdef JDK12 -/// java.lang.ref.Reference died; -/// while ((died = queue.poll()) != null) { -/// classes.values().remove(died); -/// } -/// WeakReference ref = (WeakReference) classes.get(name); -/// ClassInfo clazz = (ref == null) ? null : (ClassInfo) ref.get(); -///#else - ClassInfo clazz = (ClassInfo) classes.get(name); -///#endif - if (clazz == null) { - clazz = new ClassInfo(name); -///#ifdef JDK12 -/// classes.put(name, new WeakReference(clazz, queue)); -///#else - classes.put(name, clazz); -///#endif - } - return clazz; - } - - private ClassInfo(String name) { - this.name = name; - } - - protected void readAttribute(String name, int length, - ConstantPool cp, - DataInputStream input, - int howMuch) throws IOException { - if ((howMuch & ALL_ATTRIBUTES) != 0 && name.equals("SourceFile")) { - if (length != 2) - throw new ClassFormatException("SourceFile attribute" - + " has wrong length"); - sourceFile = cp.getUTF8(input.readUnsignedShort()); - } else if ((howMuch & (OUTERCLASSES | INNERCLASSES)) != 0 - && name.equals("InnerClasses")) { - int count = input.readUnsignedShort(); - int innerCount = 0, outerCount = 0, extraCount = 0; - InnerClassInfo[] innerClassInfo = new InnerClassInfo[count]; - for (int i=0; i< count; i++) { - int innerIndex = input.readUnsignedShort(); - int outerIndex = input.readUnsignedShort(); - int nameIndex = input.readUnsignedShort(); - String inner = cp.getClassName(innerIndex); - String outer = - outerIndex != 0 ? cp.getClassName(outerIndex) : null; - String innername = - nameIndex != 0 ? cp.getUTF8(nameIndex) : null; - int access = input.readUnsignedShort(); - if (innername != null && innername.length() == 0) - innername = null; - InnerClassInfo ici = new InnerClassInfo - (inner, outer, innername, access); - - if (outer != null && outer.equals(getName()) - && innername != null) - innerClassInfo[innerCount++] = ici; - else - innerClassInfo[count - (++extraCount)] = ici; - } - { - String lastOuterName = getName(); - for (int i = count - extraCount; i < count; i++) { - InnerClassInfo ici = innerClassInfo[i]; - if (ici.inner.equals(lastOuterName)) { - for (int j = i; j > count - extraCount; j--) - innerClassInfo[j] = innerClassInfo[j-1]; - innerClassInfo[count-extraCount] = ici; - extraCount--; - outerCount++; - lastOuterName = ici.outer; - } - } - } - if (innerCount > 0) { - innerClasses = new InnerClassInfo[innerCount]; - System.arraycopy(innerClassInfo, 0, - innerClasses, 0, innerCount); - } else - innerClasses = null; - - if (outerCount > 0) { - outerClasses = new InnerClassInfo[outerCount]; - System.arraycopy(innerClassInfo, innerCount, - outerClasses, 0, outerCount); - } else - outerClasses = null; - - if (extraCount > 0) { - extraClasses = new InnerClassInfo[extraCount]; - System.arraycopy(innerClassInfo, innerCount + outerCount, - extraClasses, 0, extraCount); - } else - extraClasses = null; - - if (length != 2 + 8 * count) - throw new ClassFormatException - ("InnerClasses attribute has wrong length"); - } else - super.readAttribute(name, length, cp, input, howMuch); - } - - public void read(DataInputStream input, int howMuch) throws IOException { - /* Since we have to read the whole class anyway, we load all - * info, that we may need later and that does not take much memory. - */ - howMuch |= FIELDS | METHODS | HIERARCHY | INNERCLASSES | OUTERCLASSES; - howMuch &= ~status; - /* header */ - if (input.readInt() != 0xcafebabe) - throw new ClassFormatException("Wrong magic"); - if (input.readUnsignedShort() > 3) - throw new ClassFormatException("Wrong minor"); - if (input.readUnsignedShort() != 45) - throw new ClassFormatException("Wrong major"); - - /* constant pool */ - ConstantPool cpool = new ConstantPool(); - cpool.read(input); - - /* always read modifiers, name, super, ifaces */ - { - modifiers = input.readUnsignedShort(); - String className = cpool.getClassName(input.readUnsignedShort()); - if (!name.equals(className)) - throw new ClassFormatException("wrong name " + className); - String superName = cpool.getClassName(input.readUnsignedShort()); - superclass = superName != null ? ClassInfo.forName(superName) : null; - int count = input.readUnsignedShort(); - interfaces = new ClassInfo[count]; - for (int i=0; i< count; i++) { - interfaces[i] = ClassInfo.forName - (cpool.getClassName(input.readUnsignedShort())); - } - status |= HIERARCHY; - } - - /* fields */ - if ((howMuch & (FIELDS | ALL_ATTRIBUTES)) != 0) { - int count = input.readUnsignedShort(); - if ((howMuch & FIELDS) != 0) - fields = new FieldInfo[count]; - for (int i=0; i< count; i++) { - if ((howMuch & FIELDS) != 0) - fields[i] = new FieldInfo(this); - fields[i].read(cpool, input, howMuch); - } - } else { - byte[] skipBuf = new byte[6]; - int count = input.readUnsignedShort(); - for (int i=0; i< count; i++) { - input.readFully(skipBuf); // modifier, name, type - skipAttributes(input); - } - } - - /* methods */ - if ((howMuch & (METHODS | ALL_ATTRIBUTES)) != 0) { - int count = input.readUnsignedShort(); - if ((howMuch & METHODS) != 0) - methods = new MethodInfo[count]; - for (int i=0; i< count; i++) { - if ((howMuch & METHODS) != 0) - methods[i] = new MethodInfo(this); - methods[i].read(cpool, input, howMuch); - } - } else { - byte[] skipBuf = new byte[6]; - int count = input.readUnsignedShort(); - for (int i=0; i< count; i++) { - input.readFully(skipBuf); // modifier, name, type - skipAttributes(input); - } - } - - /* attributes */ - readAttributes(cpool, input, howMuch); - status |= howMuch; - } - - public void reserveSmallConstants(GrowableConstantPool gcp) { - for (int i=0; i < fields.length; i++) - fields[i].reserveSmallConstants(gcp); - - for (int i=0; i < methods.length; i++) - methods[i].reserveSmallConstants(gcp); - } - - public void prepareWriting(GrowableConstantPool gcp) { - gcp.putClassName(name); - gcp.putClassName(superclass.getName()); - for (int i=0; i < interfaces.length; i++) - gcp.putClassName(interfaces[i].getName()); - - for (int i=0; i < fields.length; i++) - fields[i].prepareWriting(gcp); - - for (int i=0; i < methods.length; i++) - methods[i].prepareWriting(gcp); - - if (sourceFile != null) { - gcp.putUTF8("SourceFile"); - gcp.putUTF8(sourceFile); - } - if (outerClasses != null || innerClasses != null - || extraClasses != null) { - gcp.putUTF8("InnerClasses"); - int outerCount = outerClasses != null ? outerClasses.length : 0; - for (int i=outerCount; i-- > 0;) { - gcp.putClassName(outerClasses[i].inner); - if (outerClasses[i].outer != null) - gcp.putClassName(outerClasses[i].outer); - if (outerClasses[i].name != null) - gcp.putUTF8(outerClasses[i].name); - } - int innerCount = innerClasses != null ? innerClasses.length : 0; - for (int i=0; i< innerCount; i++) { - gcp.putClassName(innerClasses[i].inner); - if (innerClasses[i].outer != null) - gcp.putClassName(innerClasses[i].outer); - if (innerClasses[i].name != null) - gcp.putUTF8(innerClasses[i].name); - } - int extraCount = extraClasses != null ? extraClasses.length : 0; - for (int i=0; i< extraCount; i++) { - gcp.putClassName(extraClasses[i].inner); - if (extraClasses[i].outer != null) - gcp.putClassName(extraClasses[i].outer); - if (extraClasses[i].name != null) - gcp.putUTF8(extraClasses[i].name); - } - } - prepareAttributes(gcp); - } - - protected int getKnownAttributeCount() { - int count = 0; - if (sourceFile != null) - count++; - if (innerClasses != null || outerClasses != null - || extraClasses != null) - count++; - return count; - } - - public void writeKnownAttributes(GrowableConstantPool gcp, - DataOutputStream output) - throws IOException { - if (sourceFile != null) { - output.writeShort(gcp.putUTF8("SourceFile")); - output.writeInt(2); - output.writeShort(gcp.putUTF8(sourceFile)); - } - if (outerClasses != null || innerClasses != null - || extraClasses != null) { - output.writeShort(gcp.putUTF8("InnerClasses")); - int outerCount = (outerClasses != null) ? outerClasses.length : 0; - int innerCount = (innerClasses != null) ? innerClasses.length : 0; - int extraCount = (extraClasses != null) ? extraClasses.length : 0; - int count = outerCount + innerCount + extraCount; - output.writeInt(2 + count * 8); - output.writeShort(count); - for (int i=outerCount; i-- > 0; ) { - output.writeShort(gcp.putClassName(outerClasses[i].inner)); - output.writeShort(outerClasses[i].outer != null ? - gcp.putClassName(outerClasses[i].outer) : 0); - output.writeShort(outerClasses[i].name != null ? - gcp.putUTF8(outerClasses[i].name) : 0); - output.writeShort(outerClasses[i].modifiers); - } - for (int i=0; i< innerCount; i++) { - output.writeShort(gcp.putClassName(innerClasses[i].inner)); - output.writeShort(innerClasses[i].outer != null ? - gcp.putClassName(innerClasses[i].outer) : 0); - output.writeShort(innerClasses[i].name != null ? - gcp.putUTF8(innerClasses[i].name) : 0); - output.writeShort(innerClasses[i].modifiers); - } - for (int i=0; i< extraCount; i++) { - output.writeShort(gcp.putClassName(extraClasses[i].inner)); - output.writeShort(extraClasses[i].outer != null ? - gcp.putClassName(extraClasses[i].outer) : 0); - output.writeShort(extraClasses[i].name != null ? - gcp.putUTF8(extraClasses[i].name) : 0); - output.writeShort(extraClasses[i].modifiers); - } - } - } - - public void write(DataOutputStream out) throws IOException { - GrowableConstantPool gcp = new GrowableConstantPool(); - reserveSmallConstants(gcp); - prepareWriting(gcp); - - out.writeInt(0xcafebabe); - out.writeShort(3); - out.writeShort(45); - gcp.write(out); - - out.writeShort(modifiers); - out.writeShort(gcp.putClassName(name)); - out.writeShort(gcp.putClassName(superclass.getName())); - out.writeShort(interfaces.length); - for (int i=0; i < interfaces.length; i++) - out.writeShort(gcp.putClassName(interfaces[i].getName())); - - out.writeShort(fields.length); - for (int i=0; i < fields.length; i++) - fields[i].write(gcp, out); - - out.writeShort(methods.length); - for (int i=0; i < methods.length; i++) - methods[i].write(gcp, out); - - writeAttributes(gcp, out); - } - - public void loadInfoReflection(Class clazz, int howMuch) - throws SecurityException { - if ((howMuch & HIERARCHY) != 0) { - modifiers = clazz.getModifiers(); - if (clazz.getSuperclass() == null) - superclass = null; - else - superclass = ClassInfo.forName - (clazz.getSuperclass().getName()); - Class[] ifaces = clazz.getInterfaces(); - interfaces = new ClassInfo[ifaces.length]; - for (int i=0; i= 0; ) { - String type = TypeSignature.getSignature(fs[i].getType()); - fields[i] = new FieldInfo - (this, fs[i].getName(), type, fs[i].getModifiers()); - } - } - if ((howMuch & METHODS) != 0 && methods == null) { - Method[] ms; - try { - ms = clazz.getDeclaredMethods(); - } catch (SecurityException ex) { - ms = clazz.getMethods(); - GlobalOptions.err.println - ("Could only get public methods of class " - + name + "."); - } - methods = new MethodInfo[ms.length]; - for (int i = ms.length; --i >= 0; ) { - String type = TypeSignature.getSignature - (ms[i].getParameterTypes(), ms[i].getReturnType()); - methods[i] = new MethodInfo - (this, ms[i].getName(), type, ms[i].getModifiers()); - } - } - if ((howMuch & INNERCLASSES) != 0 && innerClasses == null) { - Class[] is; - try { - is = clazz.getDeclaredClasses(); - } catch (SecurityException ex) { - is = clazz.getClasses(); - GlobalOptions.err.println - ("Could only get public methods of class " - + name + "."); - } - if (is.length > 0) { - innerClasses = new InnerClassInfo[is.length]; - for (int i = is.length; --i >= 0; ) { - String inner = is[i].getName(); - int dollar = inner.lastIndexOf('$'); - String name = inner.substring(dollar+1); - innerClasses[i] = new InnerClassInfo - (inner, getName(), name, is[i].getModifiers()); - } - } - } - if ((howMuch & OUTERCLASSES) != 0 && outerClasses == null) { - int count = 0; - Class declarer = clazz.getDeclaringClass(); - while (declarer != null) { - count++; - declarer = declarer.getDeclaringClass(); - } - if (count > 0) { - outerClasses = new InnerClassInfo[count]; - Class current = clazz; - for (int i = 0; i < count; i++) { - declarer = current.getDeclaringClass(); - String name = current.getName(); - int dollar = name.lastIndexOf('$'); - outerClasses[i] = new InnerClassInfo - (name, declarer.getName(), - name.substring(dollar+1), current.getModifiers()); - current = declarer; - } - } - } - status |= howMuch; - } - - public void loadInfo(int howMuch) { - if ((status & howMuch) == howMuch) - return; - if (modified) { - System.err.println("Allocating info 0x" - + Integer.toHexString(howMuch) - + " (status 0x" + Integer.toHexString(status) - + ") in class " + this); - Thread.dumpStack(); - return; - } - try { - DataInputStream input = - new DataInputStream(classpath.getFile(name.replace('.', '/') - + ".class")); - read(input, howMuch); - - } catch (IOException ex) { - String message = ex.getMessage(); - if ((howMuch & ~(FIELDS|METHODS|HIERARCHY - |INNERCLASSES|OUTERCLASSES)) != 0) { - GlobalOptions.err.println - ("Can't read class " + name + "."); - ex.printStackTrace(GlobalOptions.err); - throw new NoClassDefFoundError(name); - } - // Try getting the info through the reflection interface - // instead. - Class clazz = null; - try { - clazz = Class.forName(name); - } catch (ClassNotFoundException ex2) { - } catch (NoClassDefFoundError ex2) { - } - try { - if (clazz != null) { - loadInfoReflection(clazz, howMuch); - return; - } - } catch (SecurityException ex2) { - GlobalOptions.err.println - (ex2+" while collecting info about class " + name + "."); - } - - // Give a warning and ``guess'' the hierarchie, methods etc. - GlobalOptions.err.println - ("Can't read class " + name + ", types may be incorrect. (" - + ex.getClass().getName() - + (message != null ? ": " + message : "") + ")"); - - if ((howMuch & HIERARCHY) != 0) { - modifiers = Modifier.PUBLIC; - if (name.equals("java.lang.Object")) - superclass = null; - else - superclass = javaLangObject; - interfaces = new ClassInfo[0]; - } - if ((howMuch & METHODS) != 0) - methods = new MethodInfo[0]; - if ((howMuch & FIELDS) != 0) - fields = new FieldInfo[0]; - status |= howMuch; - } - } - - public String getName() { - return name; - } - - public String getJavaName() { - /* Don't load attributes for class names not containing a - * dollar sign. - */ - if (name.indexOf('$') == -1) - return getName(); - if (getOuterClasses() != null) { - int last = outerClasses.length-1; - StringBuffer sb = - new StringBuffer(outerClasses[last].outer != null - ? outerClasses[last].outer : "METHOD"); - for (int i=last; i >= 0; i--) - sb.append(".").append(outerClasses[i].name != null - ? outerClasses[i].name : "ANONYMOUS"); - return sb.toString(); - } - return getName(); - } - - public ClassInfo getSuperclass() { - if ((status & HIERARCHY) == 0) - loadInfo(HIERARCHY); - return superclass; - } - - public ClassInfo[] getInterfaces() { - if ((status & HIERARCHY) == 0) - loadInfo(HIERARCHY); - return interfaces; - } - - public int getModifiers() { - if ((status & HIERARCHY) == 0) - loadInfo(HIERARCHY); - return modifiers; - } - - public boolean isInterface() { - return Modifier.isInterface(getModifiers()); - } - - public FieldInfo findField(String name, String typeSig) { - if ((status & FIELDS) == 0) - loadInfo(FIELDS); - for (int i=0; i< fields.length; i++) - if (fields[i].getName().equals(name) - && fields[i].getType().equals(typeSig)) - return fields[i]; - return null; - } - - public MethodInfo findMethod(String name, String typeSig) { - if ((status & METHODS) == 0) - loadInfo(METHODS); - for (int i=0; i< methods.length; i++) - if (methods[i].getName().equals(name) - && methods[i].getType().equals(typeSig)) - return methods[i]; - return null; - } - - public MethodInfo[] getMethods() { - if ((status & METHODS) == 0) - loadInfo(METHODS); - return methods; - } - - public FieldInfo[] getFields() { - if ((status & FIELDS) == 0) - loadInfo(FIELDS); - return fields; - } - - public InnerClassInfo[] getOuterClasses() { - if ((status & OUTERCLASSES) == 0) - loadInfo(OUTERCLASSES); - return outerClasses; - } - - public InnerClassInfo[] getInnerClasses() { - if ((status & INNERCLASSES) == 0) - loadInfo(INNERCLASSES); - return innerClasses; - } - - public InnerClassInfo[] getExtraClasses() { - if ((status & INNERCLASSES) == 0) - loadInfo(INNERCLASSES); - return extraClasses; - } - - public String getSourceFile() { - return sourceFile; - } - - public void setName(String newName) { - name = newName; - modified = true; - } - - public void setSuperclass(ClassInfo newSuper) { - superclass = newSuper; - modified = true; - } - - public void setInterfaces(ClassInfo[] newIfaces) { - interfaces = newIfaces; - modified = true; - } - - public void setModifiers(int newModifiers) { - modifiers = newModifiers; - modified = true; - } - - public void setMethods(MethodInfo[] mi) { - methods = mi; - modified = true; - } - - public void setFields(FieldInfo[] fi) { - fields = fi; - modified = true; - } - - public void setOuterClasses(InnerClassInfo[] oc) { - outerClasses = oc; - modified = true; - } - - public void setInnerClasses(InnerClassInfo[] ic) { - innerClasses = ic; - modified = true; - } - - public void setExtraClasses(InnerClassInfo[] ec) { - extraClasses = ec; - modified = true; - } - - public void setSourceFile(String newSource) { - sourceFile = newSource; - modified = true; - } - - public boolean superClassOf(ClassInfo son) { - while (son != this && son != null) { - son = son.getSuperclass(); - } - return son == this; - } - - public boolean implementedBy(ClassInfo clazz) { - while (clazz != this && clazz != null) { - ClassInfo[] ifaces = clazz.getInterfaces(); - for (int i=0; i< ifaces.length; i++) { - if (implementedBy(ifaces[i])) - return true; - } - clazz = clazz.getSuperclass(); - } - return clazz == this; - } - - public String toString() { - return name; - } -} diff --git a/jode/jode/decompiler/ClassAnalyzer.java b/jode/jode/decompiler/ClassAnalyzer.java index c81b555..44e7913 100644 --- a/jode/jode/decompiler/ClassAnalyzer.java +++ b/jode/jode/decompiler/ClassAnalyzer.java @@ -29,7 +29,6 @@ import jode.bytecode.InnerClassInfo; import jode.bytecode.ConstantPool; import jode.expr.Expression; import jode.expr.ThisOperator; -import jode.expr.ConstructorOperator; import jode.flow.TransformConstructors; import jode.flow.StructuredBlock; diff --git a/jode/jode/decompiler/ImportHandler.java b/jode/jode/decompiler/ImportHandler.java.in similarity index 96% rename from jode/jode/decompiler/ImportHandler.java rename to jode/jode/decompiler/ImportHandler.java.in index 5b8ed9c..cdf771f 100644 --- a/jode/jode/decompiler/ImportHandler.java +++ b/jode/jode/decompiler/ImportHandler.java.in @@ -26,21 +26,12 @@ import jode.type.ArrayType; import jode.type.ClassInterfacesType; import jode.type.NullType; -///#ifdef JDK12 -///import java.util.SortedMap; -///import java.util.TreeMap; -///import java.util.List; -///import java.util.LinkedList; -///import java.util.Comparator; -///import java.util.Iterator; -///#else -import jode.util.SortedMap; -import jode.util.TreeMap; -import jode.util.List; -import jode.util.LinkedList; -import jode.util.Comparator; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.SortedMap; +import @COLLECTIONS@.TreeMap; +import @COLLECTIONS@.List; +import @COLLECTIONS@.LinkedList; +import @COLLECTIONS@.Comparator; +import @COLLECTIONS@.Iterator; import java.io.IOException; import java.util.Hashtable; diff --git a/jode/jode/decompiler/MethodAnalyzer.java b/jode/jode/decompiler/MethodAnalyzer.java.in similarity index 99% rename from jode/jode/decompiler/MethodAnalyzer.java rename to jode/jode/decompiler/MethodAnalyzer.java.in index 515043c..1df0af0 100644 --- a/jode/jode/decompiler/MethodAnalyzer.java +++ b/jode/jode/decompiler/MethodAnalyzer.java.in @@ -53,11 +53,7 @@ import java.io.DataInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; -///#ifdef JDK12 -///import java.util.Map; -///#else -import jode.util.Map; -///#endif +import @COLLECTIONS@.Map; public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer { ImportHandler imports; diff --git a/jode/jode/expr/CheckNullOperator.java b/jode/jode/expr/CheckNullOperator.java.in similarity index 96% rename from jode/jode/expr/CheckNullOperator.java rename to jode/jode/expr/CheckNullOperator.java.in index 1f90207..3f9735f 100644 --- a/jode/jode/expr/CheckNullOperator.java +++ b/jode/jode/expr/CheckNullOperator.java.in @@ -22,11 +22,7 @@ import jode.type.Type; import jode.decompiler.LocalInfo; import jode.decompiler.TabbedPrintWriter; -///#ifdef JDK12 -///import java.util.Collection; -///#else -import jode.util.Collection; -///#endif +import @COLLECTIONS@.Collection; /** * This is a pseudo operator, which represents the check against null diff --git a/jode/jode/expr/Expression.java b/jode/jode/expr/Expression.java.in similarity index 98% rename from jode/jode/expr/Expression.java rename to jode/jode/expr/Expression.java.in index 63c8289..0bd54ae 100644 --- a/jode/jode/expr/Expression.java +++ b/jode/jode/expr/Expression.java.in @@ -22,11 +22,7 @@ import jode.type.Type; import jode.GlobalOptions; import jode.decompiler.TabbedPrintWriter; -///#ifdef JDK12 -///import java.util.Collection; -///#else -import jode.util.Collection; -///#endif +import @COLLECTIONS@.Collection; public abstract class Expression { protected Type type; diff --git a/jode/jode/expr/InvokeOperator.java b/jode/jode/expr/InvokeOperator.java.in similarity index 99% rename from jode/jode/expr/InvokeOperator.java rename to jode/jode/expr/InvokeOperator.java.in index 2b0f89b..ec316c4 100644 --- a/jode/jode/expr/InvokeOperator.java +++ b/jode/jode/expr/InvokeOperator.java.in @@ -34,17 +34,10 @@ import jode.util.SimpleMap; import java.lang.reflect.InvocationTargetException; import java.util.Hashtable; -///#ifdef JDK12 -///import java.util.Collections; -///import java.util.Collection; -///import java.util.Map; -///import java.util.Iterator; -///#else -import jode.util.Collections; -import jode.util.Collection; -import jode.util.Map; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Collections; +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.Map; +import @COLLECTIONS@.Iterator; public final class InvokeOperator extends Operator implements MatchableOperator { diff --git a/jode/jode/expr/Operator.java b/jode/jode/expr/Operator.java.in similarity index 99% rename from jode/jode/expr/Operator.java rename to jode/jode/expr/Operator.java.in index aafb43b..92d154f 100644 --- a/jode/jode/expr/Operator.java +++ b/jode/jode/expr/Operator.java.in @@ -22,11 +22,7 @@ import jode.type.Type; import jode.GlobalOptions; import jode.decompiler.TabbedPrintWriter; -///#ifdef JDK12 -///import java.util.Collection; -///#else -import jode.util.Collection; -///#endif +import @COLLECTIONS@.Collection; public abstract class Operator extends Expression { /* Don't reorder these constants unless you know what you are doing! */ diff --git a/jode/jode/flow/CatchBlock.java b/jode/jode/flow/CatchBlock.java.in similarity index 97% rename from jode/jode/flow/CatchBlock.java rename to jode/jode/flow/CatchBlock.java.in index 716ca9a..43cf256 100644 --- a/jode/jode/flow/CatchBlock.java +++ b/jode/jode/flow/CatchBlock.java.in @@ -26,13 +26,8 @@ import jode.expr.LocalStoreOperator; import jode.expr.StoreInstruction; import jode.util.SimpleSet; -///#ifdef JDK12 -///import java.util.Collections; -///import java.util.Set; -///#else -import jode.util.Collections; -import jode.util.Set; -///#endif +import @COLLECTIONS@.Collections; +import @COLLECTIONS@.Set; /** diff --git a/jode/jode/flow/FlowBlock.java b/jode/jode/flow/FlowBlock.java.in similarity index 99% rename from jode/jode/flow/FlowBlock.java rename to jode/jode/flow/FlowBlock.java.in index 8df16c8..b7c1d25 100644 --- a/jode/jode/flow/FlowBlock.java +++ b/jode/jode/flow/FlowBlock.java.in @@ -18,7 +18,6 @@ */ package jode.flow; -import java.util.*; import jode.GlobalOptions; import jode.AssertError; import jode.decompiler.TabbedPrintWriter; @@ -29,22 +28,11 @@ import jode.expr.CombineableOperator; import jode.util.SimpleMap; import jode.util.SimpleSet; -///#ifdef JDK12 -///import java.util.Map; -///import java.util.Iterator; -///import java.util.Set; -///import java.util.SimpleSet; -///import java.util.ArrayList; -///import java.util.List; -///#else -import jode.util.Map; -import jode.util.Iterator; -import jode.util.Set; -import jode.util.ArrayList; -import jode.util.List; -import jode.util.SimpleSet; -///#endif - +import @COLLECTIONS@.Map; +import @COLLECTIONS@.Iterator; +import @COLLECTIONS@.Set; +import @COLLECTIONS@.ArrayList; +import @COLLECTIONS@.List; /** * A flow block is the structure of which the flow graph consists. A diff --git a/jode/jode/flow/IfThenElseBlock.java b/jode/jode/flow/IfThenElseBlock.java.in similarity index 98% rename from jode/jode/flow/IfThenElseBlock.java rename to jode/jode/flow/IfThenElseBlock.java.in index cf0e95f..96a6b6c 100644 --- a/jode/jode/flow/IfThenElseBlock.java +++ b/jode/jode/flow/IfThenElseBlock.java.in @@ -24,11 +24,7 @@ import jode.expr.Expression; import jode.type.Type; import jode.util.SimpleSet; -///#ifdef JDK12 -///import java.util.Set; -///#else -import jode.util.Set; -///#endif +import @COLLECTIONS@.Set; /** * An IfThenElseBlock is the structured block representing an if diff --git a/jode/jode/flow/InstructionBlock.java b/jode/jode/flow/InstructionBlock.java.in similarity index 98% rename from jode/jode/flow/InstructionBlock.java rename to jode/jode/flow/InstructionBlock.java.in index cdda53e..8738f18 100644 --- a/jode/jode/flow/InstructionBlock.java +++ b/jode/jode/flow/InstructionBlock.java.in @@ -26,11 +26,7 @@ import jode.expr.StoreInstruction; import jode.expr.LocalStoreOperator; import jode.util.SimpleSet; -///#ifdef JDK12 -///import java.util.Set; -///#else -import jode.util.Set; -///#endif +import @COLLECTIONS@.Set; /** * This is the structured block for atomic instructions. diff --git a/jode/jode/flow/InstructionContainer.java b/jode/jode/flow/InstructionContainer.java.in similarity index 97% rename from jode/jode/flow/InstructionContainer.java rename to jode/jode/flow/InstructionContainer.java.in index 17c3fd2..472afac 100644 --- a/jode/jode/flow/InstructionContainer.java +++ b/jode/jode/flow/InstructionContainer.java.in @@ -24,11 +24,7 @@ import jode.expr.InvokeOperator; import jode.expr.LocalVarOperator; import jode.util.SimpleSet; -///#ifdef JDK12 -///import java.util.Set; -///#else -import jode.util.Set; -///#endif +import @COLLECTIONS@.Set; /** * This is a method for block containing a single instruction. diff --git a/jode/jode/flow/LoopBlock.java b/jode/jode/flow/LoopBlock.java.in similarity index 99% rename from jode/jode/flow/LoopBlock.java rename to jode/jode/flow/LoopBlock.java.in index 17e82a9..29d1340 100644 --- a/jode/jode/flow/LoopBlock.java +++ b/jode/jode/flow/LoopBlock.java.in @@ -28,11 +28,7 @@ import jode.expr.LocalStoreOperator; import jode.expr.CombineableOperator; import jode.util.SimpleSet; -///#ifdef JDK12 -///import java.util.Set; -///#else -import jode.util.Set; -///#endif +import @COLLECTIONS@.Set; /** * This is the structured block for an Loop block. diff --git a/jode/jode/flow/RetBlock.java b/jode/jode/flow/RetBlock.java.in similarity index 93% rename from jode/jode/flow/RetBlock.java rename to jode/jode/flow/RetBlock.java.in index 6ee36b3..0823add 100644 --- a/jode/jode/flow/RetBlock.java +++ b/jode/jode/flow/RetBlock.java.in @@ -20,13 +20,8 @@ package jode.flow; import jode.decompiler.LocalInfo; -///#ifdef JDK12 -///import java.util.Collections; -///import java.util.Set; -///#else -import jode.util.Collections; -import jode.util.Set; -///#endif +import @COLLECTIONS@.Collections; +import @COLLECTIONS@.Set; /** * This block represents a ret instruction. A ret instruction is diff --git a/jode/jode/flow/SequentialBlock.java b/jode/jode/flow/SequentialBlock.java.in similarity index 99% rename from jode/jode/flow/SequentialBlock.java rename to jode/jode/flow/SequentialBlock.java.in index 0275692..3598fbd 100644 --- a/jode/jode/flow/SequentialBlock.java +++ b/jode/jode/flow/SequentialBlock.java.in @@ -24,11 +24,7 @@ import jode.expr.LocalStoreOperator; import jode.expr.StoreInstruction; import jode.util.SimpleSet; -///#ifdef JDK12 -///import java.util.Set; -///#else -import jode.util.Set; -///#endif +import @COLLECTIONS@.Set; /** * A sequential block combines exactly two structured blocks to a new diff --git a/jode/jode/flow/SlotSet.java b/jode/jode/flow/SlotSet.java.in similarity index 96% rename from jode/jode/flow/SlotSet.java rename to jode/jode/flow/SlotSet.java.in index 949e992..7acf9b6 100644 --- a/jode/jode/flow/SlotSet.java +++ b/jode/jode/flow/SlotSet.java.in @@ -21,15 +21,9 @@ package jode.flow; import jode.decompiler.LocalInfo; import jode.util.ArrayEnum; -///#ifdef JDK12 -///import java.util.Collection; -///import java.util.AbstractSet; -///import java.util.Iterator; -///#else -import jode.util.Collection; -import jode.util.AbstractSet; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.AbstractSet; +import @COLLECTIONS@.Iterator; /** * This class represents a set of local info, all having different diff --git a/jode/jode/flow/StructuredBlock.java b/jode/jode/flow/StructuredBlock.java.in similarity index 99% rename from jode/jode/flow/StructuredBlock.java rename to jode/jode/flow/StructuredBlock.java.in index dbfdf1e..8d92da9 100644 --- a/jode/jode/flow/StructuredBlock.java +++ b/jode/jode/flow/StructuredBlock.java.in @@ -25,15 +25,9 @@ import jode.decompiler.LocalInfo; import jode.decompiler.Declarable; import jode.util.SimpleSet; -///#ifdef JDK12 -///import java.util.Collections; -///import java.util.Iterator; -///import java.util.Set; -///#else -import jode.util.Collections; -import jode.util.Iterator; -import jode.util.Set; -///#endif +import @COLLECTIONS@.Collections; +import @COLLECTIONS@.Iterator; +import @COLLECTIONS@.Set; /** * A structured block is the building block of the source programm. diff --git a/jode/jode/flow/SynchronizedBlock.java b/jode/jode/flow/SynchronizedBlock.java.in similarity index 97% rename from jode/jode/flow/SynchronizedBlock.java rename to jode/jode/flow/SynchronizedBlock.java.in index 7943a98..be3c331 100644 --- a/jode/jode/flow/SynchronizedBlock.java +++ b/jode/jode/flow/SynchronizedBlock.java.in @@ -23,11 +23,7 @@ import jode.decompiler.TabbedPrintWriter; import jode.expr.Expression; import jode.util.SimpleSet; -///#ifdef JDK12 -///import java.util.Set; -///#else -import jode.util.Set; -///#endif +import @COLLECTIONS@.Set; /** * This class represents a synchronized structured block. diff --git a/jode/jode/flow/TransformExceptionHandlers.java b/jode/jode/flow/TransformExceptionHandlers.java.in similarity index 99% rename from jode/jode/flow/TransformExceptionHandlers.java rename to jode/jode/flow/TransformExceptionHandlers.java.in index ef2cd71..818192d 100644 --- a/jode/jode/flow/TransformExceptionHandlers.java +++ b/jode/jode/flow/TransformExceptionHandlers.java.in @@ -24,18 +24,11 @@ import jode.type.Type; import jode.decompiler.LocalInfo; import jode.expr.*; -///#ifdef JDK12 -///import java.util.TreeSet; -///import java.util.SortedSetSet; -///import java.util.Map; -///import java.util.Iterator; -///#else -import jode.util.TreeSet; -import jode.util.SortedSet; -import jode.util.Map; -import jode.util.Iterator; -import jode.util.Comparable; -///#endif +import @COLLECTIONS@.TreeSet; +import @COLLECTIONS@.SortedSet; +import @COLLECTIONS@.Map; +import @COLLECTIONS@.Iterator; +import @COLLECTIONEXTRA@.Comparable; /** * diff --git a/jode/jode/flow/VariableSet.java b/jode/jode/flow/VariableSet.java.in similarity index 96% rename from jode/jode/flow/VariableSet.java rename to jode/jode/flow/VariableSet.java.in index 1773637..384a3c9 100644 --- a/jode/jode/flow/VariableSet.java +++ b/jode/jode/flow/VariableSet.java.in @@ -21,15 +21,9 @@ package jode.flow; import jode.decompiler.LocalInfo; import jode.util.ArrayEnum; -///#ifdef JDK12 -///import java.util.Collection; -///import java.util.AbstractSet; -///import java.util.Iterator; -///#else -import jode.util.Collection; -import jode.util.AbstractSet; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.AbstractSet; +import @COLLECTIONS@.Iterator; /** * This class represents a set of Variables, which are mainly used in diff --git a/jode/jode/obfuscator/ClassBundle.java b/jode/jode/obfuscator/ClassBundle.java.in similarity index 93% rename from jode/jode/obfuscator/ClassBundle.java rename to jode/jode/obfuscator/ClassBundle.java.in index 013d19b..8442bab 100644 --- a/jode/jode/obfuscator/ClassBundle.java +++ b/jode/jode/obfuscator/ClassBundle.java.in @@ -24,22 +24,17 @@ import jode.bytecode.Reference; import java.io.*; import java.util.zip.ZipOutputStream; +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.Iterator; +import @COLLECTIONS@.Set; +import @COLLECTIONS@.HashSet; +import @COLLECTIONS@.Map; +import @COLLECTIONS@.TreeMap; + ///#ifdef JDK12 -///import java.util.Collection; -///import java.util.Iterator; -///import java.util.Set; -///import java.util.HashSet; -///import java.util.Map; -///import java.util.TreeMap; -///import java.util.WeakHashMap; +///import @COLLECTIONS@.WeakHashMap; ///#else -import jode.util.Collection; -import jode.util.Iterator; -import jode.util.Set; -import jode.util.HashSet; -import jode.util.Map; -import jode.util.TreeMap; -import jode.util.HashMap; +import @COLLECTIONS@.HashMap; ///#endif public class ClassBundle { diff --git a/jode/jode/obfuscator/ClassIdentifier.java b/jode/jode/obfuscator/ClassIdentifier.java.in similarity index 97% rename from jode/jode/obfuscator/ClassIdentifier.java rename to jode/jode/obfuscator/ClassIdentifier.java.in index 86f659b..0aa72c1 100644 --- a/jode/jode/obfuscator/ClassIdentifier.java +++ b/jode/jode/obfuscator/ClassIdentifier.java.in @@ -20,28 +20,17 @@ package jode.obfuscator; import jode.GlobalOptions; import jode.bytecode.*; -///#ifdef JDK12 -///import java.util.Comparator; -///import java.util.Collection; -///import java.util.Collections; -///import java.util.ArrayList; -///import java.util.Arrays; -///import java.util.Iterator; -///import java.util.List; -///import java.util.LinkedList; -///import java.util.Map; -///#else -import jode.util.Comparator; -import jode.util.Collection; -import jode.util.Collections; -import jode.util.ArrayList; -import jode.util.Arrays; -import jode.util.Iterator; -import jode.util.List; -import jode.util.LinkedList; -import jode.util.Map; -import jode.util.UnsupportedOperationException; -///#endif +import @COLLECTIONS@.Comparator; +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.Collections; +import @COLLECTIONS@.ArrayList; +import @COLLECTIONS@.Arrays; +import @COLLECTIONS@.Iterator; +import @COLLECTIONS@.List; +import @COLLECTIONS@.LinkedList; +import @COLLECTIONS@.Map; +import @COLLECTIONS@.Random; +import @COLLECTIONEXTRA@.UnsupportedOperationException; import java.lang.reflect.Modifier; import java.security.MessageDigest; @@ -49,7 +38,6 @@ import java.security.NoSuchAlgorithmException; import java.io.OutputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.Random; public class ClassIdentifier extends Identifier { PackageIdentifier pack; diff --git a/jode/jode/obfuscator/ConstantAnalyzer.java b/jode/jode/obfuscator/ConstantAnalyzer.java.in similarity index 99% rename from jode/jode/obfuscator/ConstantAnalyzer.java rename to jode/jode/obfuscator/ConstantAnalyzer.java.in index d1ac3a7..c25be7a 100644 --- a/jode/jode/obfuscator/ConstantAnalyzer.java +++ b/jode/jode/obfuscator/ConstantAnalyzer.java.in @@ -31,23 +31,13 @@ import java.lang.reflect.Modifier; import java.lang.reflect.InvocationTargetException; import java.util.BitSet; -///#ifdef JDK12 -///import java.util.Arrays; -///import java.util.Collection; -///import java.util.HashSet; -///import java.util.Set; -///import java.util.HashMap; -///import java.util.Map; -///import java.util.Iterator; -///#else -import jode.util.Arrays; -import jode.util.Collection; -import jode.util.HashSet; -import jode.util.Set; -import jode.util.HashMap; -import jode.util.Map; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Arrays; +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.HashSet; +import @COLLECTIONS@.Set; +import @COLLECTIONS@.HashMap; +import @COLLECTIONS@.Map; +import @COLLECTIONS@.Iterator; /** * Analyze the code, assuming every field that is not yet written to diff --git a/jode/jode/obfuscator/FieldIdentifier.java b/jode/jode/obfuscator/FieldIdentifier.java.in similarity index 92% rename from jode/jode/obfuscator/FieldIdentifier.java rename to jode/jode/obfuscator/FieldIdentifier.java.in index cae8bfc..484a826 100644 --- a/jode/jode/obfuscator/FieldIdentifier.java +++ b/jode/jode/obfuscator/FieldIdentifier.java.in @@ -20,19 +20,11 @@ package jode.obfuscator; import java.lang.reflect.Modifier; import jode.bytecode.*; -///#ifdef JDK12 -///import java.util.Collection; -///import java.util.Collections; -///import java.util.Iterator; -///import java.util.HashSet; -///import java.util.Map; -///#else -import jode.util.Collection; -import jode.util.Collections; -import jode.util.Iterator; -import jode.util.HashSet; -import jode.util.Map; -///#endif +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.Collections; +import @COLLECTIONS@.Iterator; +import @COLLECTIONS@.HashSet; +import @COLLECTIONS@.Map; public class FieldIdentifier extends Identifier{ diff --git a/jode/jode/obfuscator/Identifier.java b/jode/jode/obfuscator/Identifier.java.in similarity index 97% rename from jode/jode/obfuscator/Identifier.java rename to jode/jode/obfuscator/Identifier.java.in index 95e58a3..fc9f6d7 100644 --- a/jode/jode/obfuscator/Identifier.java +++ b/jode/jode/obfuscator/Identifier.java.in @@ -20,13 +20,8 @@ package jode.obfuscator; import jode.GlobalOptions; import java.io.*; -///#ifdef JDK12 -///import java.util.Map; -///import java.util.Iterator; -///#else -import jode.util.Map; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Map; +import @COLLECTIONS@.Iterator; public abstract class Identifier { /** diff --git a/jode/jode/obfuscator/LocalIdentifier.java b/jode/jode/obfuscator/LocalIdentifier.java.in similarity index 90% rename from jode/jode/obfuscator/LocalIdentifier.java rename to jode/jode/obfuscator/LocalIdentifier.java.in index 3619d2c..5f2f860 100644 --- a/jode/jode/obfuscator/LocalIdentifier.java +++ b/jode/jode/obfuscator/LocalIdentifier.java.in @@ -19,13 +19,8 @@ package jode.obfuscator; -///#ifdef JDK12 -///import java.util.Collections; -///import java.util.Iterator; -///#else -import jode.util.Collections; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Collections; +import @COLLECTIONS@.Iterator; public class LocalIdentifier extends Identifier { String name; diff --git a/jode/jode/obfuscator/Main.java b/jode/jode/obfuscator/Main.java.in similarity index 98% rename from jode/jode/obfuscator/Main.java rename to jode/jode/obfuscator/Main.java.in index a9b88d4..34675d4 100644 --- a/jode/jode/obfuscator/Main.java +++ b/jode/jode/obfuscator/Main.java.in @@ -26,15 +26,9 @@ import java.util.StringTokenizer; import java.lang.reflect.Modifier; import java.io.PrintWriter; import java.io.File; -///#ifdef JDK12 -///import java.util.Collection; -///import java.util.Arrays; -///import java.util.HashSet; -///#else -import jode.util.Collection; -import jode.util.Arrays; -import jode.util.HashSet; -///#endif +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.Arrays; +import @COLLECTIONS@.HashSet; public class Main { public static boolean swapOrder = false; diff --git a/jode/jode/obfuscator/MethodIdentifier.java b/jode/jode/obfuscator/MethodIdentifier.java.in similarity index 96% rename from jode/jode/obfuscator/MethodIdentifier.java rename to jode/jode/obfuscator/MethodIdentifier.java.in index 6216487..76aa2e5 100644 --- a/jode/jode/obfuscator/MethodIdentifier.java +++ b/jode/jode/obfuscator/MethodIdentifier.java.in @@ -23,15 +23,9 @@ import jode.GlobalOptions; import jode.bytecode.*; import jode.type.Type; -///#ifdef JDK12 -///import java.util.Collections; -///import java.util.Iterator; -///import java.util.Map; -///#else -import jode.util.Collections; -import jode.util.Iterator; -import jode.util.Map; -///#endif +import @COLLECTIONS@.Collections; +import @COLLECTIONS@.Iterator; +import @COLLECTIONS@.Map; ///#ifdef JDK12 ///import java.lang.ref.SoftReference; diff --git a/jode/jode/obfuscator/NameSwapper.java b/jode/jode/obfuscator/NameSwapper.java.in similarity index 91% rename from jode/jode/obfuscator/NameSwapper.java rename to jode/jode/obfuscator/NameSwapper.java.in index a21e636..a437d12 100644 --- a/jode/jode/obfuscator/NameSwapper.java +++ b/jode/jode/obfuscator/NameSwapper.java.in @@ -20,17 +20,10 @@ package jode.obfuscator; import java.util.Random; -///#ifdef JDK12 -///import java.util.Collection; -///import java.util.Set; -///import java.util.HashSet; -///import java.util.Iterator; -///#else -import jode.util.Collection; -import jode.util.Set; -import jode.util.HashSet; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Collection; +import @COLLECTIONS@.Set; +import @COLLECTIONS@.HashSet; +import @COLLECTIONS@.Iterator; public class NameSwapper implements Renamer { diff --git a/jode/jode/obfuscator/PackageIdentifier.java b/jode/jode/obfuscator/PackageIdentifier.java.in similarity index 98% rename from jode/jode/obfuscator/PackageIdentifier.java rename to jode/jode/obfuscator/PackageIdentifier.java.in index 2957c35..32b305c 100644 --- a/jode/jode/obfuscator/PackageIdentifier.java +++ b/jode/jode/obfuscator/PackageIdentifier.java.in @@ -29,15 +29,9 @@ import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -///#ifdef JDK12 -///import java.util.Map; -///import java.util.HashMap; -///import java.util.Iterator; -///#else -import jode.util.Map; -import jode.util.HashMap; -import jode.util.Iterator; -///#endif +import @COLLECTIONS@.Map; +import @COLLECTIONS@.HashMap; +import @COLLECTIONS@.Iterator; public class PackageIdentifier extends Identifier { ClassBundle bundle; diff --git a/jode/jode/obfuscator/TranslationTable.java b/jode/jode/obfuscator/TranslationTable.java.in similarity index 90% rename from jode/jode/obfuscator/TranslationTable.java rename to jode/jode/obfuscator/TranslationTable.java.in index 63d765b..40d8574 100644 --- a/jode/jode/obfuscator/TranslationTable.java +++ b/jode/jode/obfuscator/TranslationTable.java.in @@ -19,15 +19,12 @@ package jode.obfuscator; -///#ifdef JDK12 -///import java.util.Map; -///import java.util.TreeMap; -///import java.util.Iterator; -///#else -import jode.util.Comparator; -import jode.util.Map; -import jode.util.TreeMap; -import jode.util.Iterator; +import @COLLECTIONS@.Map; +import @COLLECTIONS@.TreeMap; +import @COLLECTIONS@.Iterator; + +///#ifndef JDK12 +import @COLLECTIONS@.Comparator; ///#endif import java.io.InputStream; diff --git a/jode/jode/swingui/PackagesTreeModel.java.in b/jode/jode/swingui/PackagesTreeModel.java.in index f27467f..c791b22 100644 --- a/jode/jode/swingui/PackagesTreeModel.java.in +++ b/jode/jode/swingui/PackagesTreeModel.java.in @@ -26,22 +26,13 @@ import @JAVAX_SWING@.tree.TreePath; import @JAVAX_SWING@.event.TreeModelListener; import @JAVAX_SWING@.event.TreeModelEvent; -///#ifndef JDK12 -///import java.util.Arrays; -///import java.util.TreeSet; -///import java.util.HashSet; -///import java.util.Set; -///import java.util.HashMap; -///import java.util.Map; -///#else -import jode.util.Comparable; -import jode.util.Arrays; -import jode.util.TreeSet; -import jode.util.HashSet; -import jode.util.Set; -import jode.util.HashMap; -import jode.util.Map; -///#endif +import @COLLECTIONEXTRA@.Comparable; +import @COLLECTIONS@.Arrays; +import @COLLECTIONS@.TreeSet; +import @COLLECTIONS@.HashSet; +import @COLLECTIONS@.Set; +import @COLLECTIONS@.HashMap; +import @COLLECTIONS@.Map; import java.util.Enumeration; diff --git a/jode/jode/util/AbstractCollection.java b/jode/jode/util/AbstractCollection.java deleted file mode 100644 index 2853ad5..0000000 --- a/jode/jode/util/AbstractCollection.java +++ /dev/null @@ -1,337 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// AbstractCollection.java -- Abstract implementation of most of Collection -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -package jode.util; - -import java.lang.reflect.Array; - -/** - * A basic implementation of most of the methods in the Collection interface to - * make it easier to create a collection. To create an unmodifiable Collection, - * just subclass AbstractCollection and provide implementations of the - * iterator() and size() methods. The Iterator returned by iterator() need only - * provide implementations of hasNext() and next() (that is, it may throw an - * UnsupportedOperationException if remove() is called). To create a modifiable - * Collection, you must in addition provide an implementation of the - * add(Object) method and the Iterator returned by iterator() must provide an - * implementation of remove(). Other methods should be overridden if the - * backing data structure allows for a more efficient implementation. The - * precise implementation used by AbstractCollection is documented, so that - * subclasses can tell which methods could be implemented more efficiently. - */ -public abstract class AbstractCollection implements Collection { - - /** - * Return an Iterator over this collection. The iterator must provide the - * hasNext and next methods and should in addition provide remove if the - * collection is modifiable. - */ - public abstract Iterator iterator(); - - /** - * Return the number of elements in this collection. - */ - public abstract int size(); - - /** - * Add an object to the collection. This implementation always throws an - * UnsupportedOperationException - it should be overridden if the collection - * is to be modifiable. - * - * @param o the object to add - * @return true if the add operation caused the Collection to change - * @exception UnsupportedOperationException if the add operation is not - * supported on this collection - */ - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - /** - * Add all the elements of a given collection to this collection. This - * implementation obtains an Iterator over the given collection and iterates - * over it, adding each element with the add(Object) method (thus this method - * will fail with an UnsupportedOperationException if the add method does). - * - * @param c the collection to add the elements of to this collection - * @return true if the add operation caused the Collection to change - * @exception UnsupportedOperationException if the add operation is not - * supported on this collection - */ - public boolean addAll(Collection c) { - Iterator i = c.iterator(); - boolean modified = false; - while (i.hasNext()) { - modified |= add(i.next()); - } - return modified; - } - - /** - * Remove all elements from the collection. This implementation obtains an - * iterator over the collection and calls next and remove on it repeatedly - * (thus this method will fail with an UnsupportedOperationException if the - * Iterator's remove method does) until there are no more elements to remove. - * Many implementations will have a faster way of doing this. - * - * @exception UnsupportedOperationException if the Iterator returned by - * iterator does not provide an implementation of remove - */ - public void clear() { - Iterator i = iterator(); - while (i.hasNext()) { - i.next(); - i.remove(); - } - } - - /** - * Test whether this collection contains a given object. That is, if the - * collection has an element e such that (o == null ? e == null : - * o.equals(e)). This implementation obtains an iterator over the collection - * and iterates over it, testing each element for equality with the given - * object. If it is equal, true is returned. Otherwise false is returned when - * the end of the collection is reached. - * - * @param o the object to remove from this collection - * @return true if this collection contains an object equal to o - */ - public boolean contains(Object o) { - Iterator i = iterator(); - - // This looks crazily inefficient, but it takes the test o==null outside - // the loop, saving time, and also saves needing to store the result of - // i.next() each time. - if (o == null) { - while (i.hasNext()) { - if (i.next() == null) { - return true; - } - } - } else { - while (i.hasNext()) { - if (o.equals(i.next())) { - return true; - } - } - } - return false; - } - - /** - * Tests whether this collection contains all the elements in a given - * collection. This implementation iterates over the given collection, - * testing whether each element is contained in this collection. If any one - * is not, false is returned. Otherwise true is returned. - * - * @param c the collection to test against - * @return true if this collection contains all the elements in the given - * collection - */ - public boolean containsAll(Collection c) { - Iterator i = c.iterator(); - while (i.hasNext()) { - if (!contains(i.next())) { - return false; - } - } - return true; - } - - /** - * Test whether this collection is empty. This implementation returns - * size() == 0. - * - * @return true if this collection is empty. - */ - public boolean isEmpty() { - return size() == 0; - } - - /** - * Remove a single instance of an object from this collection. That is, - * remove one element e such that (o == null ? e == null : o.equals(e)), if - * such an element exists. This implementation obtains an iterator over the - * collection and iterates over it, testing each element for equality with - * the given object. If it is equal, it is removed by the iterator's remove - * method (thus this method will fail with an UnsupportedOperationException - * if the Iterator's remove method does). After the first element has been - * removed, true is returned; if the end of the collection is reached, false - * is returned. - * - * @param o the object to remove from this collection - * @return true if the remove operation caused the Collection to change, or - * equivalently if the collection did contain o. - * @exception UnsupportedOperationException if this collection's Iterator - * does not support the remove method - */ - public boolean remove(Object o) { - Iterator i = iterator(); - - // This looks crazily inefficient, but it takes the test o==null outside - // the loop, saving time, and also saves needing to store the result of - // i.next() each time. - if (o == null) { - while (i.hasNext()) { - if (i.next() == null) { - i.remove(); - return true; - } - } - } else { - while (i.hasNext()) { - if (o.equals(i.next())) { - i.remove(); - return true; - } - } - } - return false; - } - - /** - * Remove from this collection all its elements that are contained in a given - * collection. This implementation iterates over this collection, and for - * each element tests if it is contained in the given collection. If so, it - * is removed by the Iterator's remove method (thus this method will fail - * with an UnsupportedOperationException if the Iterator's remove method - * does). - * - * @param c the collection to remove the elements of - * @return true if the remove operation caused the Collection to change - * @exception UnsupportedOperationException if this collection's Iterator - * does not support the remove method - */ - public boolean removeAll(Collection c) { - Iterator i = iterator(); - boolean changed = false; - while (i.hasNext()) { - if (c.contains(i.next())) { - i.remove(); - changed = true; - } - } - return changed; - } - - /** - * Remove from this collection all its elements that are not contained in a - * given collection. This implementation iterates over this collection, and - * for each element tests if it is contained in the given collection. If not, - * it is removed by the Iterator's remove method (thus this method will fail - * with an UnsupportedOperationException if the Iterator's remove method - * does). - * - * @param c the collection to retain the elements of - * @return true if the remove operation caused the Collection to change - * @exception UnsupportedOperationException if this collection's Iterator - * does not support the remove method - */ - public boolean retainAll(Collection c) { - Iterator i = iterator(); - boolean changed = false; - while (i.hasNext()) { - if (!c.contains(i.next())) { - i.remove(); - changed = true; - } - } - return changed; - } - - /** - * Return an array containing the elements of this collection. This - * implementation creates an Object array of size size() and then iterates - * over the collection, setting each element of the array from the value - * returned by the iterator. - * - * @return an array containing the elements of this collection - */ - public Object[] toArray() { - Object[] a = new Object[size()]; - Iterator i = iterator(); - for (int pos = 0; pos < a.length; pos++) { - a[pos] = i.next(); - } - return a; - } - - /** - * Copy the collection into a given array if it will fit, or into a - * dynamically created array of the same run-time type as the given array if - * not. If there is space remaining in the array, the first element after the - * end of the collection is set to null (this is only useful if the - * collection is known to contain no null elements, however). This - * implementation first tests whether the given array is large enough to hold - * all the elements of the collection. If not, the reflection API is used to - * allocate a new array of the same run-time type. Next an iterator is - * obtained over the collection and the elements are placed in the array as - * they are returned by the iterator. Finally the first spare element, if - * any, of the array is set to null, and the created array is returned. - * - * @param a the array to copy into, or of the correct run-time type - * @return the array that was produced - * @exception ClassCastException if the type of the array precludes holding - * one of the elements of the Collection - */ - public Object[] toArray(Object[] a) { - final int n = size(); - if (a.length < n) { - a = (Object[])Array.newInstance(a.getClass().getComponentType(), n); - } - Iterator i = iterator(); - for (int pos = 0; pos < n; pos++) { - a[pos] = i.next(); - } - if (a.length > n) { - a[n] = null; - } - return a; - } - - /** - * Creates a String representation of the Collection. The string returned is - * of the form "[a, b, ...]" where a and b etc are the results of calling - * toString on the elements of the collection. This implementation obtains an - * Iterator over the Collection and adds each element to a StringBuffer as it - * is returned by the iterator. - * - * @return a String representation of the Collection - */ - public String toString() { - StringBuffer s = new StringBuffer(); - s.append('['); - Iterator i = iterator(); - boolean more = i.hasNext(); - while(more) { - s.append(i.next()); - if (more = i.hasNext()) { - s.append(", "); - } - } - s.append(']'); - return s.toString(); - } -} diff --git a/jode/jode/util/AbstractList.java b/jode/jode/util/AbstractList.java deleted file mode 100644 index 4a71e34..0000000 --- a/jode/jode/util/AbstractList.java +++ /dev/null @@ -1,560 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// AbstractList.java -- Abstract implementation of most of List -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Doc comments for almost everything. -// ~ Better general commenting - -package jode.util; -import java.util.NoSuchElementException; - -/** - * A basic implementation of most of the methods in the List interface to make - * it easier to create a List based on a random-access data structure. To - * create an unmodifiable list, it is only necessary to override the size() and - * get(int) methods (this contrasts with all other abstract collection classes - * which require an iterator to be provided). To make the list modifiable, the - * set(int, Object) method should also be overridden, and to make the list - * resizable, the add(int, Object) and remove(int) methods should be overridden - * too. Other methods should be overridden if the backing data structure allows - * for a more efficient implementation. The precise implementation used by - * AbstractList is documented, so that subclasses can tell which methods could - * be implemented more efficiently. - */ -public abstract class AbstractList extends AbstractCollection implements List { - - /** - * A count of the number of structural modifications that have been made to - * the list (that is, insertions and removals). - */ - protected transient int modCount = 0; - - public abstract Object get(int index); - - public void add(int index, Object o) { - throw new UnsupportedOperationException(); - } - - public boolean add(Object o) { - add(size(), o); - return true; - } - - public boolean addAll(int index, Collection c) { - Iterator i = c.iterator(); - if (i.hasNext()) { - do { - add(index++, i.next()); - } while (i.hasNext()); - return true; - } else { - return false; - } - } - - public void clear() { - removeRange(0, size()); - } - - public boolean equals(Object o) { - if (o == this) { - return true; - } else if (!(o instanceof List)) { - return false; - } else { - Iterator i1 = iterator(); - Iterator i2 = ((List)o).iterator(); - while (i1.hasNext()) { - if (!i2.hasNext()) { - return false; - } else { - Object e = i1.next(); - if (e == null ? i2.next() != null : !e.equals(i2.next())) { - return false; - } - } - } - if (i2.hasNext()) { - return false; - } else { - return true; - } - } - } - - public int hashCode() { - int hashCode = 1; - Iterator i = iterator(); - while (i.hasNext()) { - Object obj = i.next(); - hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode()); - } - return hashCode; - } - - public int indexOf(Object o) { - int index = 0; - ListIterator i = listIterator(); - if (o == null) { - while (i.hasNext()) { - if (i.next() == null) { - return index; - } - index++; - } - } else { - while (i.hasNext()) { - if (o.equals(i.next())) { - return index; - } - index++; - } - } - return -1; - } - - public Iterator iterator() { - return new Iterator() { - private int knownMod = modCount; - private int position = 0; - boolean removed = true; - - private void checkMod() { - if (knownMod != modCount) { - throw new ConcurrentModificationException(); - } - } - - public boolean hasNext() { - checkMod(); - return position < size(); - } - - public Object next() { - checkMod(); - removed = false; - try { - return get(position++); - } catch (IndexOutOfBoundsException e) { - throw new NoSuchElementException(); - } - } - - public void remove() { - checkMod(); - if (removed) { - throw new IllegalStateException(); - } - AbstractList.this.remove(--position); - knownMod = modCount; - removed = true; - } - }; - } - - public int lastIndexOf(Object o) { - int index = size(); - ListIterator i = listIterator(index); - if (o == null) { - while (i.hasPrevious()) { - if (i.previous() == null) { - return index; - } - index--; - } - } else { - while (i.hasPrevious()) { - if (o.equals(i.previous())) { - return index; - } - index--; - } - } - return -1; - } - - public ListIterator listIterator() { - return listIterator(0); - } - - public ListIterator listIterator(final int index) { - - if (index < 0 || index > size()) { - throw new IndexOutOfBoundsException(); - } - - return new ListIterator() { - private int knownMod = modCount; - private int position = index; - private int lastReturned = -1; - - private void checkMod() { - if (knownMod != modCount) { - throw new ConcurrentModificationException(); - } - } - - public boolean hasNext() { - checkMod(); - return position < size(); - } - - public boolean hasPrevious() { - checkMod(); - return position > 0; - } - - public Object next() { - checkMod(); - if (hasNext()) { - lastReturned = position++; - return get(lastReturned); - } else { - throw new NoSuchElementException(); - } - } - - public Object previous() { - checkMod(); - if (hasPrevious()) { - lastReturned = --position; - return get(lastReturned); - } else { - throw new NoSuchElementException(); - } - } - - public int nextIndex() { - checkMod(); - return position; - } - - public int previousIndex() { - checkMod(); - return position - 1; - } - - public void remove() { - checkMod(); - if (lastReturned < 0) { - throw new IllegalStateException(); - } - AbstractList.this.remove(lastReturned); - knownMod = modCount; - position = lastReturned; - lastReturned = -1; - } - - public void set(Object o) { - checkMod(); - if (lastReturned < 0) { - throw new IllegalStateException(); - } - AbstractList.this.set(lastReturned, o); - } - - public void add(Object o) { - checkMod(); - AbstractList.this.add(position++, o); - lastReturned = -1; - knownMod = modCount; - } - }; - } - - public Object remove(int index) { - throw new UnsupportedOperationException(); - } - - /** - * Remove a subsection of the list. This is called by the clear and - * removeRange methods of the class which implements subList, which are - * difficult for subclasses to override directly. Therefore, this method - * should be overridden instead by the more efficient implementation, if one - * exists. - *

- * This implementation first checks for illegal or out of range arguments. It - * then obtains a ListIterator over the list using listIterator(fromIndex). - * It then calls next() and remove() on this iterator repeatedly, toIndex - - * fromIndex times. - * - * @param fromIndex the index, inclusive, to remove from. - * @param toIndex the index, exclusive, to remove to. - * @exception UnsupportedOperationException if this list does not support - * the removeRange operation. - * @exception IndexOutOfBoundsException if fromIndex > toIndex || fromIndex < - * 0 || toIndex > size(). - */ - protected void removeRange(int fromIndex, int toIndex) { - if (fromIndex > toIndex) { - throw new IllegalArgumentException(); - } else if (fromIndex < 0 || toIndex > size()) { - throw new IndexOutOfBoundsException(); - } else { - ListIterator i = listIterator(fromIndex); - for (int index = fromIndex; index < toIndex; index++) { - i.next(); - i.remove(); - } - } - } - - public Object set(int index, Object o) { - throw new UnsupportedOperationException(); - } - - private static class SubList extends AbstractList { - - // Note that within this class two fields called modCount are inherited - - // one from the superclass, and one from the backing class. These are - // explicitly disambiguated in the code by referring to "this.modCount" - // and "backing.modCount". - // The code uses both these two fields and *no other* to provide fail-fast - // behaviour. For correct operation, the two fields should contain equal - // values. Therefore, if this.modCount != backing.modCount, there - // has been a concurrent modification. This is all achieved purely by using - // the modCount field, precisely according to the docs of AbstractList. - // See the methods upMod and checkMod. - - // Jikes doesn't want to access outer instance with AbstractList.this, - // since this is an AbstractList, too. I therefor changed class to static - // and do it by hand. This makes it a lot clearer by the way. - private AbstractList backing; - private final int offset; - private int size; - - SubList(AbstractList backing, int fromIndex, int toIndex) { - this.backing = backing; - this.offset = fromIndex; - this.size = toIndex - fromIndex; - - upMod(); - } - - /** - * This method checks the two modCount fields to ensure that there has - * not been a concurrent modification. It throws an exception if there - * has been, and otherwise returns normally. - * Note that since this method is private, it will be inlined. - * - * @exception ConcurrentModificationException if there has been a - * concurrent modification. - */ - private void checkMod() { - if (modCount != backing.modCount) { - throw new ConcurrentModificationException(); - } - } - - /** - * This method is called after every method that causes a structural - * modification to the backing list. It updates the local modCount field - * to match that of the backing list. - * Note that since this method is private, it will be inlined. - */ - private void upMod() { - modCount = backing.modCount; - } - - /** - * This method checks that a value is between 0 and size (inclusive). If - * it is not, an exception is thrown. - * Note that since this method is private, it will be inlined. - * - * @exception IndexOutOfBoundsException if the value is out of range. - */ - private void checkBoundsInclusive(int index) { - if (index < 0 || index > size) { - throw new IndexOutOfBoundsException(); - } - } - - /** - * This method checks that a value is between 0 (inclusive) and size - * (exclusive). If it is not, an exception is thrown. - * Note that since this method is private, it will be inlined. - * - * @exception IndexOutOfBoundsException if the value is out of range. - */ - private void checkBoundsExclusive(int index) { - if (index < 0 || index >= size) { - throw new IndexOutOfBoundsException(); - } - } - - public int size() { - checkMod(); - return size; - } - - public Iterator iterator() { - return listIterator(); - } - - public ListIterator listIterator(final int index) { - - checkMod(); - checkBoundsInclusive(index); - - return new ListIterator() { - ListIterator i = backing.listIterator(index + offset); - int position = index; - - public boolean hasNext() { - checkMod(); - return position < size; - } - - public boolean hasPrevious() { - checkMod(); - return position > 0; - } - - public Object next() { - if (position < size) { - Object o = i.next(); - position++; - return o; - } else { - throw new NoSuchElementException(); - } - } - - public Object previous() { - if (position > 0) { - Object o = i.previous(); - position--; - return o; - } else { - throw new NoSuchElementException(); - } - } - - public int nextIndex() { - return offset + i.nextIndex(); - } - - public int previousIndex() { - return offset + i.previousIndex(); - } - - public void remove() { - i.remove(); - upMod(); - size--; - position = nextIndex(); - } - - public void set(Object o) { - i.set(o); - } - - public void add(Object o) { - i.add(o); - upMod(); - size++; - position++; - } - - // Here is the reason why the various modCount fields are mostly - // ignored in this wrapper listIterator. - // IF the backing listIterator is failfast, then the following holds: - // Using any other method on this list will call a corresponding - // method on the backing list *after* the backing listIterator - // is created, which will in turn cause a ConcurrentModException - // when this listIterator comes to use the backing one. So it is - // implicitly failfast. - // If the backing listIterator is NOT failfast, then the whole of - // this list isn't failfast, because the modCount field of the - // backing list is not valid. It would still be *possible* to - // make the iterator failfast wrt modifications of the sublist - // only, but somewhat pointless when the list can be changed under - // us. - // Either way, no explicit handling of modCount is needed. - // However upMod() must be called in add and remove, and size - // must also be updated in these two methods, since they do not go - // through the corresponding methods of the subList. - - }; - } - - public Object set(int index, Object o) { - checkMod(); - checkBoundsExclusive(index); - o = backing.set(index + offset, o); - upMod(); - return o; - } - - public Object get(int index) { - checkMod(); - checkBoundsExclusive(index); - return backing.get(index + offset); - } - - public void add(int index, Object o) { - checkMod(); - checkBoundsInclusive(index); - backing.add(index + offset, o); - upMod(); - size++; - } - - public Object remove(int index) { - checkMod(); - checkBoundsExclusive(index); - Object o = backing.remove(index + offset); - upMod(); - size--; - return o; - } - - public void removeRange(int fromIndex2, int toIndex2) { - checkMod(); - checkBoundsExclusive(fromIndex2); - checkBoundsInclusive(toIndex2); - - // this call will catch the toIndex2 < fromIndex2 condition - backing.removeRange(offset + fromIndex2, offset + toIndex2); - upMod(); - size -= toIndex2 - fromIndex2; - } - - public boolean addAll(int index, Collection c) { - checkMod(); - checkBoundsInclusive(index); - int s = backing.size(); - boolean result = backing.addAll(offset + index, c); - upMod(); - size += backing.size() - s; - return result; - } - } - - public List subList(final int fromIndex, final int toIndex) { - return new SubList(this, fromIndex, toIndex); - } - -} diff --git a/jode/jode/util/AbstractMap.java b/jode/jode/util/AbstractMap.java deleted file mode 100644 index fd57b75..0000000 --- a/jode/jode/util/AbstractMap.java +++ /dev/null @@ -1,280 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// AbstractMap.java -- Abstract implementation of most of Map -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com), -// Free Software Foundation, Inc. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// comments -// test suite - -package jode.util; - -public abstract class AbstractMap implements Map { - - public void clear() - { - entrySet().clear(); - } - - public boolean containsKey( Object key ) - { - Object k; - Iterator entries = entrySet().iterator(); - - while( entries.hasNext() ) - { - k = ((Map.Entry)entries.next()).getKey(); - if( key == null ? k == null : key.equals( k ) ) - return true; - } - - return false; - } - - public boolean containsValue( Object value ) - { - Object v; - Iterator entries = entrySet().iterator(); - - while( entries.hasNext() ) - { - v = ((Map.Entry)entries.next()).getValue(); - if( value == null ? v == null : value.equals( v ) ) - return true; - } - - return false; - } - - public abstract Set entrySet(); - - public boolean equals( Object o ) - { - if( this == o ) - return true; - - if( o == null || !( o instanceof Map ) ) - return false; - - Map m = (Map)o; - if( m.size() != size() ) - return false; - - Object key, value1, value2; - Map.Entry entry; - Iterator entries = entrySet().iterator(); - while( entries.hasNext() ) - { - entry = (Map.Entry)entries.next(); - key = entry.getKey(); - value1 = entry.getValue(); - value2 = m.get( key ); - - if( !( ( value1 == null && value2 == null ) - || value1.equals( value2 ) ) ) - return false; - } - - return true; - } - - public Object get( Object key ) - { - Object k; - Map.Entry entry; - Iterator entries = entrySet().iterator(); - - while( entries.hasNext() ) - { - entry = (Map.Entry)entries.next(); - k = entry.getKey(); - if( key == null ? k == null : key.equals( k ) ) - return entry.getValue(); - } - - return null; - } - - public int hashCode() - { - int hashcode = 0; - Iterator entries = entrySet().iterator(); - - while( entries.hasNext() ) - hashcode += entries.next().hashCode(); - - return hashcode; - } - - public boolean isEmpty() - { - return size() == 0; - } - - public Set keySet() - { - if( this.keySet == null ) - { - this.keySet = - new AbstractSet() - { - public int size() - { - return AbstractMap.this.size(); - } - - public boolean contains(Object key) - { - return AbstractMap.this.containsKey(key); - } - - public Iterator iterator() - { - return new Iterator() - { - Iterator map_iterator = AbstractMap.this.entrySet().iterator(); - - public boolean hasNext() - { - return map_iterator.hasNext(); - } - - public Object next() - { - return ((Map.Entry)map_iterator.next()).getKey(); - } - - public void remove() - { - map_iterator.remove(); - } - }; - } - }; - } - - return this.keySet; - } - - public Object put( Object key, Object value ) - { - throw new UnsupportedOperationException(); - } - - public void putAll( Map m ) - { - Map.Entry entry; - Iterator entries = m.entrySet().iterator(); - while( entries.hasNext() ) - { - entry = (Map.Entry)entries.next(); - put( entry.getKey(), entry.getValue() ); - } - } - - public Object remove( Object key ) - { - Object k, value; - Map.Entry entry; - Iterator entries = entrySet().iterator(); - - while( entries.hasNext() ) - { - entry = (Map.Entry)entries.next(); - k = entry.getKey(); - if( key == null ? k == null : key.equals( k ) ) - { - value = entry.getValue(); - entries.remove(); - return value; - } - } - - return null; - } - - public int size() - { - return entrySet().size(); - } - - public String toString() - { - Map.Entry entry; - String rep = "AbstractMap< "; - Iterator entries = entrySet().iterator(); - - while( entries.hasNext() ) - { - entry = (Map.Entry)entries.next(); - rep += entry.getKey() + " -> " + entry.getValue() + ", "; - } - - return rep.substring( 0, rep.length() - 2 ) + " >"; - } - - public Collection values() - { - if( this.valueCollection == null ) - { - this.valueCollection = - new AbstractCollection() - { - public int size() - { - return AbstractMap.this.size(); - } - - public Iterator iterator() - { - return new Iterator() - { - Iterator map_iterator = AbstractMap.this.entrySet().iterator(); - - public boolean hasNext() - { - return map_iterator.hasNext(); - } - - public Object next() - { - return ((Map.Entry)map_iterator.next()).getValue(); - } - - public void remove() - { - map_iterator.remove(); - } - }; - } - }; - } - - return this.valueCollection; - } - - - private Collection valueCollection = null; - private Set keySet = null; -} diff --git a/jode/jode/util/AbstractSequentialList.java b/jode/jode/util/AbstractSequentialList.java deleted file mode 100644 index 03aa06e..0000000 --- a/jode/jode/util/AbstractSequentialList.java +++ /dev/null @@ -1,111 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// AbstractSequentialList.java -- List implementation for sequential access -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Lots of doc comments still missing. -// ~ The class comment should include a description of what should be overridden -// to provide what features, as should the listIterator comment. - -package jode.util; - -/** - * Abstract superclass to make it easier to implement the List interface when - * backed by a sequential-access store, such as a linked list. - */ -public abstract class AbstractSequentialList extends AbstractList { - - /** - * Returns a ListIterator over the list, starting from position index. - * Subclasses must provide an implementation of this method. - * - * @exception IndexOutOfBoundsException if index < 0 || index > size() - */ - public abstract ListIterator listIterator(int index); - - /** - * Add an element to the list at a given index. This implementation obtains a - * ListIterator positioned at the specified index, and then adds the element - * using the ListIterator's add method. - * - * @param index the position to add the element - * @param o the element to insert - * @exception IndexOutOfBoundsException if index < 0 || index > size() - * @exception UnsupportedOperationException if the iterator returned by - * listIterator(index) does not support the add method. - */ - public void add(int index, Object o) { - ListIterator i = listIterator(index); - i.add(o); - } - - public boolean addAll(int index, Collection c) { - boolean changed = false; - Iterator ci = c.iterator(); - ListIterator i = listIterator(index); - while (ci.hasNext()) { - i.add(ci.next()); - changed = true; - } - return changed; - } - - public Object get(int index) { - ListIterator i = listIterator(index); - if (!i.hasNext()) { - throw new IndexOutOfBoundsException(); - } - return i.next(); - } - - /** - * Return an Iterator over this List. This implementation returns - * listIterator(). - * - * @return an Iterator over this List - */ - public Iterator iterator() { - return listIterator(); - } - - public Object remove(int index) { - ListIterator i = listIterator(index); - if (!i.hasNext()) { - throw new IndexOutOfBoundsException(); - } - Object removed = i.next(); - i.remove(); - return removed; - } - - public Object set(int index, Object o) { - ListIterator i = listIterator(index); - if (!i.hasNext()) { - throw new IndexOutOfBoundsException(); - } - Object old = i.next(); - i.set(o); - return old; - } -} diff --git a/jode/jode/util/AbstractSet.java b/jode/jode/util/AbstractSet.java deleted file mode 100644 index cc99633..0000000 --- a/jode/jode/util/AbstractSet.java +++ /dev/null @@ -1,78 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// AbstractSet.java -- Abstract implementation of most of Set -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -package jode.util; - -/** - * An abstract implementation of Set to make it easier to create your own - * implementations. In order to create a Set, subclass AbstractSet and - * implement the same methods that are required for AbstractCollection - * (although these methods must of course meet the requirements that Set puts - * on them - specifically, no element may be in the set more than once). This - * class simply provides implementations of equals() and hashCode() to fulfil - * the requirements placed on them by the Set interface. - */ -public abstract class AbstractSet extends AbstractCollection implements Set { - - /** - * Tests whether the given object is equal to this Set. This implementation - * first checks whether this set is the given object, and returns - * true if so. Otherwise, if o is a Set and is the same size as this one, it - * returns the result of calling containsAll on the given Set. Otherwise, it - * returns false. - * - * @param o the Object to be tested for equality with this Set - * @return true if the given object is equal to this Set - */ - public boolean equals(Object o) { - if (o == this) { - return true; - } else if (o instanceof Set && ((Set)o).size() == size()) { - return containsAll((Collection)o); - } else { - return false; - } - } - - /** - * Returns a hash code for this Set. The hash code of a Set is the sum of the - * hash codes of all its elements, except that the hash code of null is - * defined to be zero. This implementation obtains an Iterator over the Set, - * and sums the results. - * - * @return a hash code for this Set - */ - public int hashCode() { - int hash = 0; - Iterator i = iterator(); - while (i.hasNext()) { - try { - hash += i.next().hashCode(); - } catch (NullPointerException e) { - } - } - return hash; - } -} diff --git a/jode/jode/util/ArrayList.java b/jode/jode/util/ArrayList.java deleted file mode 100644 index 845d10d..0000000 --- a/jode/jode/util/ArrayList.java +++ /dev/null @@ -1,489 +0,0 @@ -// This class is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// ArrayList.java -- JDK1.2's answer to Vector; this is an array-backed -// implementation of the List interface -// -// This is a JDK 1.2 compliant version of ArrayList.java -// -// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com), -// Free Software Foundation, Inc. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// -package jode.util; - -import java.lang.reflect.Array; -import java.io.Serializable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -/** - * An array-backed implementation of the List interface. ArrayList - * performs well on simple tasks: random access into a list, appending - * to or removing from the end of a list, checking the size, &c. - * - * @author Jon A. Zeppieri - * @version $Id$ - * @see java.util.AbstractList - * @see java.util.List - */ -public class ArrayList extends AbstractList - implements List, Cloneable, Serializable -{ - /** the default capacity for new ArrayLists */ - private static final int DEFAULT_CAPACITY = 16; - - /** the number of elements in this list */ - int size; - - /** where the data is stored */ - transient Object[] _arData; - - /** - * Construct a new ArrayList with the supplied initial capacity. - * - * @param iCapacity - */ - public ArrayList(int iCapacity) - { - _arData = new Object[iCapacity]; - } - - - /** - * Construct a new ArrayList with the default capcity - */ - public ArrayList() - { - this(DEFAULT_CAPACITY); - } - - /** - * Construct a new ArrayList, and initialize it with the elements - * in the supplied Collection; Sun specs say that the initial - * capacity is 110% of the Collection's size. - * - * @param oCollection the collection whose elements will - * initialize this list - */ - public ArrayList(Collection oCollection) - { - this((int) (oCollection.size() * 1.1)); - addAll(oCollection); - } - - /** - * Guarantees that this list will have at least enough capacity to - * hold iMinCapacity elements. - * - * @param iMinCapacity the minimum guaranteed capacity - */ - public void ensureCapacity(int iMinCapacity) - { - Object[] arNewData; - int iCapacity = _arData.length; - - if (iMinCapacity > iCapacity) - { - arNewData = new Object[Math.max((iCapacity * 2), iMinCapacity)]; - System.arraycopy(_arData, 0, arNewData, 0, iCapacity); - _arData = arNewData; - } - } - - /** - * Appends the supplied element to the end of this list. - * - * @param oElement the element to be appended to this list - */ - public boolean add(Object oElement) - { - ensureCapacity(size + 1); - _arData[size++] = oElement; - modCount++; - return true; - } - - /** - * Retrieves the element at the user-supplied index. - * - * @param iIndex the index of the element we are fetching - * @throws IndexOutOfBoundsException (iIndex < 0) || (iIndex >= size()) - */ - public Object get(int iIndex) - { - if (iIndex >= size) - throw new IndexOutOfBoundsException("ArrayList size=" + - String.valueOf(size) + "; " + - "index=" + String.valueOf(iIndex)); - return _arData[iIndex]; - } - - /** - * Returns the number of elements in this list - */ - public int size() - { - return size; - } - - /** - * Removes the element at the user-supplied index - * - * @param iIndex the index of the element to be removed - * @return the removed Object - * @throws IndexOutOfBoundsException (iIndex < 0) || (iIndex >= size()) - */ - public Object remove(int iIndex) - { - Object oResult; - - if (iIndex >= size) - throw new IndexOutOfBoundsException("ArrayList size=" + - String.valueOf(size) + "; " + - "index=" + String.valueOf(iIndex)); - - oResult = _arData[iIndex]; - - if (iIndex != --size) - System.arraycopy(_arData, (iIndex + 1), _arData, iIndex, - (size - iIndex)); - - modCount++; - _arData[size] = null; - - return oResult; - } - - /** - * Removes all elements in the half-open interval [iFromIndex, iToIndex). - * - * @param iFromIndex the first index which will be removed - * @param iToIndex one greater than the last index which will be - * removed - */ - public void removeRange(int iFromIndex, int iToIndex) - { - int iReduction; - int i; - - if ((iFromIndex >= size) || (iToIndex >= size)) - { - throw new IndexOutOfBoundsException("ArrayList size=" + - String.valueOf(size) + "; " + - "indices=" + - String.valueOf(iFromIndex) + "," + - String.valueOf(iToIndex)); - } - else if (iFromIndex > iToIndex) - { - throw new IllegalArgumentException("fromIndex(" + - String.valueOf(iFromIndex) + - ") > toIndex(" + - String.valueOf(iToIndex) + ")"); - } - else if (iFromIndex != iToIndex) - { - iReduction = iToIndex - iFromIndex; - System.arraycopy(_arData, (iFromIndex + iReduction), _arData, - iFromIndex, (size - iFromIndex - iReduction)); - modCount++; - - for (i = (iFromIndex + iReduction); i < size; i++) - _arData[i] = null; - - size -= iReduction; - } - } - - /** - * Adds the supplied element at the specified index, shifting all - * elements currently at that index or higher one to the right. - * - * @param iIndex the index at which the element is being added - * @param oElement the element being added - */ - public void add(int iIndex, Object oElement) - { - if (iIndex > size) - throw new IndexOutOfBoundsException("ArrayList size=" + - String.valueOf(size) + "; " + - "index=" + String.valueOf(iIndex)); - - ensureCapacity(size + 1); - System.arraycopy(_arData, iIndex, _arData, - (iIndex + 1), (size - iIndex)); - _arData[iIndex] = oElement; - size++; - modCount++; - } - - /** - * Add each element in the supplied Collection to this List. - * - * @param oCollection a Collection containing elements to be - * added to this List - */ - public boolean addAll(Collection oCollection) - { - Iterator itElements; - int iLen = oCollection.size(); - - if (iLen > 0) - { - ensureCapacity(size + iLen); - modCount++; - - itElements = oCollection.iterator(); - - while (itElements.hasNext()) - _arData[size++] = itElements.next(); - - return true; - } - return false; - } - - /** - * Add all elements in the supplied collection, inserting them beginning - * at the specified index. - * - * @param iIndex the index at which the elements will be inserted - * @param oCollection the Collection containing the elements to be - * inserted - */ - public boolean addAll(int iIndex, Collection oCollection) - { - Iterator itElements; - int iLen; - - if (iIndex > size) - throw new IndexOutOfBoundsException("ArrayList size=" + - String.valueOf(size) + "; " + - "index=" + String.valueOf(iIndex)); - - iLen = oCollection.size(); - - if (iLen > 0) - { - ensureCapacity(size + iLen); - - System.arraycopy(_arData, iIndex, _arData, - (iIndex + iLen), (size - iIndex)); - modCount++; - size += iLen; - - itElements = oCollection.iterator(); - while (itElements.hasNext()) - _arData[iIndex++] = itElements.next(); - - return true; - } - return false; - } - - /** - * Creates a shallow copy of this ArrayList - */ - public Object clone() - { - ArrayList oClone; - - try - { - oClone = (ArrayList) super.clone(); - oClone._arData = _arData; - oClone.size = size; - } - catch(CloneNotSupportedException e) - { - oClone = null; - } - return oClone; - } - - /** - * Returns true iff oElement is in this ArrayList. - * - * @param oElement the element whose inclusion in the List is being - * tested - */ - public boolean contains(Object oElement) - { - return (indexOf(oElement) != -1); - } - - /** - * Returns the lowest index at which oElement appears in this List, or - * -1 if it does not appear. - * - * @param oElement the element whose inclusion in the List is being - * tested - */ - public int indexOf(Object oElement) - { - int i; - - for (i = 0; i < size; i++) - { - if (doesEqual(oElement, _arData[i])) - return i; - } - return -1; - } - - /** - * Returns the highest index at which oElement appears in this List, or - * -1 if it does not appear. - * - * @param oElement the element whose inclusion in the List is being - * tested - */ - public int lastIndexOf(Object oElement) - { - int i; - - for (i = size - 1; i >= 0; i--) - { - if (doesEqual(oElement, _arData[i])) - return i; - } - return -1; - } - - /** - * Removes all elements from this List - */ - public void clear() - { - int i; - - if (size > 0) - { - modCount++; - size = 0; - - for (i = 0; i < size; i++) - _arData[i] = null; - } - } - - /** - * Sets the element at the specified index. - * - * @param iIndex the index at which the element is being set - * @param oElement the element to be set - * @return the element previously at the specified index, or null if - * none was there - */ - public Object set(int iIndex, Object oElement) - { - Object oResult; - - if (iIndex >= size) - throw new IndexOutOfBoundsException("ArrayList size=" + - String.valueOf(size) + "; " + - "index=" + String.valueOf(iIndex)); - oResult = _arData[iIndex]; - modCount++; - _arData[iIndex] = oElement; - - return oResult; - } - - /** - * Returns an Object Array containing all of the elements in this ArrayList - */ - public Object[] toArray() - { - Object[] arObjects = new Object[size]; - System.arraycopy(_arData, 0, arObjects, 0, size); - return arObjects; - } - - /** - * Returns an Array whse component type is the runtime component type of - * the passes-in Array. The returned Array is populated with all of the - * elements in this ArrayList. If the passed-in Array is not large enough - * to store all of the elements in this List, a new Array will be created - * and returned; if the passed-in Array is larger than the size - * of this List, then size() + 1 index will be set to null. - * - * @param arObjects the passed-in Array - */ - public Object[] toArray(Object[] arObjects) - { - Object[] arReturn = (arObjects.length >= size) - ? arObjects - : (Object[]) - Array.newInstance(arObjects.getClass().getComponentType(), size); - - System.arraycopy(_arData, 0, arReturn, 0, size); - - if (arReturn.length > size) - arReturn[size] = null; - - return arReturn; - } - - /** - * Trims the capacity of tjis List to be equal to its size; - * a memory saver. - */ - public void trimToSize() - { - Object[] arNewData = new Object[size]; - System.arraycopy(_arData, 0, arNewData, 0, size); - modCount++; - _arData = arNewData; - } - - private void writeObject(ObjectOutputStream oOut) - throws IOException - { - int i; - - oOut.defaultWriteObject(); - - oOut.writeInt(_arData.length); - for (i = 0; i < _arData.length; i++) - oOut.writeObject(_arData[i]); - } - - private void readObject(ObjectInputStream oIn) - throws IOException, ClassNotFoundException - { - int i; - int iCapacity; - oIn.defaultReadObject(); - - iCapacity = oIn.readInt(); - _arData = new Object[iCapacity]; - - for (i = 0; i < iCapacity; i++) - _arData[i] = oIn.readObject(); - } - - private static final boolean doesEqual(Object oOne, Object oTwo) - { - return ((oOne == null) ? (oTwo == null) : oOne.equals(oTwo)); - } -} - diff --git a/jode/jode/util/Arrays.java b/jode/jode/util/Arrays.java deleted file mode 100644 index 1949ac9..0000000 --- a/jode/jode/util/Arrays.java +++ /dev/null @@ -1,1685 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// Arrays.java -- Utility class with methods to operate on arrays -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Fix the behaviour of sort and binarySearch as applied to float and double -// arrays containing NaN values. See the JDC, bug ID 4143272. - -package jode.util; - -/** - * This class contains various static utility methods performing operations on - * arrays, and a method to provide a List "view" of an array to facilitate - * using arrays with Collection-based APIs. - */ -public class Arrays { - - /** - * This class is non-instantiable. - */ - private Arrays() { - } - - /** - * Perform a binary search of a byte array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(byte[] a, byte key) { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) { - mid = (low + hi) >> 1; - final byte d = a[mid]; - if (d == key) { - return mid; - } else if (d > key) { - hi = mid - 1; - } else { - low = ++mid; // This gets the insertion point right on the last loop - } - } - return -mid - 1; - } - - /** - * Perform a binary search of a char array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(char[] a, char key) { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) { - mid = (low + hi) >> 1; - final char d = a[mid]; - if (d == key) { - return mid; - } else if (d > key) { - hi = mid - 1; - } else { - low = ++mid; // This gets the insertion point right on the last loop - } - } - return -mid - 1; - } - - /** - * Perform a binary search of a double array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(double[] a, double key) { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) { - mid = (low + hi) >> 1; - final double d = a[mid]; - if (d == key) { - return mid; - } else if (d > key) { - hi = mid - 1; - } else { - low = ++mid; // This gets the insertion point right on the last loop - } - } - return -mid - 1; - } - - /** - * Perform a binary search of a float array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(float[] a, float key) { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) { - mid = (low + hi) >> 1; - final float d = a[mid]; - if (d == key) { - return mid; - } else if (d > key) { - hi = mid - 1; - } else { - low = ++mid; // This gets the insertion point right on the last loop - } - } - return -mid - 1; - } - - /** - * Perform a binary search of an int array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(int[] a, int key) { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) { - mid = (low + hi) >> 1; - final int d = a[mid]; - if (d == key) { - return mid; - } else if (d > key) { - hi = mid - 1; - } else { - low = ++mid; // This gets the insertion point right on the last loop - } - } - return -mid - 1; - } - - /** - * Perform a binary search of a long array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(long[] a, long key) { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) { - mid = (low + hi) >> 1; - final long d = a[mid]; - if (d == key) { - return mid; - } else if (d > key) { - hi = mid - 1; - } else { - low = ++mid; // This gets the insertion point right on the last loop - } - } - return -mid - 1; - } - - /** - * Perform a binary search of a short array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(short[] a, short key) { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) { - mid = (low + hi) >> 1; - final short d = a[mid]; - if (d == key) { - return mid; - } else if (d > key) { - hi = mid - 1; - } else { - low = ++mid; // This gets the insertion point right on the last loop - } - } - return -mid - 1; - } - - /** - * Compare two objects with or without a Comparator. If c is null, uses the - * natural ordering. Slightly slower than doing it inline if the JVM isn't - * clever, but worth it for removing a duplicate of the sort and search code. - * Note: This same code is used in Collections - */ - private static int compare(Object o1, Object o2, Comparator c) { - if (c == null) { - return ((Comparable)o1).compareTo(o2); - } else { - return c.compare(o1, o2); - } - } - - /** - * This method does the work for the Object binary search methods. If the - * specified comparator is null, uses the natural ordering. - */ - private static int objectSearch(Object[] a, Object key, final Comparator c) { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) { - mid = (low + hi) >> 1; - final int d = compare(key, a[mid], c); - if (d == 0) { - return mid; - } else if (d < 0) { - hi = mid - 1; - } else { - low = ++mid; // This gets the insertion point right on the last loop - } - } - return -mid - 1; - } - - /** - * Perform a binary search of an Object array for a key, using the natural - * ordering of the elements. The array must be sorted (as by the sort() - * method) - if it is not, the behaviour of this method is undefined, and may - * be an infinite loop. Further, the key must be comparable with every item - * in the array. If the array contains the key more than once, any one of - * them may be found. Note: although the specification allows for an infinite - * loop if the array is unsorted, it will not happen in this (JCL) - * implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - * @exception ClassCastException if key could not be compared with one of the - * elements of a - * @exception NullPointerException if a null element has compareTo called - */ - public static int binarySearch(Object[] a, Object key) { - return objectSearch(a, key, null); - } - - /** - * Perform a binary search of an Object array for a key, using a supplied - * Comparator. The array must be sorted (as by the sort() method with the - * same Comparator) - if it is not, the behaviour of this method is - * undefined, and may be an infinite loop. Further, the key must be - * comparable with every item in the array. If the array contains the key - * more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this (JCL) implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @param c the comparator by which the array is sorted - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - * @exception ClassCastException if key could not be compared with one of the - * elements of a - */ - public static int binarySearch(Object[] a, Object key, Comparator c) { - if (c == null) { - throw new NullPointerException(); - } - return objectSearch(a, key, c); - } - - /** - * Compare two byte arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @returns true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(byte[] a1, byte[] a2) { - - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) { - return true; - } - try { - - // If they're the same length, test each element - if (a1.length == a2.length) { - for (int i = 0; i < a1.length; i++) { - if (a1[i] != a2[i]) { - return false; - } - } - return true; - } - - // If a1 == null or a2 == null but not both then we will get a NullPointer - } catch (NullPointerException e) { - } - - return false; - } - - /** - * Compare two char arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @returns true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(char[] a1, char[] a2) { - - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) { - return true; - } - try { - - // If they're the same length, test each element - if (a1.length == a2.length) { - for (int i = 0; i < a1.length; i++) { - if (a1[i] != a2[i]) { - return false; - } - } - return true; - } - - // If a1 == null or a2 == null but not both then we will get a NullPointer - } catch (NullPointerException e) { - } - - return false; - } - - /** - * Compare two double arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @returns true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(double[] a1, double[] a2) { - - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) { - return true; - } - try { - - // If they're the same length, test each element - if (a1.length == a2.length) { - for (int i = 0; i < a1.length; i++) { - if (a1[i] != a2[i]) { - return false; - } - } - return true; - } - - // If a1 == null or a2 == null but not both then we will get a NullPointer - } catch (NullPointerException e) { - } - - return false; - } - - /** - * Compare two float arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @returns true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(float[] a1, float[] a2) { - - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) { - return true; - } - try { - - // If they're the same length, test each element - if (a1.length == a2.length) { - for (int i = 0; i < a1.length; i++) { - if (a1[i] != a2[i]) { - return false; - } - } - return true; - } - - // If a1 == null or a2 == null but not both then we will get a NullPointer - } catch (NullPointerException e) { - } - - return false; - } - - /** - * Compare two long arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @returns true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(long[] a1, long[] a2) { - - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) { - return true; - } - try { - - // If they're the same length, test each element - if (a1.length == a2.length) { - for (int i = 0; i < a1.length; i++) { - if (a1[i] != a2[i]) { - return false; - } - } - return true; - } - - // If a1 == null or a2 == null but not both then we will get a NullPointer - } catch (NullPointerException e) { - } - - return false; - } - - /** - * Compare two short arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @returns true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(short[] a1, short[] a2) { - - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) { - return true; - } - try { - - // If they're the same length, test each element - if (a1.length == a2.length) { - for (int i = 0; i < a1.length; i++) { - if (a1[i] != a2[i]) { - return false; - } - } - return true; - } - - // If a1 == null or a2 == null but not both then we will get a NullPointer - } catch (NullPointerException e) { - } - - return false; - } - - /** - * Compare two boolean arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @returns true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(boolean[] a1, boolean[] a2) { - - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) { - return true; - } - try { - - // If they're the same length, test each element - if (a1.length == a2.length) { - for (int i = 0; i < a1.length; i++) { - if (a1[i] != a2[i]) { - return false; - } - } - return true; - } - - // If a1 == null or a2 == null but not both then we will get a NullPointer - } catch (NullPointerException e) { - } - - return false; - } - - /** - * Compare two int arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @returns true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(int[] a1, int[] a2) { - - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) { - return true; - } - try { - - // If they're the same length, test each element - if (a1.length == a2.length) { - for (int i = 0; i < a1.length; i++) { - if (a1[i] != a2[i]) { - return false; - } - } - return true; - } - - // If a1 == null or a2 == null but not both then we will get a NullPointer - } catch (NullPointerException e) { - } - - return false; - } - - /** - * Compare two Object arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @returns true if a1 and a2 are both null, or if a1 is of the same length - * as a2, and for each 0 <= i < a.length, a1[i] == null ? a2[i] == null : - * a1[i].equals(a2[i]). - */ - public static boolean equals(Object[] a1, Object[] a2) { - - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) { - return true; - } - try { - - // If they're the same length, test each element - if (a1.length == a2.length) { - for (int i = 0; i < a1.length; i++) { - if (!(a1[i] == null ? a2[i] == null : a1[i].equals(a2[i]))) { - return false; - } - } - return true; - } - - // If a1 == null or a2 == null but not both then we will get a NullPointer - } catch (NullPointerException e) { - } - - return false; - } - - /** - * Fill an array with a boolean value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(boolean[] a, boolean val) { - // This implementation is slightly inefficient timewise, but the extra - // effort over inlining it is O(1) and small, and I refuse to repeat code - // if it can be helped. - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a boolean value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - */ - public static void fill(boolean[] a, int fromIndex, int toIndex, - boolean val) { - for (int i = fromIndex; i < toIndex; i++) { - a[i] = val; - } - } - - /** - * Fill an array with a byte value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(byte[] a, byte val) { - // This implementation is slightly inefficient timewise, but the extra - // effort over inlining it is O(1) and small, and I refuse to repeat code - // if it can be helped. - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a byte value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - */ - public static void fill(byte[] a, int fromIndex, int toIndex, byte val) { - for (int i = fromIndex; i < toIndex; i++) { - a[i] = val; - } - } - - /** - * Fill an array with a char value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(char[] a, char val) { - // This implementation is slightly inefficient timewise, but the extra - // effort over inlining it is O(1) and small, and I refuse to repeat code - // if it can be helped. - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a char value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - */ - public static void fill(char[] a, int fromIndex, int toIndex, char val) { - for (int i = fromIndex; i < toIndex; i++) { - a[i] = val; - } - } - - /** - * Fill an array with a double value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(double[] a, double val) { - // This implementation is slightly inefficient timewise, but the extra - // effort over inlining it is O(1) and small, and I refuse to repeat code - // if it can be helped. - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a double value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - */ - public static void fill(double[] a, int fromIndex, int toIndex, double val) { - for (int i = fromIndex; i < toIndex; i++) { - a[i] = val; - } - } - - /** - * Fill an array with a float value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(float[] a, float val) { - // This implementation is slightly inefficient timewise, but the extra - // effort over inlining it is O(1) and small, and I refuse to repeat code - // if it can be helped. - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a float value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - */ - public static void fill(float[] a, int fromIndex, int toIndex, float val) { - for (int i = fromIndex; i < toIndex; i++) { - a[i] = val; - } - } - - /** - * Fill an array with an int value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(int[] a, int val) { - // This implementation is slightly inefficient timewise, but the extra - // effort over inlining it is O(1) and small, and I refuse to repeat code - // if it can be helped. - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with an int value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - */ - public static void fill(int[] a, int fromIndex, int toIndex, int val) { - for (int i = fromIndex; i < toIndex; i++) { - a[i] = val; - } - } - - /** - * Fill an array with a long value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(long[] a, long val) { - // This implementation is slightly inefficient timewise, but the extra - // effort over inlining it is O(1) and small, and I refuse to repeat code - // if it can be helped. - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a long value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - */ - public static void fill(long[] a, int fromIndex, int toIndex, long val) { - for (int i = fromIndex; i < toIndex; i++) { - a[i] = val; - } - } - - /** - * Fill an array with a short value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(short[] a, short val) { - // This implementation is slightly inefficient timewise, but the extra - // effort over inlining it is O(1) and small, and I refuse to repeat code - // if it can be helped. - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a short value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - */ - public static void fill(short[] a, int fromIndex, int toIndex, short val) { - for (int i = fromIndex; i < toIndex; i++) { - a[i] = val; - } - } - - /** - * Fill an array with an Object value. - * - * @param a the array to fill - * @param val the value to fill it with - * @exception ClassCastException if val is not an instance of the element - * type of a. - */ - public static void fill(Object[] a, Object val) { - // This implementation is slightly inefficient timewise, but the extra - // effort over inlining it is O(1) and small, and I refuse to repeat code - // if it can be helped. - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with an Object value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @exception ClassCastException if val is not an instance of the element - * type of a. - */ - public static void fill(Object[] a, int fromIndex, int toIndex, Object val) { - for (int i = fromIndex; i < toIndex; i++) { - a[i] = val; - } - } - - // Thanks to Paul Fisher for finding this quicksort algorithm - // as specified by Sun and porting it to Java. - - /** - * Sort a byte array into ascending order. The sort algorithm is an optimised - * quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's - * "Engineering a Sort Function", Software-Practice and Experience, Vol. - * 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n) - * performance on many arrays that would take quadratic time with a standard - * quicksort. - * - * @param a the array to sort - */ - public static void sort(byte[] a) { - qsort(a, 0, a.length); - } - - private static short cmp(byte i, byte j) { - return (short)(i-j); - } - - private static int med3(int a, int b, int c, byte[] d) { - return cmp(d[a], d[b]) < 0 ? - (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a) - : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a); - } - - private static void swap(int i, int j, byte[] a) { - byte c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - private static void qsort(byte[] a, int start, int n) { - // use an insertion sort on small arrays - if (n < 7) { - for (int i = start + 1; i < start + n; i++) - for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--) - swap(j, j-1, a); - return; - } - - int pm = n/2; // small arrays, middle element - if (n > 7) { - int pl = start; - int pn = start + n-1; - - if (n > 40) { // big arrays, pseudomedian of 9 - int s = n/8; - pl = med3(pl, pl+s, pl+2*s, a); - pm = med3(pm-s, pm, pm+s, a); - pn = med3(pn-2*s, pn-s, pn, a); - } - pm = med3(pl, pm, pn, a); // mid-size, med of 3 - } - - int pa, pb, pc, pd, pv; - short r; - - pv = start; swap(pv, pm, a); - pa = pb = start; - pc = pd = start + n-1; - - for (;;) { - while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) { - if (r == 0) { swap(pa, pb, a); pa++; } - pb++; - } - while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) { - if (r == 0) { swap(pc, pd, a); pd--; } - pc--; - } - if (pb > pc) break; - swap(pb, pc, a); - pb++; - pc--; - } - int pn = start + n; - int s; - s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a); - s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a); - if ((s = pb-pa) > 1) qsort(a, start, s); - if ((s = pd-pc) > 1) qsort(a, pn-s, s); - } - - private static void vecswap(int i, int j, int n, byte[] a) { - for (; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Sort a char array into ascending order. The sort algorithm is an optimised - * quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's - * "Engineering a Sort Function", Software-Practice and Experience, Vol. - * 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n) - * performance on many arrays that would take quadratic time with a standard - * quicksort. - * - * @param a the array to sort - */ - public static void sort(char[] a) { - qsort(a, 0, a.length); - } - - private static int cmp(char i, char j) { - return i-j; - } - - private static int med3(int a, int b, int c, char[] d) { - return cmp(d[a], d[b]) < 0 ? - (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a) - : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a); - } - - private static void swap(int i, int j, char[] a) { - char c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - private static void qsort(char[] a, int start, int n) { - // use an insertion sort on small arrays - if (n < 7) { - for (int i = start + 1; i < start + n; i++) - for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--) - swap(j, j-1, a); - return; - } - - int pm = n/2; // small arrays, middle element - if (n > 7) { - int pl = start; - int pn = start + n-1; - - if (n > 40) { // big arrays, pseudomedian of 9 - int s = n/8; - pl = med3(pl, pl+s, pl+2*s, a); - pm = med3(pm-s, pm, pm+s, a); - pn = med3(pn-2*s, pn-s, pn, a); - } - pm = med3(pl, pm, pn, a); // mid-size, med of 3 - } - - int pa, pb, pc, pd, pv; - int r; - - pv = start; swap(pv, pm, a); - pa = pb = start; - pc = pd = start + n-1; - - for (;;) { - while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) { - if (r == 0) { swap(pa, pb, a); pa++; } - pb++; - } - while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) { - if (r == 0) { swap(pc, pd, a); pd--; } - pc--; - } - if (pb > pc) break; - swap(pb, pc, a); - pb++; - pc--; - } - int pn = start + n; - int s; - s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a); - s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a); - if ((s = pb-pa) > 1) qsort(a, start, s); - if ((s = pd-pc) > 1) qsort(a, pn-s, s); - } - - private static void vecswap(int i, int j, int n, char[] a) { - for (; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Sort a double array into ascending order. The sort algorithm is an - * optimised quicksort, as described in Jon L. Bentley and M. Douglas - * McIlroy's "Engineering a Sort Function", Software-Practice and Experience, - * Vol. 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n) - * performance on many arrays that would take quadratic time with a standard - * quicksort. Note that this implementation, like Sun's, has undefined - * behaviour if the array contains any NaN values. - * - * @param a the array to sort - */ - public static void sort(double[] a) { - qsort(a, 0, a.length); - } - - private static double cmp(double i, double j) { - return i-j; - } - - private static int med3(int a, int b, int c, double[] d) { - return cmp(d[a], d[b]) < 0 ? - (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a) - : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a); - } - - private static void swap(int i, int j, double[] a) { - double c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - private static void qsort(double[] a, int start, int n) { - // use an insertion sort on small arrays - if (n < 7) { - for (int i = start + 1; i < start + n; i++) - for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--) - swap(j, j-1, a); - return; - } - - int pm = n/2; // small arrays, middle element - if (n > 7) { - int pl = start; - int pn = start + n-1; - - if (n > 40) { // big arrays, pseudomedian of 9 - int s = n/8; - pl = med3(pl, pl+s, pl+2*s, a); - pm = med3(pm-s, pm, pm+s, a); - pn = med3(pn-2*s, pn-s, pn, a); - } - pm = med3(pl, pm, pn, a); // mid-size, med of 3 - } - - int pa, pb, pc, pd, pv; - double r; - - pv = start; swap(pv, pm, a); - pa = pb = start; - pc = pd = start + n-1; - - for (;;) { - while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) { - if (r == 0) { swap(pa, pb, a); pa++; } - pb++; - } - while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) { - if (r == 0) { swap(pc, pd, a); pd--; } - pc--; - } - if (pb > pc) break; - swap(pb, pc, a); - pb++; - pc--; - } - int pn = start + n; - int s; - s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a); - s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a); - if ((s = pb-pa) > 1) qsort(a, start, s); - if ((s = pd-pc) > 1) qsort(a, pn-s, s); - } - - private static void vecswap(int i, int j, int n, double[] a) { - for (; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Sort a float array into ascending order. The sort algorithm is an - * optimised quicksort, as described in Jon L. Bentley and M. Douglas - * McIlroy's "Engineering a Sort Function", Software-Practice and Experience, - * Vol. 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n) - * performance on many arrays that would take quadratic time with a standard - * quicksort. Note that this implementation, like Sun's, has undefined - * behaviour if the array contains any NaN values. - * - * @param a the array to sort - */ - public static void sort(float[] a) { - qsort(a, 0, a.length); - } - - private static float cmp(float i, float j) { - return i-j; - } - - private static int med3(int a, int b, int c, float[] d) { - return cmp(d[a], d[b]) < 0 ? - (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a) - : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a); - } - - private static void swap(int i, int j, float[] a) { - float c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - private static void qsort(float[] a, int start, int n) { - // use an insertion sort on small arrays - if (n < 7) { - for (int i = start + 1; i < start + n; i++) - for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--) - swap(j, j-1, a); - return; - } - - int pm = n/2; // small arrays, middle element - if (n > 7) { - int pl = start; - int pn = start + n-1; - - if (n > 40) { // big arrays, pseudomedian of 9 - int s = n/8; - pl = med3(pl, pl+s, pl+2*s, a); - pm = med3(pm-s, pm, pm+s, a); - pn = med3(pn-2*s, pn-s, pn, a); - } - pm = med3(pl, pm, pn, a); // mid-size, med of 3 - } - - int pa, pb, pc, pd, pv; - float r; - - pv = start; swap(pv, pm, a); - pa = pb = start; - pc = pd = start + n-1; - - for (;;) { - while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) { - if (r == 0) { swap(pa, pb, a); pa++; } - pb++; - } - while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) { - if (r == 0) { swap(pc, pd, a); pd--; } - pc--; - } - if (pb > pc) break; - swap(pb, pc, a); - pb++; - pc--; - } - int pn = start + n; - int s; - s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a); - s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a); - if ((s = pb-pa) > 1) qsort(a, start, s); - if ((s = pd-pc) > 1) qsort(a, pn-s, s); - } - - private static void vecswap(int i, int j, int n, float[] a) { - for (; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Sort an int array into ascending order. The sort algorithm is an optimised - * quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's - * "Engineering a Sort Function", Software-Practice and Experience, Vol. - * 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n) - * performance on many arrays that would take quadratic time with a standard - * quicksort. - * - * @param a the array to sort - */ - public static void sort(int[] a) { - qsort(a, 0, a.length); - } - - private static long cmp(int i, int j) { - return (long)i-(long)j; - } - - private static int med3(int a, int b, int c, int[] d) { - return cmp(d[a], d[b]) < 0 ? - (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a) - : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a); - } - - private static void swap(int i, int j, int[] a) { - int c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - private static void qsort(int[] a, int start, int n) { - // use an insertion sort on small arrays - if (n < 7) { - for (int i = start + 1; i < start + n; i++) - for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--) - swap(j, j-1, a); - return; - } - - int pm = n/2; // small arrays, middle element - if (n > 7) { - int pl = start; - int pn = start + n-1; - - if (n > 40) { // big arrays, pseudomedian of 9 - int s = n/8; - pl = med3(pl, pl+s, pl+2*s, a); - pm = med3(pm-s, pm, pm+s, a); - pn = med3(pn-2*s, pn-s, pn, a); - } - pm = med3(pl, pm, pn, a); // mid-size, med of 3 - } - - int pa, pb, pc, pd, pv; - long r; - - pv = start; swap(pv, pm, a); - pa = pb = start; - pc = pd = start + n-1; - - for (;;) { - while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) { - if (r == 0) { swap(pa, pb, a); pa++; } - pb++; - } - while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) { - if (r == 0) { swap(pc, pd, a); pd--; } - pc--; - } - if (pb > pc) break; - swap(pb, pc, a); - pb++; - pc--; - } - int pn = start + n; - int s; - s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a); - s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a); - if ((s = pb-pa) > 1) qsort(a, start, s); - if ((s = pd-pc) > 1) qsort(a, pn-s, s); - } - - private static void vecswap(int i, int j, int n, int[] a) { - for (; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Sort a long array into ascending order. The sort algorithm is an optimised - * quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's - * "Engineering a Sort Function", Software-Practice and Experience, Vol. - * 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n) - * performance on many arrays that would take quadratic time with a standard - * quicksort. - * - * @param a the array to sort - */ - public static void sort(long[] a) { - qsort(a, 0, a.length); - } - - // The "cmp" method has been removed from here and replaced with direct - // compares in situ, to avoid problems with overflow if the difference - // between two numbers is bigger than a long will hold. - // One particular change as a result is the use of r1 and r2 in qsort - - private static int med3(int a, int b, int c, long[] d) { - return d[a] < d[b] ? - (d[b] < d[c] ? b : d[a] < d[c] ? c : a) - : (d[b] > d[c] ? b : d[a] > d[c] ? c : a); - } - - private static void swap(int i, int j, long[] a) { - long c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - private static void qsort(long[] a, int start, int n) { - // use an insertion sort on small arrays - if (n < 7) { - for (int i = start + 1; i < start + n; i++) - for (int j = i; j > 0 && a[j-1] > a[j]; j--) - swap(j, j-1, a); - return; - } - - int pm = n/2; // small arrays, middle element - if (n > 7) { - int pl = start; - int pn = start + n-1; - - if (n > 40) { // big arrays, pseudomedian of 9 - int s = n/8; - pl = med3(pl, pl+s, pl+2*s, a); - pm = med3(pm-s, pm, pm+s, a); - pn = med3(pn-2*s, pn-s, pn, a); - } - pm = med3(pl, pm, pn, a); // mid-size, med of 3 - } - - int pa, pb, pc, pd, pv; - long r1, r2; - - pv = start; swap(pv, pm, a); - pa = pb = start; - pc = pd = start + n-1; - - for (;;) { - while (pb <= pc && (r1 = a[pb]) <= (r2 = a[pv])) { - if (r1 == r2) { swap(pa, pb, a); pa++; } - pb++; - } - while (pc >= pb && (r1 = a[pc]) >= (r2 = a[pv])) { - if (r1 == r2) { swap(pc, pd, a); pd--; } - pc--; - } - if (pb > pc) break; - swap(pb, pc, a); - pb++; - pc--; - } - int pn = start + n; - int s; - s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a); - s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a); - if ((s = pb-pa) > 1) qsort(a, start, s); - if ((s = pd-pc) > 1) qsort(a, pn-s, s); - } - - private static void vecswap(int i, int j, int n, long[] a) { - for (; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Sort a short array into ascending order. The sort algorithm is an - * optimised quicksort, as described in Jon L. Bentley and M. Douglas - * McIlroy's "Engineering a Sort Function", Software-Practice and Experience, - * Vol. 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n) - * performance on many arrays that would take quadratic time with a standard - * quicksort. - * - * @param a the array to sort - */ - public static void sort(short[] a) { - qsort(a, 0, a.length); - } - - private static int cmp(short i, short j) { - return i-j; - } - - private static int med3(int a, int b, int c, short[] d) { - return cmp(d[a], d[b]) < 0 ? - (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a) - : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a); - } - - private static void swap(int i, int j, short[] a) { - short c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - private static void qsort(short[] a, int start, int n) { - // use an insertion sort on small arrays - if (n < 7) { - for (int i = start + 1; i < start + n; i++) - for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--) - swap(j, j-1, a); - return; - } - - int pm = n/2; // small arrays, middle element - if (n > 7) { - int pl = start; - int pn = start + n-1; - - if (n > 40) { // big arrays, pseudomedian of 9 - int s = n/8; - pl = med3(pl, pl+s, pl+2*s, a); - pm = med3(pm-s, pm, pm+s, a); - pn = med3(pn-2*s, pn-s, pn, a); - } - pm = med3(pl, pm, pn, a); // mid-size, med of 3 - } - - int pa, pb, pc, pd, pv; - int r; - - pv = start; swap(pv, pm, a); - pa = pb = start; - pc = pd = start + n-1; - - for (;;) { - while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) { - if (r == 0) { swap(pa, pb, a); pa++; } - pb++; - } - while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) { - if (r == 0) { swap(pc, pd, a); pd--; } - pc--; - } - if (pb > pc) break; - swap(pb, pc, a); - pb++; - pc--; - } - int pn = start + n; - int s; - s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a); - s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a); - if ((s = pb-pa) > 1) qsort(a, start, s); - if ((s = pd-pc) > 1) qsort(a, pn-s, s); - } - - private static void vecswap(int i, int j, int n, short[] a) { - for (; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * The bulk of the work for the object sort routines. If c is null, - * uses the natural ordering. - * In general, the code attempts to be simple rather than fast, the idea - * being that a good optimising JIT will be able to optimise it better than I - * can, and if I try it will make it more confusing for the JIT. The - * exception is in declaring values "final", which I do whenever there is no - * need for them ever to change - this may give slight speedups. - */ - private static void mergeSort(Object[] a, final Comparator c) { - final int n = a.length; - Object[] x = a; - Object[] y = new Object[n]; - Object[] t = null; // t is used for swapping x and y - - // The merges are done in this loop - for (int sizenf = 1; sizenf < n; sizenf <<= 1) { - final int size = sizenf; // Slightly inelegant but probably speeds us up - - for (int startnf = 0; startnf < n; startnf += size << 1) { - final int start = startnf; // see above with size and sizenf - - // size2 is the size of the second sublist, which may not be the same - // as the first if we are at the end of the list. - final int size2 = n - start - size < size ? n - start - size : size; - - // The second list is empty or the elements are already in order - no - // need to merge - if (size2 <= 0 || - compare(x[start + size - 1], x[start + size], c) <= 0) { - System.arraycopy(x, start, y, start, size + size2); - - // The two halves just need swapping - no need to merge - } else if (compare(x[start], x[start + size + size2 - 1], c) >= 0) { - System.arraycopy(x, start, y, start + size2, size); - System.arraycopy(x, start + size, y, start, size2); - - } else { - // Declare a lot of variables to save repeating calculations. - // Hopefully a decent JIT will put these in registers and make this - // fast - int p1 = start; - int p2 = start + size; - int i = start; - int d1; - - // initial value added to placate javac - int d2 = -1; - - // The main merge loop; terminates as soon as either half is ended - // You'd think you needed to use & rather than && to make sure d2 - // gets calculated even if d1 == 0, but in fact if this is the case, - // d2 hasn't changed since the last iteration. - while ((d1 = start + size - p1) > 0 && - (d2 = start + size + size2 - p2) > 0) { - y[i++] = x[(compare(x[p1], x[p2], c) <= 0) ? p1++ : p2++]; - } - - // Finish up by copying the remainder of whichever half wasn't - // finished. - System.arraycopy(x, d1 > 0 ? p1 : p2, y, i, d1 > 0 ? d1 : d2); - } - } - t = x; x = y; y = t; // swap x and y ready for the next merge - } - - // make sure the result ends up back in the right place. - if (x != a) { - System.arraycopy(x, 0, a, 0, n); - } - } - - /** - * Sort an array of Objects according to their natural ordering. The sort is - * guaranteed to be stable, that is, equal elements will not be reordered. - * The sort algorithm is a mergesort with the merge omitted if the last - * element of one half comes before the first element of the other half. This - * algorithm gives guaranteed O(nlog(n)) time, at the expense of making a - * copy of the array. - * - * @param a the array to be sorted - * @exception ClassCastException if any two elements are not mutually - * comparable - * @exception NullPointerException if an element is null (since - * null.compareTo cannot work) - */ - public static void sort(Object[] a) { - mergeSort(a, null); - } - - /** - * Sort an array of Objects according to a Comparator. The sort is - * guaranteed to be stable, that is, equal elements will not be reordered. - * The sort algorithm is a mergesort with the merge omitted if the last - * element of one half comes before the first element of the other half. This - * algorithm gives guaranteed O(nlog(n)) time, at the expense of making a - * copy of the array. - * - * @param a the array to be sorted - * @param c a Comparator to use in sorting the array - * @exception ClassCastException if any two elements are not mutually - * comparable by the Comparator provided - */ - public static void sort(Object[] a, Comparator c) { - - // Passing null to mergeSort would use the natural ordering. This is wrong - // by the spec and not in the reference implementation. - if (c == null) { - throw new NullPointerException(); - } - mergeSort(a, c); - } - - /** - * Returns a list "view" of the specified array. This method is intended to - * make it easy to use the Collections API with existing array-based APIs and - * programs. - * - * @param a the array to return a view of - * @returns a fixed-size list, changes to which "write through" to the array - */ - public static List asList(final Object[] a) { - - // Check for a null argument - if (a == null) { - throw new NullPointerException(); - } - - return new ListImpl( a ); - } - - - /** - * Inner class used by asList(Object[]) to provide a list interface - * to an array. The methods are all simple enough to be self documenting. - * Note: When Sun fully specify serialized forms, this class will have to - * be renamed. - */ - private static class ListImpl extends AbstractList { - - ListImpl(Object[] a) { - this.a = a; - } - - public Object get(int index) { - return a[index]; - } - - public int size() { - return a.length; - } - - public Object set(int index, Object element) { - Object old = a[index]; - a[index] = element; - return old; - } - - private Object[] a; - } - -} diff --git a/jode/jode/util/BasicMapEntry.java b/jode/jode/util/BasicMapEntry.java deleted file mode 100644 index 83aaafe..0000000 --- a/jode/jode/util/BasicMapEntry.java +++ /dev/null @@ -1,138 +0,0 @@ -// This class is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// BasicMapEntry.java -- a class providing a plain-vanilla implementation of -// the Map.Entry interface; could be used anywhere in -// java.util -// -// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -package jode.util; -///#ifdef JDK12 -///import java.lang.UnsupportedOperationException; -///import java.util.Map; -///#endif - -/** - * a class which implements Map.Entry - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ -class BasicMapEntry implements Map.Entry -{ - /** the key */ - Object key; - /** the value */ - Object value; - - /** - * construct a new BasicMapEntry with the given key and value - * - * @param newKey the key of this Entry - * @param newValue the value of this Entry - */ - BasicMapEntry(Object newKey, Object newValue) - { - key = newKey; - value = newValue; - } - - /** - * returns true if

o
is a Map.Entry and - *
 
-     * (((o.getKey == null) ? (key == null) : 
-     * o.getKey().equals(key)) && 
-     * ((o.getValue() == null) ? (value == null) : 
-     * o.getValue().equals(value)))
-     * 
- * - * NOTE: the calls to getKey() and getValue() in this implementation - * are NOT superfluous and should not be removed. They insure - * that subclasses such as HashMapEntry work correctly - * - * @param o the Object being tested for equality - */ - public boolean equals(Object o) - { - Map.Entry tester; - Object oTestingKey, oTestingValue; - Object oKey, oValue; - if (o instanceof Map.Entry) - { - tester = (Map.Entry) o; - oKey = getKey(); - oValue = getValue(); - oTestingKey = tester.getKey(); - oTestingValue = tester.getValue(); - return (((oTestingKey == null) ? (oKey == null) : - oTestingKey.equals(oKey)) && - ((oTestingValue == null) ? (oValue == null) : - oTestingValue.equals(oValue))); - } - return false; - } - - /** returns the key */ - public Object getKey() - { - return key; - } - - /** returns the value */ - public Object getValue() - { - return value; - } - - /** the hashCode() for a Map.Entry is - *
 
-     * ((getKey() == null) ? 0 : getKey().hashCode()) ^ 
-     * ((getValue() == null) ? 0 : getValue().hashCode());
-     * 
- * - * NOTE: the calls to getKey() and getValue() in this implementation - * are NOT superfluous and should not be removed. They insure - * that subclasses such as HashMapEntry work correctly - */ - public int hashCode() - { - Object oKey = getKey(); - Object oValue = getValue(); - return ((oKey == null) ? 0 : oKey.hashCode()) ^ - ((oValue == null) ? 0 : oValue.hashCode()); - } - - /** - * sets the value of this Map.Entry - * - * @param newValue the new value of this Map.Entry - */ - public Object setValue(Object newValue) - throws UnsupportedOperationException, ClassCastException, - IllegalArgumentException, NullPointerException - { - Object oVal = value; - value = newValue; - return oVal; - } -} diff --git a/jode/jode/util/Bucket.java b/jode/jode/util/Bucket.java deleted file mode 100644 index 4ce894b..0000000 --- a/jode/jode/util/Bucket.java +++ /dev/null @@ -1,198 +0,0 @@ -// This class is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// Bucket.java -- a class providing a hash-bucket data structure (a lightweight -// linked list) -// -// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -package jode.util; - -/** - * a class representing a simple, lightweight linked-list, using Node - * objects as its linked nodes; this is used by Hashtable and HashMap - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ -class Bucket -{ - /** the first node of the lined list, originally null */ - Node first; - - /** trivial constructor for a Bucket */ - Bucket() - { - } - - /** add this key / value pair to the list - * - * @param entry a Map.Entry object to be added to this list - */ - Map.Entry add(Node newNode) - { - Object oKey; - Object oTestKey = newNode.getKey(); - Node it = first; - Node prev = null; - if (it == null) // if the list is empty (the ideal case), we make a new single-node list - { - first = newNode; - return null; - } - else // otherwise try to find where this key already exists in the list, - {// and if it does, replace the value with the new one (and return the old one) - while (it != null) - { - oKey = it.getKey(); - if ((oKey == null) ? (oTestKey == null) : - oKey.equals(oTestKey)) - { - if (prev != null) - prev.next = newNode; - else - first = newNode; - newNode.next = it.next; - return it; - } - prev = it; - it = it.next; - } - prev.next = newNode; // otherwise, just stick this at the - return null; // end of the list - } - } - - /** - * remove a Map.Entry in this list with the supplied key and return its value, - * if it exists, else return null - * - * @param key the key we are looking for in this list - */ - Object removeByKey(Object key) - { - Object oEntryKey; - Node prev = null; - Node it = first; - while (it != null) - { - oEntryKey = it.getKey(); - if ((oEntryKey == null) ? (key == null) : oEntryKey.equals(key)) - { - if (prev == null) // we are removing the first element - first = it.next; - else - prev.next = it.next; - return it.getValue(); - } - else - { - prev = it; - it = it.next; - } - } - return null; - } - - /** - * return the value which the supplied key maps to, if it maps to anything in this list, - * otherwise, return null - * - * @param key the key mapping to a value that we are looking for - */ - Object getValueByKey(Object key) - { - Node entry = getEntryByKey(key); - return (entry == null) ? null : entry.getValue(); - } - - /** - * return the Map.Entry which the supplied key is a part of, if such a Map.Entry exists, - * null otherwise - * - * this method is important for HashMap, which can hold null values and the null key - * - * @param key the key for which we are finding the corresponding Map.Entry - */ - Node getEntryByKey(Object key) - { - Object oEntryKey; - Node it = first; - while (it != null) - { - oEntryKey = it.getKey(); - if ((oEntryKey == null) ? (key == null) : oEntryKey.equals(key)) - return it; - it = it.next; - } - return null; - } - - /** - * return true if this list has a Map.Entry whose value equals() the supplied value - * - * @param value the value we are looking to match in this list - */ - boolean containsValue(Object value) - { - Object oEntryValue; - Node it = first; - while (it != null) - { - oEntryValue = it.getValue(); - if ((oEntryValue == null) ? (value == null) : oEntryValue.equals(value)) - return true; - it = it.next; - } - return false; - } - - // INNSER CLASSES ---------------------------------------------------------- - - /** - * a class represnting a node in our lightweight linked-list - * that we use for hash buckets; a Node object contains a Map.Entry as its - *
value
property and a reference (possibly, even hopefully, null) - * to another Node as its
next
property. - * - * There is a reason for not using a highly generic "LinkedNode" type - * class: we want to eliminate runtime typechecks. - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ - static class Node extends BasicMapEntry implements Map.Entry - { - /** a reference to the next node in the linked list */ - Node next; - - /** non-trivial contructor -- sets the
value
of the Bucket upon instantiation */ - Node(Object key, Object value) - { - super(key, value); - } - - - } - // EOF ------------------------------------------------------------------------ -} diff --git a/jode/jode/util/Collection.java b/jode/jode/util/Collection.java deleted file mode 100644 index 9279326..0000000 --- a/jode/jode/util/Collection.java +++ /dev/null @@ -1,234 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// Collection.java -- Interface that represents a collection of objects -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Maybe some more @see clauses would be helpful. - -package jode.util; - -/** - * Interface that represents a collection of objects. This interface is the - * root of the collection hierarchy, and does not provide any guarantees about - * the order of its elements or whether or not duplicate elements are - * permitted. - *

- * All methods of this interface that are defined to modify the collection are - * defined as optional. An optional operation may throw an - * UnsupportedOperationException if the data backing this collection does not - * support such a modification. This may mean that the data structure is - * immutable, or that it is read-only but may change ("unmodifiable"), or - * that it is modifiable but of fixed size (such as an array), or any number - * of other combinations. - *

- * A class that wishes to implement this interface should consider subclassing - * AbstractCollection, which provides basic implementations of most of the - * methods of this interface. Classes that are prepared to make guarantees - * about ordering or about absence of duplicate elements should consider - * implementing List or Set respectively, both of which are subinterfaces of - * Collection. - *

- * A general-purpose implementation of the Collection interface should in most - * cases provide at least two constructors: One which takes no arguments and - * creates an empty collection, and one which takes a Collection as an argument - * and returns a collection containing the same elements (that is, creates a - * copy of the argument using its own implementation). - * - * @see java.util.List - * @see java.util.Set - * @see java.util.AbstractCollection - */ -public interface Collection { - - /** - * Add an element to this collection. - * - * @param o the object to add. - * @returns true if the collection was modified as a result of this action. - * @exception UnsupportedOperationException if this collection does not - * support the add operation. - * @exception ClassCastException if o cannot be added to this collection due - * to its type. - * @exception IllegalArgumentException if o cannot be added to this - * collection for some other reason. - */ - boolean add(Object o); - - /** - * Add the contents of a given collection to this collection. - * - * @param c the collection to add. - * @returns true if the collection was modified as a result of this action. - * @exception UnsupportedOperationException if this collection does not - * support the addAll operation. - * @exception ClassCastException if some element of c cannot be added to this - * collection due to its type. - * @exception IllegalArgumentException if some element of c cannot be added - * to this collection for some other reason. - */ - boolean addAll(Collection c); - - /** - * Clear the collection, such that a subsequent call to isEmpty() would - * return true. - * - * @exception UnsupportedOperationException if this collection does not - * support the clear operation. - */ - void clear(); - - /** - * Test whether this collection contains a given object as one of its - * elements. - * - * @param o the element to look for. - * @returns true if this collection contains at least one element e such that - * o == null ? e == null : o.equals(e). - */ - boolean contains(Object o); - - /** - * Test whether this collection contains every element in a given collection. - * - * @param c the collection to test for. - * @returns true if for every element o in c, contains(o) would return true. - */ - boolean containsAll(Collection c); - - /** - * Test whether this collection is equal to some object. The Collection - * interface does not explicitly require any behaviour from this method, and - * it may be left to the default implementation provided by Object. The Set - * and List interfaces do, however, require specific behaviour from this - * method. - *

- * If an implementation of Collection, which is not also an implementation of - * Set or List, should choose to implement this method, it should take care - * to obey the contract of the equals method of Object. In particular, care - * should be taken to return false when o is a Set or a List, in order to - * preserve the symmetry of the relation. - * - * @param o the object to compare to this collection. - * @returns true if the o is equal to this collection. - */ - boolean equals(Object o); - - /** - * Obtain a hash code for this collection. The Collection interface does not - * explicitly require any behaviour from this method, and it may be left to - * the default implementation provided by Object. The Set and List interfaces - * do, however, require specific behaviour from this method. - *

- * If an implementation of Collection, which is not also an implementation of - * Set or List, should choose to implement this method, it should take care - * to obey the contract of the hashCode method of Object. Note that this - * method renders it impossible to correctly implement both Set and List, as - * the required implementations are mutually exclusive. - * - * @returns a hash code for this collection. - */ - int hashCode(); - - /** - * Test whether this collection is empty, that is, if size() == 0. - * - * @returns true if this collection contains no elements. - */ - boolean isEmpty(); - - /** - * Obtain an Iterator over this collection. - * - * @returns an Iterator over the elements of this collection, in any order. - */ - Iterator iterator(); - - /** - * Remove a single occurrence of an object from this collection. That is, - * remove an element e, if one exists, such that o == null ? e == null - * : o.equals(e). - * - * @param o the object to remove. - * @returns true if the collection changed as a result of this call, that is, - * if the collection contained at least one occurrence of o. - * @exception UnsupportedOperationException if this collection does not - * support the remove operation. - */ - boolean remove(Object o); - - /** - * Remove all elements of a given collection from this collection. That is, - * remove every element e such that c.contains(e). - * - * @returns true if this collection was modified as a result of this call. - * @exception UnsupportedOperationException if this collection does not - * support the removeAll operation. - */ - boolean removeAll(Collection c); - - /** - * Remove all elements of this collection that are not contained in a given - * collection. That is, remove every element e such that !c.contains(e). - * - * @returns true if this collection was modified as a result of this call. - * @exception UnsupportedOperationException if this collection does not - * support the retainAll operation. - */ - boolean retainAll(Collection c); - - /** - * Get the number of elements in this collection. - * - * @returns the number of elements in the collection. - */ - int size(); - - /** - * Copy the current contents of this collection into an array. - * - * @returns an array of type Object[] and length equal to the size of this - * collection, containing the elements currently in this collection, in - * any order. - */ - Object[] toArray(); - - /** - * Copy the current contents of this collection into an array. If the array - * passed as an argument has length less than the size of this collection, an - * array of the same run-time type as a, and length equal to the size of this - * collection, is allocated using Reflection. Otherwise, a itself is used. - * The elements of this collection are copied into it, and if there is space - * in the array, the following element is set to null. The resultant array is - * returned. - * Note: The fact that the following element is set to null is only useful - * if it is known that this collection does not contain any null elements. - * - * @param a the array to copy this collection into. - * @returns an array containing the elements currently in this collection, in - * any order. - * @exception ArrayStoreException if the type of any element of the - * collection is not a subtype of the element type of a. - */ - Object[] toArray(Object[] a); -} diff --git a/jode/jode/util/Collections.java b/jode/jode/util/Collections.java deleted file mode 100644 index 9bcdfd4..0000000 --- a/jode/jode/util/Collections.java +++ /dev/null @@ -1,1413 +0,0 @@ -// This class is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// Collections.java -- Utility class with methods to operate on collections -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Serialization is very much broken. Blame Sun for not specifying it. -// ~ The synchronized* and unmodifiable* methods don't have doc-comments. - -package jode.util; - -import java.io.Serializable; -import java.util.Enumeration; -import java.util.Random; -import java.util.NoSuchElementException; - -/** - * Utility class consisting of static methods that operate on, or return - * Collections. Contains methods to sort, search, reverse, fill and shuffle - * Collections, methods to facilitate interoperability with legacy APIs that - * are unaware of collections, a method to return a list which consists of - * multiple copies of one element, and methods which "wrap" collections to give - * them extra properties, such as thread-safety and unmodifiability. - */ -public class Collections { - - /** - * This class is non-instantiable. - */ - private Collections() { - } - - /** - * An immutable, empty Set. - * Note: This implementation isn't Serializable, although it should be by the - * spec. - */ - public static final Set EMPTY_SET = new AbstractSet() { - - public int size() { - return 0; - } - - // This is really cheating! I think it's perfectly valid, though - the - // more conventional code is here, commented out, in case anyone disagrees. - public Iterator iterator() { - return EMPTY_LIST.iterator(); - } - - // public Iterator iterator() { - // return new Iterator() { - // - // public boolean hasNext() { - // return false; - // } - // - // public Object next() { - // throw new NoSuchElementException(); - // } - // - // public void remove() { - // throw new UnsupportedOperationException(); - // } - // }; - // } - - }; - - /** - * An immutable, empty List. - * Note: This implementation isn't serializable, although it should be by the - * spec. - */ - public static final List EMPTY_LIST = new AbstractList() { - - public int size() { - return 0; - } - - public Object get(int index) { - throw new IndexOutOfBoundsException(); - } - }; - - /** - * Compare two objects with or without a Comparator. If c is null, uses the - * natural ordering. Slightly slower than doing it inline if the JVM isn't - * clever, but worth it for removing a duplicate of the search code. - * Note: This same code is used in Arrays (for sort as well as search) - */ - private static int compare(Object o1, Object o2, Comparator c) { - if (c == null) { - return ((Comparable)o1).compareTo(o2); - } else { - return c.compare(o1, o2); - } - } - - /** - * The hard work for the search routines. If the Comparator given is null, - * uses the natural ordering of the elements. - */ - private static int search(List l, Object key, final Comparator c) { - - int pos = 0; - - // We use a linear search using an iterator if we can guess that the list - // is sequential-access. - if (l instanceof AbstractSequentialList) { - ListIterator i = l.listIterator(); - while (i.hasNext()) { - final int d = compare(key, i.next(), c); - if (d == 0) { - return pos; - } else if (d < 0) { - return -pos - 1; - } - pos++; - } - - // We assume the list is random-access, and use a binary search - } else { - int low = 0; - int hi = l.size() - 1; - while (low <= hi) { - pos = (low + hi) >> 1; - final int d = compare(key, l.get(pos), c); - if (d == 0) { - return pos; - } else if (d < 0) { - hi = pos - 1; - } else { - low = ++pos; // This gets the insertion point right on the last loop - } - } - } - - // If we failed to find it, we do the same whichever search we did. - return -pos - 1; - } - - /** - * Perform a binary search of a List for a key, using the natural ordering of - * the elements. The list must be sorted (as by the sort() method) - if it is - * not, the behaviour of this method is undefined, and may be an infinite - * loop. Further, the key must be comparable with every item in the list. If - * the list contains the key more than once, any one of them may be found. To - * avoid pathological behaviour on sequential-access lists, a linear search - * is used if (l instanceof AbstractSequentialList). Note: although the - * specification allows for an infinite loop if the list is unsorted, it will - * not happen in this (Classpath) implementation. - * - * @param l the list to search (must be sorted) - * @param key the value to search for - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - * @exception ClassCastException if key could not be compared with one of the - * elements of l - * @exception NullPointerException if a null element has compareTo called - */ - public static int binarySearch(List l, Object key) { - return search(l, key, null); - } - - /** - * Perform a binary search of a List for a key, using a supplied Comparator. - * The list must be sorted (as by the sort() method with the same Comparator) - * - if it is not, the behaviour of this method is undefined, and may be an - * infinite loop. Further, the key must be comparable with every item in the - * list. If the list contains the key more than once, any one of them may be - * found. To avoid pathological behaviour on sequential-access lists, a - * linear search is used if (l instanceof AbstractSequentialList). Note: - * although the specification allows for an infinite loop if the list is - * unsorted, it will not happen in this (Classpath) implementation. - * - * @param l the list to search (must be sorted) - * @param key the value to search for - * @param c the comparator by which the list is sorted - * @returns the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - * @exception ClassCastException if key could not be compared with one of the - * elements of l - */ - public static int binarySearch(List l, Object key, Comparator c) { - if (c == null) { - throw new NullPointerException(); - } - return search(l, key, c); - } - - /** - * Copy one list to another. If the destination list is longer than the - * source list, the remaining elements are unaffected. This method runs in - * linear time. - * - * @param dest the destination list. - * @param source the source list. - * @exception IndexOutOfBoundsException if the destination list is shorter - * than the source list (the elements that can be copied will be, prior to - * the exception being thrown). - * @exception UnsupportedOperationException if dest.listIterator() does not - * support the set operation. - */ - public static void copy(List dest, List source) { - Iterator i1 = source.iterator(); - ListIterator i2 = dest.listIterator(); - while (i1.hasNext()) { - i2.next(); - i2.set(i1.next()); - } - } - - /** - * Returns an Enumeration over a collection. This allows interoperability - * with legacy APIs that require an Enumeration as input. - * - * @param c the Collection to iterate over - * @returns an Enumeration backed by an Iterator over c - */ - public static Enumeration enumeration(Collection c) { - final Iterator i = c.iterator(); - return new Enumeration() { - public final boolean hasMoreElements() { - return i.hasNext(); - } - public final Object nextElement() { - return i.next(); - } - }; - } - - /** - * Replace every element of a list with a given value. This method runs in - * linear time. - * - * @param l the list to fill. - * @param val the object to vill the list with. - * @exception UnsupportedOperationException if l.listIterator() does not - * support the set operation. - */ - public static void fill(List l, Object val) { - ListIterator i = l.listIterator(); - while (i.hasNext()) { - i.next(); - i.set(val); - } - } - - /** - * Find the maximum element in a Collection, according to the natural - * ordering of the elements. This implementation iterates over the - * Collection, so it works in linear time. - * - * @param c the Collection to find the maximum element of - * @returns the maximum element of c - * @exception NoSuchElementException if c is empty - * @exception ClassCastException if elements in c are not mutually comparable - * @exception NullPointerException if null.compareTo is called - */ - public static Object max(Collection c) { - Iterator i = c.iterator(); - Comparable max = (Comparable)i.next(); // throws NoSuchElementException - while (i.hasNext()) { - Object o = i.next(); - if (max.compareTo(o) < 0) { - max = (Comparable)o; - } - } - return max; - } - - /** - * Find the maximum element in a Collection, according to a specified - * Comparator. This implementation iterates over the Collection, so it - * works in linear time. - * - * @param c the Collection to find the maximum element of - * @param order the Comparator to order the elements by - * @returns the maximum element of c - * @exception NoSuchElementException if c is empty - * @exception ClassCastException if elements in c are not mutually comparable - */ - public static Object max(Collection c, Comparator order) { - Iterator i = c.iterator(); - Object max = i.next(); // throws NoSuchElementException - while (i.hasNext()) { - Object o = i.next(); - if (order.compare(max, o) < 0) { - max = o; - } - } - return max; - } - - /** - * Find the minimum element in a Collection, according to the natural - * ordering of the elements. This implementation iterates over the - * Collection, so it works in linear time. - * - * @param c the Collection to find the minimum element of - * @returns the minimum element of c - * @exception NoSuchElementException if c is empty - * @exception ClassCastException if elements in c are not mutually comparable - * @exception NullPointerException if null.compareTo is called - */ - public static Object min(Collection c) { - Iterator i = c.iterator(); - Comparable min = (Comparable)i.next(); // throws NoSuchElementException - while (i.hasNext()) { - Object o = i.next(); - if (min.compareTo(o) > 0) { - min = (Comparable)o; - } - } - return min; - } - - /** - * Find the minimum element in a Collection, according to a specified - * Comparator. This implementation iterates over the Collection, so it - * works in linear time. - * - * @param c the Collection to find the minimum element of - * @param order the Comparator to order the elements by - * @returns the minimum element of c - * @exception NoSuchElementException if c is empty - * @exception ClassCastException if elements in c are not mutually comparable - */ - public static Object min(Collection c, Comparator order) { - Iterator i = c.iterator(); - Object min = i.next(); // throws NoSuchElementExcception - while (i.hasNext()) { - Object o = i.next(); - if (order.compare(min, o) > 0) { - min = o; - } - } - return min; - } - - /** - * Creates an immutable list consisting of the same object repeated n times. - * The returned object is tiny, consisting of only a single reference to the - * object and a count of the number of elements. It is Serializable. - * - * @param n the number of times to repeat the object - * @param o the object to repeat - * @returns a List consisting of n copies of o - * @throws IllegalArgumentException if n < 0 - */ - // It's not Serializable, because the serialized form is unspecced. - // Also I'm only assuming that it should be because I don't think it's - // stated - I just would be amazed if it isn't... - public static List nCopies(final int n, final Object o) { - - // Check for insane arguments - if (n < 0) { - throw new IllegalArgumentException(); - } - - // Create a minimal implementation of List - return new AbstractList() { - - public int size() { - return n; - } - - public Object get(int index) { - if (index < 0 || index >= n) { - throw new IndexOutOfBoundsException(); - } - return o; - } - }; - } - - /** - * Reverse a given list. This method works in linear time. - * - * @param l the list to reverse. - * @exception UnsupportedOperationException if l.listIterator() does not - * support the set operation. - */ - public static void reverse(List l) { - ListIterator i1 = l.listIterator(); - ListIterator i2 = l.listIterator(l.size()); - while (i1.nextIndex() < i2.previousIndex()) { - Object o = i1.next(); - i1.set(i2.previous()); - i2.set(o); - } - } - - /** - * Get a comparator that implements the reverse of natural ordering. This is - * intended to make it easy to sort into reverse order, by simply passing - * Collections.reverseOrder() to the sort method. The return value of this - * method is Serializable. - */ - // The return value isn't Serializable, because the spec is broken. - public static Comparator reverseOrder() { - return new Comparator() { - public int compare(Object a, Object b) { - return -((Comparable)a).compareTo(b); - } - }; - } - - /** - * Shuffle a list according to a default source of randomness. The algorithm - * used would result in a perfectly fair shuffle (that is, each element would - * have an equal chance of ending up in any position) with a perfect source - * of randomness; in practice the results are merely very close to perfect. - *

- * This method operates in linear time on a random-access list, but may take - * quadratic time on a sequential-access list. - * Note: this (classpath) implementation will never take quadratic time, but - * it does make a copy of the list. This is in line with the behaviour of the - * sort methods and seems preferable. - * - * @param l the list to shuffle. - * @exception UnsupportedOperationException if l.listIterator() does not - * support the set operation. - */ - public static void shuffle(List l) { - shuffle(l, new Random()); - } - - /** - * Shuffle a list according to a given source of randomness. The algorithm - * used iterates backwards over the list, swapping each element with an - * element randomly selected from the elements in positions less than or - * equal to it (using r.nextInt(int)). - *

- * This algorithm would result in a perfectly fair shuffle (that is, each - * element would have an equal chance of ending up in any position) if r were - * a perfect source of randomness. In practise (eg if r = new Random()) the - * results are merely very close to perfect. - *

- * This method operates in linear time on a random-access list, but may take - * quadratic time on a sequential-access list. - * Note: this (classpath) implementation will never take quadratic time, but - * it does make a copy of the list. This is in line with the behaviour of the - * sort methods and seems preferable. - * - * @param l the list to shuffle. - * @param r the source of randomness to use for the shuffle. - * @exception UnsupportedOperationException if l.listIterator() does not - * support the set operation. - */ - public static void shuffle(List l, Random r) { - Object[] a = l.toArray(); // Dump l into an array - ListIterator i = l.listIterator(l.size()); - - // Iterate backwards over l - while (i.hasPrevious()) { - - // Obtain a random position to swap with. nextIndex is used so that the - // range of the random number includes the current position. -// int swap = r.nextInt(i.nextIndex()); - // Change for jode by - int swap = Math.abs(r.nextInt()) % i.nextIndex(); - - // Swap the swapth element of the array with the next element of the - // list. - Object o = i.previous(); - i.set(a[swap]); - a[swap] = o; - } - } - - /** - * Obtain an immutable Set consisting of a single element. The return value - * of this method is Serializable. - * - * @param o the single element. - * @returns an immutable Set containing only o. - */ - // It's not serializable because the spec is broken. - public static Set singleton(final Object o) { - - return new AbstractSet() { - - public int size() { - return 1; - } - - public Iterator iterator() { - return new Iterator() { - - private boolean hasNext = true; - - public boolean hasNext() { - return hasNext; - } - - public Object next() { - if (hasNext) { - hasNext = false; - return o; - } else { - throw new NoSuchElementException(); - } - } - - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - }; - } - - /** - * Sort a list according to the natural ordering of its elements. The list - * must be modifiable, but can be of fixed size. The sort algorithm is - * precisely that used by Arrays.sort(Object[]), which offers guaranteed - * nlog(n) performance. This implementation dumps the list into an array, - * sorts the array, and then iterates over the list setting each element from - * the array. - * - * @param l the List to sort - * @exception ClassCastException if some items are not mutually comparable - * @exception UnsupportedOperationException if the List is not modifiable - */ - public static void sort(List l) { - Object[] a = l.toArray(); - Arrays.sort(a); - ListIterator i = l.listIterator(); - for (int pos = 0; pos < a.length; pos++) { - i.next(); - i.set(a[pos]); - } - } - - /** - * Sort a list according to a specified Comparator. The list must be - * modifiable, but can be of fixed size. The sort algorithm is precisely that - * used by Arrays.sort(Object[], Comparator), which offers guaranteed - * nlog(n) performance. This implementation dumps the list into an array, - * sorts the array, and then iterates over the list setting each element from - * the array. - * - * @param l the List to sort - * @param c the Comparator specifying the ordering for the elements - * @exception ClassCastException if c will not compare some pair of items - * @exception UnsupportedOperationException if the List is not modifiable - */ - public static void sort(List l, Comparator c) { - Object[] a = l.toArray(); - Arrays.sort(a, c); - ListIterator i = l.listIterator(); - for (int pos = 0; pos < a.length; pos++) { - i.next(); - i.set(a[pos]); - } - } - - // All the methods from here on in require doc-comments. - - public static Collection synchronizedCollection(Collection c) { - return new SynchronizedCollection(c); - } - public static List synchronizedList(List l) { - return new SynchronizedList(l); - } - public static Map synchronizedMap(Map m) { - return new SynchronizedMap(m); - } - public static Set synchronizedSet(Set s) { - return new SynchronizedSet(s); - } - public static SortedMap synchronizedSortedMap(SortedMap m) { - return new SynchronizedSortedMap(m); - } - public static SortedSet synchronizedSortedSet(SortedSet s) { - return new SynchronizedSortedSet(s); - } - public static Collection unmodifiableCollection(Collection c) { - return new UnmodifiableCollection(c); - } - public static List unmodifiableList(List l) { - return new UnmodifiableList(l); - } - public static Map unmodifiableMap(Map m) { - return new UnmodifiableMap(m); - } - public static Set unmodifiableSet(Set s) { - return new UnmodifiableSet(s); - } - public static SortedMap unmodifiableSortedMap(SortedMap m) { - return new UnmodifiableSortedMap(m); - } - public static SortedSet unmodifiableSortedSet(SortedSet s) { - return new UnmodifiableSortedSet(s); - } - - // Sun's spec will need to be checked for the precise names of these - // classes, for serializability's sake. However, from what I understand, - // serialization is broken for these classes anyway. - - // Note: although this code is largely uncommented, it is all very - // mechanical and there's nothing really worth commenting. - // When serialization of these classes works, we'll need doc-comments on - // them to document the serialized form. - - private static class UnmodifiableIterator implements Iterator { - private Iterator i; - - public UnmodifiableIterator(Iterator i) { - this.i = i; - } - - public Object next() { - return i.next(); - } - public boolean hasNext() { - return i.hasNext(); - } - public void remove() { - throw new UnsupportedOperationException(); - } - } - - private static class UnmodifiableListIterator extends UnmodifiableIterator - implements ListIterator { - - // This is stored both here and in the superclass, to avoid excessive - // casting. - private ListIterator li; - - public UnmodifiableListIterator(ListIterator li) { - super(li); - this.li = li; - } - - public boolean hasPrevious() { - return li.hasPrevious(); - } - public Object previous() { - return li.previous(); - } - public int nextIndex() { - return li.nextIndex(); - } - public int previousIndex() { - return li.previousIndex(); - } - public void add(Object o) { - throw new UnsupportedOperationException(); - } - public void set(Object o) { - throw new UnsupportedOperationException(); - } - } - - private static class UnmodifiableCollection implements Collection, Serializable { - Collection c; - - public UnmodifiableCollection(Collection c) { - this.c = c; - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - public void clear() { - throw new UnsupportedOperationException(); - } - public boolean contains(Object o) { - return c.contains(o); - } - public boolean containsAll(Collection c1) { - return c.containsAll(c1); - } - public boolean isEmpty() { - return c.isEmpty(); - } - public Iterator iterator() { - return new UnmodifiableIterator(c.iterator()); - } - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - public int size() { - return c.size(); - } - public Object[] toArray() { - return c.toArray(); - } - public Object[] toArray(Object[] a) { - return c.toArray(a); - } - } - - private static class UnmodifiableList extends UnmodifiableCollection - implements List { - - // This is stored both here and in the superclass, to avoid excessive - // casting. - List l; - - public UnmodifiableList(List l) { - super(l); - this.l = l; - } - - public void add(int index, Object o) { - l.add(index, o); - } - public boolean addAll(int index, Collection c) { - return l.addAll(index, c); - } - public boolean equals(Object o) { - return l.equals(o); - } - public Object get(int index) { - return l.get(index); - } - public int hashCode() { - return l.hashCode(); - } - public int indexOf(Object o) { - return l.indexOf(o); - } - public int lastIndexOf(Object o) { - return l.lastIndexOf(o); - } - public ListIterator listIterator() { - return new UnmodifiableListIterator(l.listIterator()); - } - public ListIterator listIterator(int index) { - return new UnmodifiableListIterator(l.listIterator(index)); - } - public Object remove(int index) { - return l.remove(index); - } - public boolean remove(Object o) { - return l.remove(o); - } - public Object set(int index, Object o) { - return l.set(index, o); - } - public List subList(int fromIndex, int toIndex) { - return new UnmodifiableList(l.subList(fromIndex, toIndex)); - } - } - - private static class UnmodifiableSet extends UnmodifiableCollection implements Set { - public UnmodifiableSet(Set s) { - super(s); - } - public boolean equals(Object o) { - return c.equals(o); - } - public int hashCode() { - return c.hashCode(); - } - } - - private static class UnmodifiableSortedSet extends UnmodifiableSet - implements SortedSet { - - // This is stored both here and in the superclass, to avoid excessive - // casting. - private SortedSet ss; - - public UnmodifiableSortedSet(SortedSet ss) { - super(ss); - this.ss = ss; - } - - public Comparator comparator() { - return ss.comparator(); - } - public Object first() { - return ss.first(); - } - public Object last() { - return ss.last(); - } - public SortedSet headSet(Object toElement) { - return new UnmodifiableSortedSet(ss.headSet(toElement)); - } - public SortedSet tailSet(Object fromElement) { - return new UnmodifiableSortedSet(ss.tailSet(fromElement)); - } - public SortedSet subSet(Object fromElement, Object toElement) { - return new UnmodifiableSortedSet(ss.subSet(fromElement, toElement)); - } - } - - private static class UnmodifiableMap implements Map, Serializable { - - Map m; - - public UnmodifiableMap(Map m) { - this.m = m; - } - - public void clear() { - throw new UnsupportedOperationException(); - } - public boolean containsKey(Object key) { - return m.containsKey(key); - } - public boolean containsValue(Object value) { - return m.containsValue(value); - } - - // This is one of the ickiest cases of nesting I've ever seen. It just - // means "return an UnmodifiableSet, except that the iterator() method - // returns an UnmodifiableIterator whos next() method returns an - // unmodifiable wrapper around its normal return value". - public Set entrySet() { - return new UnmodifiableSet(m.entrySet()) { - public Iterator iterator() { - return new UnmodifiableIterator(c.iterator()) { - public Object next() { - final Map.Entry e = (Map.Entry)super.next(); - return new Map.Entry() { - public Object getKey() { - return e.getKey(); - } - public Object getValue() { - return e.getValue(); - } - public Object setValue(Object value) { - throw new UnsupportedOperationException(); - } - public int hashCode() { - return e.hashCode(); - } - public boolean equals(Object o) { - return e.equals(o); - } - }; - } - }; - } - }; - } - public boolean equals(Object o) { - return m.equals(o); - } - public Object get(Object key) { - return m.get(key); - } - public Object put(Object key, Object value) { - throw new UnsupportedOperationException(); - } - public int hashCode() { - return m.hashCode(); - } - public boolean isEmpty() { - return m.isEmpty(); - } - public Set keySet() { - return new UnmodifiableSet(m.keySet()); - } - public void putAll(Map m) { - throw new UnsupportedOperationException(); - } - public Object remove(Object o) { - throw new UnsupportedOperationException(); - } - public int size() { - return m.size(); - } - public Collection values() { - return new UnmodifiableCollection(m.values()); - } - } - - private static class UnmodifiableSortedMap extends UnmodifiableMap - implements SortedMap { - - // This is stored both here and in the superclass, to avoid excessive - // casting. - private SortedMap sm; - - public UnmodifiableSortedMap(SortedMap sm) { - super(sm); - this.sm = sm; - } - - public Comparator comparator() { - return sm.comparator(); - } - public Object firstKey() { - return sm.firstKey(); - } - public Object lastKey() { - return sm.lastKey(); - } - public SortedMap headMap(Object toKey) { - return new UnmodifiableSortedMap(sm.headMap(toKey)); - } - public SortedMap tailMap(Object fromKey) { - return new UnmodifiableSortedMap(sm.tailMap(fromKey)); - } - public SortedMap subMap(Object fromKey, Object toKey) { - return new UnmodifiableSortedMap(sm.subMap(fromKey, toKey)); - } - } - - // All the "Synchronized" wrapper objects include a "sync" field which - // specifies what object to synchronize on. That way, nested wrappers such as - // UnmodifiableMap.keySet synchronize on the right things. - - private static class SynchronizedIterator implements Iterator { - Object sync; - private Iterator i; - - public SynchronizedIterator(Object sync, Iterator i) { - this.sync = sync; - this.i = i; - } - - public Object next() { - synchronized (sync) { - return i.next(); - } - } - public boolean hasNext() { - synchronized (sync) { - return i.hasNext(); - } - } - public void remove() { - synchronized (sync) { - i.remove(); - } - } - } - - private static class SynchronizedListIterator extends SynchronizedIterator - implements ListIterator { - - // This is stored both here and in the superclass, to avoid excessive - // casting. - private ListIterator li; - - public SynchronizedListIterator(Object sync, ListIterator li) { - super(sync, li); - this.li = li; - } - - public boolean hasPrevious() { - synchronized (sync) { - return li.hasPrevious(); - } - } - public Object previous() { - synchronized (sync) { - return li.previous(); - } - } - public int nextIndex() { - synchronized (sync) { - return li.nextIndex(); - } - } - public int previousIndex() { - synchronized (sync) { - return li.previousIndex(); - } - } - public void add(Object o) { - synchronized (sync) { - li.add(o); - } - } - public void set(Object o) { - synchronized (sync) { - li.set(o); - } - } - } - - private static class SynchronizedCollection implements Collection, Serializable { - Object sync; - Collection c; - - public SynchronizedCollection(Collection c) { - this.sync = this; - this.c = c; - } - public SynchronizedCollection(Object sync, Collection c) { - this.c = c; - this.sync = sync; - } - - public boolean add(Object o) { - synchronized (sync) { - return c.add(o); - } - } - public boolean addAll(Collection col) { - synchronized (sync) { - return c.addAll(col); - } - } - public void clear() { - synchronized (sync) { - c.clear(); - } - } - public boolean contains(Object o) { - synchronized (sync) { - return c.contains(o); - } - } - public boolean containsAll(Collection c1) { - synchronized (sync) { - return c.containsAll(c1); - } - } - public boolean isEmpty() { - synchronized (sync) { - return c.isEmpty(); - } - } - public Iterator iterator() { - synchronized (sync) { - return new SynchronizedIterator(sync, c.iterator()); - } - } - public boolean remove(Object o) { - synchronized (sync) { - return c.remove(o); - } - } - public boolean removeAll(Collection col) { - synchronized (sync) { - return c.removeAll(col); - } - } - public boolean retainAll(Collection col) { - synchronized (sync) { - return c.retainAll(col); - } - } - public int size() { - synchronized (sync) { - return c.size(); - } - } - public Object[] toArray() { - synchronized (sync) { - return c.toArray(); - } - } - public Object[] toArray(Object[] a) { - synchronized (sync) { - return c.toArray(a); - } - } - } - - private static class SynchronizedList extends SynchronizedCollection - implements List { - - // This is stored both here and in the superclass, to avoid excessive - // casting. - List l; - - public SynchronizedList(Object sync, List l) { - super(sync, l); - this.l = l; - } - public SynchronizedList(List l) { - super(l); - } - - public void add(int index, Object o) { - synchronized (sync) { - l.add(index, o); - } - } - public boolean addAll(int index, Collection c) { - synchronized (sync) { - return l.addAll(index, c); - } - } - public boolean equals(Object o) { - synchronized (sync) { - return l.equals(o); - } - } - public Object get(int index) { - synchronized (sync) { - return l.get(index); - } - } - public int hashCode() { - synchronized (sync) { - return l.hashCode(); - } - } - public int indexOf(Object o) { - synchronized (sync) { - return l.indexOf(o); - } - } - public int lastIndexOf(Object o) { - synchronized (sync) { - return l.lastIndexOf(o); - } - } - public ListIterator listIterator() { - synchronized (sync) { - return new SynchronizedListIterator(sync, l.listIterator()); - } - } - public ListIterator listIterator(int index) { - synchronized (sync) { - return new SynchronizedListIterator(sync, l.listIterator(index)); - } - } - public Object remove(int index) { - synchronized (sync) { - return l.remove(index); - } - } - public boolean remove(Object o) { - synchronized (sync) { - return l.remove(o); - } - } - public Object set(int index, Object o) { - synchronized (sync) { - return l.set(index, o); - } - } - public List subList(int fromIndex, int toIndex) { - synchronized (sync) { - return new SynchronizedList(l.subList(fromIndex, toIndex)); - } - } - } - - private static class SynchronizedSet extends SynchronizedCollection implements Set { - - public SynchronizedSet(Object sync, Set s) { - super(sync, s); - } - public SynchronizedSet(Set s) { - super(s); - } - - public boolean equals(Object o) { - synchronized (sync) { - return c.equals(o); - } - } - public int hashCode() { - synchronized (sync) { - return c.hashCode(); - } - } - } - - private static class SynchronizedSortedSet extends SynchronizedSet - implements SortedSet { - - // This is stored both here and in the superclass, to avoid excessive - // casting. - private SortedSet ss; - - public SynchronizedSortedSet(Object sync, SortedSet ss) { - super(sync, ss); - this.ss = ss; - } - public SynchronizedSortedSet(SortedSet ss) { - super(ss); - } - - public Comparator comparator() { - synchronized (sync) { - return ss.comparator(); - } - } - public Object first() { - synchronized (sync) { - return ss.first(); - } - } - public Object last() { - synchronized (sync) { - return ss.last(); - } - } - public SortedSet headSet(Object toElement) { - synchronized (sync) { - return new SynchronizedSortedSet(sync, ss.headSet(toElement)); - } - } - public SortedSet tailSet(Object fromElement) { - synchronized (sync) { - return new SynchronizedSortedSet(sync, ss.tailSet(fromElement)); - } - } - public SortedSet subSet(Object fromElement, Object toElement) { - synchronized (sync) { - return new SynchronizedSortedSet(sync, ss.subSet(fromElement, toElement)); - } - } - } - - private static class SynchronizedMap implements Map, Serializable { - - Object sync; - Map m; - - public SynchronizedMap(Object sync, Map m) { - this.sync = sync; - this.m = m; - } - public SynchronizedMap(Map m) { - this.m = m; - this.sync = this; - } - - public void clear() { - synchronized (sync) { - m.clear(); - } - } - public boolean containsKey(Object key) { - synchronized (sync) { - return m.containsKey(key); - } - } - public boolean containsValue(Object value) { - synchronized (sync) { - return m.containsValue(value); - } - } - - // This is one of the ickiest cases of nesting I've ever seen. It just - // means "return an SynchronizedSet, except that the iterator() method - // returns an SynchronizedIterator whos next() method returns a - // synchronized wrapper around its normal return value". - public Set entrySet() { - synchronized (sync) { - return new SynchronizedSet(sync, m.entrySet()) { - public Iterator iterator() { - synchronized (SynchronizedMap.this.sync) { - return new SynchronizedIterator(SynchronizedMap.this.sync, c.iterator()) { - public Object next() { - synchronized (SynchronizedMap.this.sync) { - final Map.Entry e = (Map.Entry)super.next(); - return new Map.Entry() { - public Object getKey() { - synchronized (SynchronizedMap.this.sync) { - return e.getKey(); - } - } - public Object getValue() { - synchronized (SynchronizedMap.this.sync) { - return e.getValue(); - } - } - public Object setValue(Object value) { - synchronized (SynchronizedMap.this.sync) { - return e.setValue(value); - } - } - public int hashCode() { - synchronized (SynchronizedMap.this.sync) { - return e.hashCode(); - } - } - public boolean equals(Object o) { - synchronized (SynchronizedMap.this.sync) { - return e.equals(o); - } - } - }; - } - } - }; - } - } - }; - } - } - public boolean equals(Object o) { - synchronized (sync) { - return m.equals(o); - } - } - public Object get(Object key) { - synchronized (sync) { - return m.get(key); - } - } - public Object put(Object key, Object value) { - synchronized (sync) { - return m.put(key, value); - } - } - public int hashCode() { - synchronized (sync) { - return m.hashCode(); - } - } - public boolean isEmpty() { - synchronized (sync) { - return m.isEmpty(); - } - } - public Set keySet() { - synchronized (sync) { - return new SynchronizedSet(sync, m.keySet()); - } - } - public void putAll(Map map) { - synchronized (sync) { - m.putAll(map); - } - } - public Object remove(Object o) { - synchronized (sync) { - return m.remove(o); - } - } - - public int size() { - synchronized (sync) { - return m.size(); - } - } - public Collection values() { - synchronized (sync) { - return new SynchronizedCollection(sync, m.values()); - } - } - } - - private static class SynchronizedSortedMap extends SynchronizedMap - implements SortedMap { - - // This is stored both here and in the superclass, to avoid excessive - // casting. - private SortedMap sm; - - public SynchronizedSortedMap(Object sync, SortedMap sm) { - super(sync, sm); - this.sm = sm; - } - public SynchronizedSortedMap(SortedMap sm) { - super(sm); - } - - public Comparator comparator() { - synchronized (sync) { - return sm.comparator(); - } - } - public Object firstKey() { - synchronized (sync) { - return sm.firstKey(); - } - } - public Object lastKey() { - synchronized (sync) { - return sm.lastKey(); - } - } - public SortedMap headMap(Object toKey) { - return new SynchronizedSortedMap(sync, sm.headMap(toKey)); - } - public SortedMap tailMap(Object fromKey) { - return new SynchronizedSortedMap(sync, sm.tailMap(fromKey)); - } - public SortedMap subMap(Object fromKey, Object toKey) { - return new SynchronizedSortedMap(sync, sm.subMap(fromKey, toKey)); - } - } -} diff --git a/jode/jode/util/Comparable.java b/jode/jode/util/Comparable.java deleted file mode 100644 index f2a7315..0000000 --- a/jode/jode/util/Comparable.java +++ /dev/null @@ -1,51 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -/************************************************************************* -/* Comparable.java -- Interface for comparaing objects to obtain an ordering -/* -/* Copyright (c) 1998 by Free Software Foundation, Inc. -/* -/* This program is free software; you can redistribute it and/or modify -/* it under the terms of the GNU Library General Public License as published -/* by the Free Software Foundation, version 2. (see COPYING.LIB) -/* -/* This program is distributed in the hope that it will be useful, but -/* WITHOUT ANY WARRANTY; without even the implied warranty of -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -/* GNU General Public License for more details. -/* -/* You should have received a copy of the GNU General Public License -/* along with this program; if not, write to the Free Software Foundation -/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -/*************************************************************************/ - -package jode.util; - -/** - ** Interface for objects that can be ordering among other - ** objects. The ordering can be total, such that two objects - ** only compare equal if they are equal by the equals method, or - ** partial such that this is not necessarily true. For - ** example, a case-sensitive dictionary order comparison of Strings - ** is total, but if it is case-insensitive it is partial, because - ** "abc" and "ABC" compare as equal even though "abc".equals("ABC") - ** returns false. - ** - ** @author Geoff Berry - ** - ** @since JDK1.2 - ** @see java.util.Comparator - **/ -public interface Comparable -{ - /** - ** @return a negative integer if this object is less than - ** o, zero if this object is equal to o, or - ** a positive integer if this object is greater than o - **/ - public int compareTo( Object o ); -} diff --git a/jode/jode/util/Comparator.java b/jode/jode/util/Comparator.java deleted file mode 100644 index 9247812..0000000 --- a/jode/jode/util/Comparator.java +++ /dev/null @@ -1,62 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// Comparator.java -- Interface for objects that specify an ordering -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -package jode.util; - -/** - * Interface for objects that specify an ordering between objects. The ordering - * can be total, such that two objects only compare equal if they are - * equal by the equals method, or partial such that this is not - * necessarily true. For example, a case-sensitive dictionary order comparison - * of Strings is total, but if it is case-insensitive it is partial, because - * "abc" and "ABC" compare as equal even though "abc".equals("ABC") returns - * false. - *

- * In general, Comparators should be Serializable, because when they are passed - * to Serializable data structures such as SortedMap or SortedSet, the entire - * data structure will only serialize correctly if the comparator is - * Serializable. - */ -public interface Comparator { - - /** - * Return an integer that is negative, zero or positive depending on whether - * the first argument is less than, equal to or greater than the second - * according to this ordering. This method should obey the following contract: - *

    - *
  • if compare(a, b) < 0 then compare(b, a) > 0
  • - *
  • if compare(a, b) throws an exception, so does compare(b, a)
  • - *
  • if compare(a, b) < 0 and compare(b, c) < 0 then compare(a, c) - * < 0
  • - *
  • if a.equals(b) or both a and b are null, then compare(a, b) == 0. - * The converse need not be true, but if it is, this Comparator - * specifies a total ordering.
  • - *
- * - * @throws ClassCastException if the elements are not of types that can be - * compared by this ordering. - */ - int compare(Object o1, Object o2); -} diff --git a/jode/jode/util/ConcurrentModificationException.java b/jode/jode/util/ConcurrentModificationException.java deleted file mode 100644 index 3e3bd4c..0000000 --- a/jode/jode/util/ConcurrentModificationException.java +++ /dev/null @@ -1,53 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// ConcurrentModificationException.java -- Data structure concurrently modified -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -package jode.util; - -/** - * Exception that is thrown by the collections classes when it is detected that - * a modification has been made to a data structure when this is not allowed, - * such as when a collection is structurally modified while an Iterator is - * operating over it. In cases where this can be detected, a - * ConcurrentModificationException will be thrown. An Iterator that detects this - * condition is referred to as fail-fast. - */ -public class ConcurrentModificationException extends RuntimeException { - - /** - * Constructs a ConcurrentModificationException with no detail message. - */ - public ConcurrentModificationException() { - super(); - } - - /** - * Constructs a ConcurrentModificationException with a detail message. - * - * @param detail the detail message for the exception - */ - public ConcurrentModificationException(String detail) { - super(detail); - } -} diff --git a/jode/jode/util/HashMap.java b/jode/jode/util/HashMap.java deleted file mode 100644 index f949f9b..0000000 --- a/jode/jode/util/HashMap.java +++ /dev/null @@ -1,876 +0,0 @@ -// This class is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// HashMap.java -- a class providing a basic hashtable data structure, -// mapping Object --> Object; part of the JDK1.2 collections -// API -// -// This is a JDK 1.2 compliant version of HashMap.java -// -// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com), -// Free Software Foundation, Inc. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// -package jode.util; -import java.util.NoSuchElementException; - -import java.io.IOException; -import java.io.Serializable; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -/** - * This class provides a hashtable-backed implementation of the - * Map interface. - * - * It uses a hash-bucket approach; that is, hash - * collisions are handled by linking the new node off of the - * pre-existing node (or list of nodes). In this manner, techniques - * such as linear probing (which can casue primary clustering) and - * rehashing (which does not fit very well with Java's method of - * precomputing hash codes) are avoided. - * - * Under ideal circumstances (no collisions, HashMap offers O(1) - * performance on most operations (
containsValue()
is, - * of course, O(n)). In the worst case (all keys map to the same - * hash code -- very unlikely), most operations are O(n). - * - * HashMap is part of the JDK1.2 Collections API. It differs from - * Hashtable in that it accepts the null key and null values, and it - * does not support "Enumeration views." - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ -public class HashMap extends AbstractMap - implements Map, Cloneable, Serializable -{ - // STATIC (CLASS) VARIABLES ------------------------------------------ - - /** - * the default capacity for an instance of HashMap -- I think this - * is low, and perhaps it shoudl be raised; Sun's documentation mildly - * suggests that this (11) is the correct value, though - */ - private static final int DEFAULT_CAPACITY = 11; - - /** the default load factor of a HashMap */ - private static final float DEFAULT_LOAD_FACTOR = 0.75F; - - /** used internally to represent the null key */ - private static final HashMap.Null NULL_KEY = new HashMap.Null(); - - /** used internally to parameterize the creation of set/collection views */ - private static final int KEYS = 0; - - /** used internally to parameterize the creation of set/collection views */ - private static final int VALUES = 1; - - /** used internally to parameterize the creation of set/collection views */ - private static final int ENTRIES = 2; - - private static final long serialVersionUID = 362498820763181265L; - - // INSTANCE VARIABLES ------------------------------------------------- - - /** the capacity of this HashMap: denotes the size of the bucket array */ - transient int capacity; - - /** the size of this HashMap: denotes the number of key-value pairs */ - private transient int size; - - /** the load factor of this HashMap: used in computing the threshold - * @serial - */ - float loadFactor; - - /* the rounded product of the capacity and the load factor; when the number of - * elements exceeds the threshold, the HashMap calls
rehash()
- * @serial - */ - private int threshold; - - /** - * this data structure contains the actual key-value mappings; a - *
BucketList
is a lightweight linked list of "Buckets", - * which, in turn, are linked nodes containing a key-value mapping - * and a reference to the "next" Bucket in the list - */ - private transient Bucket[] buckets; - - /** - * counts the number of modifications this HashMap has undergone; used by Iterators - * to know when to throw ConcurrentModificationExceptions (idea ripped-off from - * Stuart Ballard's AbstractList implementation) - */ - private transient int modCount; - - - // CONSTRUCTORS --------------------------------------------------------- - - /** - * construct a new HashMap with the default capacity and the default - * load factor - */ - public HashMap() - { - init(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); - } - - /** - * construct a new HashMap with a specific inital capacity and load factor - * - * @param initialCapacity the initial capacity of this HashMap (>=0) - * @param initialLoadFactor the load factor of this HashMap - * (a misnomer, really, since the load factor of - * a HashMap does not change) - * - * @throws IllegalArgumentException if (initialCapacity < 0) || - * (initialLoadFactor > 1.0) || - * (initialLoadFactor <= 0.0) - */ - public HashMap(int initialCapacity, float initialLoadFactor) - throws IllegalArgumentException - { - if (initialCapacity < 0 || initialLoadFactor <= 0 || initialLoadFactor > 1) - throw new IllegalArgumentException(); - else - init(initialCapacity, initialLoadFactor); - } - - /** - * construct a new HashMap with a specific inital capacity - * - * @param initialCapacity the initial capacity of this HashMap (>=0) - * - * @throws IllegalArgumentException if (initialCapacity < 0) - */ - public HashMap(int initialCapacity) - throws IllegalArgumentException - { - if (initialCapacity < 0) - throw new IllegalArgumentException(); - else - init(initialCapacity, DEFAULT_LOAD_FACTOR); - } - - /** - * construct a new HashMap from the given Map - * - * every element in Map t will be put into this new HashMap - * - * @param t a Map whose key / value pairs will be put into - * the new HashMap. NOTE: key / value pairs - * are not cloned in this constructor - */ - public HashMap(Map t) - { - int mapSize = t.size() * 2; - init(((mapSize > DEFAULT_CAPACITY) ? mapSize : DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR); - putAll(t); - } - - - // PUBLIC METHODS --------------------------------------------------------- - - /** returns the number of kay-value mappings currently in this Map */ - public int size() - { - return size; - } - - /** returns true if there are no key-value mappings currently in this Map */ - public boolean isEmpty() - { - return size == 0; - } - - /** empties this HashMap of all elements */ - public void clear() - { - size = 0; - modCount++; - buckets = new Bucket[capacity]; - } - - /** - * returns a shallow clone of this HashMap (i.e. the Map itself is cloned, but - * its contents are not) - */ - public Object clone() - { - Map.Entry entry; - Iterator it = entrySet().iterator(); - HashMap clone = new HashMap(capacity, loadFactor); - while (it.hasNext()) - { - entry = (Map.Entry) it.next(); - clone.internalPut(entry.getKey(), entry.getValue()); - } - return clone; - } - - /** returns a "set view" of this HashMap's keys */ - public Set keySet() - { - return new HashMapSet(KEYS); - } - - /** returns a "set view" of this HashMap's entries */ - public Set entrySet() - { - return new HashMapSet(ENTRIES); - } - - /** returns a "collection view" (or "bag view") of this HashMap's values */ - public Collection values() - { - return new HashMapCollection(); - } - - /** - * returns true if the supplied object equals (
equals()
) a key - * in this HashMap - * - * @param key the key to search for in this HashMap - */ - public boolean containsKey(Object key) - { - return (internalGet(key) != null); - } - - /** - * returns true if this HashMap contains a value
o
, such that - *
o.equals(value)
. - * - * @param value the value to search for in this Hashtable - */ - public boolean containsValue(Object value) - { - int i; - Bucket list; - - for (i = 0; i < capacity; i++) - { - list = buckets[i]; - if (list != null && list.containsValue(value)) - return true; - } - return false; - } - - /* - * return the value in this Hashtable associated with the supplied key, or
null
- * if the key maps to nothing - * - * @param key the key for which to fetch an associated value - */ - public Object get(Object key) - { - Map.Entry oResult = internalGet(key); - return (oResult == null) ? null : oResult.getValue(); - } - - /** - * puts the supplied value into the Map, mapped by the supplied key - * - * @param key the HashMap key used to locate the value - * @param value the value to be stored in the HashMap - */ - public Object put(Object key, Object value) - { - return internalPut(key, value); - } - - /** - * part of the Map interface; for each Map.Entry in t, the key / value pair is - * added to this Map, using the
put()
method -- this may not be - * you want, so be warned (if you override the put() method, this could lead to - * off behavior)
- * - * @param t a Map whose key / value pairs will be added to this Hashtable - */ - public void putAll(Map t) - { - Map.Entry entry; - Iterator it = t.entrySet().iterator(); - while (it.hasNext()) - { - entry = (Map.Entry) it.next(); - put(entry.getKey(), entry.getValue()); - } - } - - /** - * removes from the HashMap and returns the value which is mapped by the - * supplied key; if the key maps to nothing, then the HashMap remains unchanged, - * and
null
is returned - * - * @param key the key used to locate the value to remove from the HashMap - */ - public Object remove(Object key) - { - Bucket list; - int index; - Object result = null; - if (size > 0) - { - index = hash(((key == null) ? NULL_KEY : key)); - list = buckets[index]; - if (list != null) - { - result = list.removeByKey(key); - if (result != null) - { - size--; - modCount++; - if (list.first == null) - buckets[index] = null; - } - } - } - return result; - } - - - // PRIVATE METHODS ----------------------------------------------------------- - - /** - * puts the given key-value pair into this HashMap; a private method is used - * because it is called by the rehash() method as well as the put() method, - * and if a subclass overrides put(), then rehash would do funky things - * if it called put() - * - * @param key the HashMap key used to locate the value - * @param value the value to be stored in the HashMap - */ - private Object internalPut(Object key, Object value) - { - HashMapEntry entry; - Bucket list; - int hashIndex; - Object oResult; - Object oRealKey = ((key == null) ? NULL_KEY : key); - - modCount++; - if (size == threshold) - rehash(); - entry = new HashMapEntry(oRealKey, value); - hashIndex = hash(oRealKey); - list = buckets[hashIndex]; - if (list == null) - { - list = new Bucket(); - buckets[hashIndex] = list; - } - oResult = list.add(entry); - if (oResult == null) - { - size++; - return null; - } - else - { - return ((Map.Entry) oResult).getValue(); - } - } - - /** - * a private method, called by all of the constructors to initialize a new HashMap - * - * @param initialCapacity the initial capacity of this HashMap (>=0) - * @param initialLoadFactor the load factor of this HashMap - * (a misnomer, really, since the load factor of - * a HashMap does not change) - */ - private void init(int initialCapacity, float initialLoadFactor) - { - size = 0; - modCount = 0; - capacity = initialCapacity; - loadFactor = initialLoadFactor; - threshold = (int) ((float) capacity * loadFactor); - buckets = new Bucket[capacity]; - } - - /** private -- simply hashes a non-null Object to its array index */ - private int hash(Object key) - { - return Math.abs(key.hashCode() % capacity); - } - - /** - * increases the size of the HashMap and rehashes all keys to new array indices; - * this is called when the addition of a new value would cause size() > threshold - */ - private void rehash() - { - int i; - Bucket[] data = buckets; - Bucket.Node node; - - modCount++; - capacity = (capacity * 2) + 1; - size = 0; - threshold = (int) ((float) capacity * loadFactor); - buckets = new Bucket[capacity]; - for (i = 0; i < data.length; i++) - { - if (data[i] != null) - { - node = data[i].first; - while (node != null) - { - internalPut(node.getKey(), node.getValue()); - node = node.next; - } - } - } - } - - /** - * a private method which does the "dirty work" (or some of it anyway) of fetching a value - * with a key - * - * @param key the key for which to fetch an associated value - */ - private Map.Entry internalGet(Object key) - { - Bucket list; - if (size == 0) - { - return null; - } - else - { - list = buckets[hash(((key == null) ? NULL_KEY : key))]; - return (list == null) ? null : list.getEntryByKey(key); - } - } - - /** - * a private method used by inner class HashMapSet to implement its own - *
contains(Map.Entry)
method; returns true if the supplied - * key / value pair is found in this HashMap (again, using
equals()
, - * rather than
==
) - * - * @param entry a Map.Entry to match against key / value pairs in - * this HashMap - */ - private boolean containsEntry(Map.Entry entry) - { - Map.Entry oInternalEntry; - if (entry == null) - { - return false; - } - else - { - oInternalEntry = internalGet(entry.getKey()); - return (oInternalEntry != null && oInternalEntry.equals(entry)); - } - } - - /** - * Serializes this object to the given stream. - * @serialdata the capacity(int) that is the length of the - * bucket array, the size(int) of the hash map are emitted - * first. They are followed by size entries, each consisting of - * a key (Object) and a value (Object). - */ - private void writeObject(ObjectOutputStream s) - throws IOException - { - // the fields - s.defaultWriteObject(); - - s.writeInt(capacity); - s.writeInt(size); - Iterator it = entrySet().iterator(); - while (it.hasNext()) - { - Map.Entry oEntry = (Map.Entry) it.next(); - s.writeObject(oEntry.getKey()); - s.writeObject(oEntry.getValue()); - } - } - - /** - * Deserializes this object from the given stream. - * @serialdata the capacity(int) that is the length of the - * bucket array, the size(int) of the hash map are emitted - * first. They are followed by size entries, each consisting of - * a key (Object) and a value (Object). - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - // the fields - s.defaultReadObject(); - - capacity = s.readInt(); - int iLen = s.readInt(); - size = 0; - modCount = 0; - buckets = new Bucket[capacity]; - - for (int i = 0; i < iLen; i++) - { - Object oKey = s.readObject(); - Object oValue = s.readObject(); - internalPut(oKey, oValue); - } - } - - // INNER CLASSES ------------------------------------------------------------- - // --------------------------------------------------------------------------- - - /** - * an inner class providing a Set view of a HashMap; this implementation is - * parameterized to view either a Set of keys or a Set of Map.Entry objects - * - * Note: a lot of these methods are implemented by AbstractSet, and would work - * just fine without any meddling, but far greater efficiency can be gained by - * overriding a number of them. And so I did. - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ - private class HashMapSet extends AbstractSet - implements Set - { - /** the type of this Set view: KEYS or ENTRIES */ - private int setType; - - /** construct a new HashtableSet with the supplied view type */ - HashMapSet(int type) - { - setType = type; - } - - /** - * adding an element is unsupported; this method simply throws an exception - * - * @throws UnsupportedOperationException - */ - public boolean add(Object o) throws UnsupportedOperationException - { - throw new UnsupportedOperationException(); - } - - /** - * adding an element is unsupported; this method simply throws an exception - * - * @throws UnsupportedOperationException - */ - public boolean addAll(Collection c) throws UnsupportedOperationException - { - throw new UnsupportedOperationException(); - } - - /** - * clears the backing HashMap; this is a prime example of an overridden implementation - * which is far more efficient than its superclass implementation (which uses an iterator - * and is O(n) -- this is an O(1) call) - */ - public void clear() - { - HashMap.this.clear(); - } - - /** - * returns true if the supplied object is contained by this Set - * - * @param o an Object being testing to see if it is in this Set - */ - public boolean contains(Object o) - { - if (setType == KEYS) - return HashMap.this.containsKey(o); - else - return (o instanceof Map.Entry) ? HashMap.this.containsEntry((Map.Entry) o) : false; - } - - /** - * returns true if the backing HashMap is empty (which is the only case either a KEYS - * Set or an ENTRIES Set would be empty) - */ - public boolean isEmpty() - { - return HashMap.this.isEmpty(); - } - - /** - * removes the supplied Object from the Set - * - * @param o the Object to be removed - */ - public boolean remove(Object o) - { - if (setType == KEYS) - return (HashMap.this.remove(o) != null); - else - return (o instanceof Map.Entry) ? - (HashMap.this.remove(((Map.Entry) o).getKey()) != null) : false; - } - - /** returns the size of this Set (always equal to the size of the backing Hashtable) */ - public int size() - { - return HashMap.this.size(); - } - - /** returns an Iterator over the elements of this Set */ - public Iterator iterator() - { - return new HashMapIterator(setType); - } - } - - /** - * Like the above Set view, except this one if for values, which are not - * guaranteed to be unique in a Map; this prvides a Bag of values - * in the HashMap - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ - private class HashMapCollection extends AbstractCollection - implements Collection - { - /** a trivial contructor for HashMapCollection */ - HashMapCollection() - { - } - - /** - * adding elements is not supported by this Collection; - * this method merely throws an exception - * - * @throws UnsupportedOperationException - */ - public boolean add(Object o) throws UnsupportedOperationException - { - throw new UnsupportedOperationException(); - } - - /** - * adding elements is not supported by this Collection; - * this method merely throws an exception - * - * @throws UnsupportedOperationException - */ - public boolean addAll(Collection c) throws UnsupportedOperationException - { - throw new UnsupportedOperationException(); - } - - /** removes all elements from this Collection (and from the backing HashMap) */ - public void clear() - { - HashMap.this.clear(); - } - - /** - * returns true if this Collection contains at least one Object which equals() the - * supplied Object - * - * @param o the Object to compare against those in the Set - */ - public boolean contains(Object o) - { - return HashMap.this.containsValue(o); - } - - /** returns true IFF the Collection has no elements */ - public boolean isEmpty() - { - return HashMap.this.isEmpty(); - } - - /** returns the size of this Collection */ - public int size() - { - return HashMap.this.size(); - } - - /** returns an Iterator over the elements in this Collection */ - public Iterator iterator() - { - return new HashMapIterator(VALUES); - } - } - - /** - * a class which implements the Iterator interface and is used for - * iterating over HashMaps; - * this implementation is parameterized to give a sequential view of - * keys, values, or entries; it also allows the removal of elements, - * as per the Javasoft spec. - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ - class HashMapIterator implements Iterator - { - /** the type of this Iterator: KEYS, VALUES, or ENTRIES */ - private int myType; - /** - * the number of modifications to the backing Hashtable for which - * this Iterator can account (idea ripped off from Stuart Ballard) - */ - private int knownMods; - /** the location of our sequential "cursor" */ - private int position; - /** the current index of the BucketList array */ - private int bucketIndex; - /** a reference, originally null, to the specific Bucket our "cursor" is pointing to */ - private Bucket.Node currentNode; - /** a reference to the current key -- used fro removing elements via the Iterator */ - private Object currentKey; - - /** construct a new HashtableIterator with the supllied type: KEYS, VALUES, or ENTRIES */ - HashMapIterator(int type) - { - myType = type; - knownMods = HashMap.this.modCount; - position = 0; - bucketIndex = -1; - currentNode = null; - currentKey = null; - } - - /** - * Stuart Ballard's code: if the backing HashMap has been altered through anything - * but this Iterator's
remove()
method, we will give up right here, - * rather than risking undefined behavior - * - * @throws ConcurrentModificationException - */ - private void checkMod() - { - if (knownMods != HashMap.this.modCount) - throw new ConcurrentModificationException(); - } - - /** returns true if the Iterator has more elements */ - public boolean hasNext() - { - checkMod(); - return position < HashMap.this.size(); - } - - /** returns the next element in the Iterator's sequential view */ - public Object next() - { - Bucket list = null; - Object result; - checkMod(); - try - { - while (currentNode == null) - { - while (list == null) - list = HashMap.this.buckets[++bucketIndex]; - currentNode = list.first; - } - currentKey = currentNode.getKey(); - result = (myType == KEYS) ? currentKey : - ((myType == VALUES) ? currentNode.getValue() : currentNode); - currentNode = currentNode.next; - } - catch(Exception e) - { - throw new NoSuchElementException(); - } - position++; - return result; - } - - /** - * removes from the backing HashMap the last element which was fetched with the - *
next()
method - */ - public void remove() - { - checkMod(); - if (currentKey == null) - { - throw new IllegalStateException(); - } - else - { - HashMap.this.remove(currentKey); - knownMods++; - currentKey = null; - } - } - } - - /** - * a singleton instance of this class (HashMap.NULL_KEY) - * is used to represent the null key in HashMap objects - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ - private static class Null - { - /** trivial constructor */ - Null() - { - } - } - - /** - * a HashMap version of Map.Entry -- one thing in this implementation is - * HashMap-specific: if the key is HashMap.NULL_KEY, getKey() will return - * null - * - * Simply, a key / value pair - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ - private static class HashMapEntry extends Bucket.Node implements Map.Entry - { - /** construct a new HashMapEntry with the given key and value */ - public HashMapEntry(Object key, Object value) - { - super(key, value); - } - - /** - * if the key == HashMap.NULL_KEY, null is returned, otherwise the actual - * key is returned - */ - public Object getKey() - { - Object oResult = super.getKey(); - return (oResult == HashMap.NULL_KEY) ? null : oResult; - } - } - // EOF ----------------------------------------------------------------------- -} diff --git a/jode/jode/util/HashSet.java b/jode/jode/util/HashSet.java deleted file mode 100644 index 98b9bd1..0000000 --- a/jode/jode/util/HashSet.java +++ /dev/null @@ -1,238 +0,0 @@ -// This class is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// HashSet.java -- a class providing a HashMap-backet Set -// -// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// -package jode.util; - -import java.io.IOException; -import java.io.Serializable; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -/** - * This class provides a HashMap-backed implementation of the - * Set interface. - * - * Each element in the Set is a key in the backing HashMap; each key - * maps to a static token, denoting that the key does, in fact, exist. - * - * Most operations are O(1), assuming no hash collisions. In the worst - * case (where all hases collide), operations are O(n). - * - * HashSet is a part of the JDK1.2 Collections API. - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ -public class HashSet extends AbstractSet - implements Set, Cloneable, Serializable -{ - // INSTANCE VARIABLES ------------------------------------------------- - /** the HashMap which backs this Set */ - private transient HashMap map; - static final long serialVersionUID = -5024744406713321676L; - - // CONSTRUCTORS --------------------------------------------------------- - - /** - * construct a new, empty HashSet whose backing HashMap has the default - * capacity and loadFacor - */ - public HashSet() - { - map = new HashMap(); - } - - /** - * construct a new, empty HashSet whose backing HashMap has the supplied - * capacity and the default load factor - * - * @param initialCapacity the initial capacity of the backing - * HashMap - */ - public HashSet(int initialCapacity) - { - map = new HashMap(initialCapacity); - } - - /** - * construct a new, empty HashSet whose backing HashMap has the supplied - * capacity and load factor - * - * @param initialCapacity the initial capacity of the backing - * HashMap - * @param loadFactor the load factor of the backing HashMap - */ - public HashSet(int initialCapacity, float loadFactor) - { - map = new HashMap(initialCapacity, loadFactor); - } - - /** - * construct a new HashSet with the same elements as are in the supplied - * collection (eliminating any duplicates, of course; the backing HashMap - * will have the default capacity and load factor - * - * @param c a collection containing the elements with - * which this set will be initialized - */ - public HashSet(Collection c) - { - map = new HashMap(); - addAll(c); - } - - - // PUBLIC METHODS --------------------------------------------------------- - - /** - * adds the given Object to the set if it is not already in the Set, - * returns true if teh element was added, false otherwise - * - * @param o the Object to add to this Set - */ - public boolean add(Object o) - { - if (map.containsKey(o)) - { - return false; - } - else - { - internalAdd(o); - return true; - } - } - - /** - * empties this Set of all elements; this is a fast operation [O(1)] - */ - public void clear() - { - map.clear(); - } - - /** - * returns a shallow copy of this Set (the Set itself is cloned; its - * elements are not) - */ - public Object clone() - { - Iterator it = iterator(); - HashSet clone = new HashSet(map.capacity, map.loadFactor); - while (it.hasNext()) - clone.internalAdd(it.next()); - return clone; - } - - /** - * returns true if the supplied element is in this Set, false otherwise - * - * @param o the Object whose presence in this Set we are testing for - */ - public boolean contains(Object o) - { - return map.containsKey(o); - } - - /** - * returns true if this set has no elements in it (size() == 0) - */ - public boolean isEmpty() - { - return map.isEmpty(); - } - - /** - * returns an Iterator over the elements of this Set; the Iterator allows - * removal of elements - */ - public Iterator iterator() - { - return map.keySet().iterator(); - } - - /** - * removes the supplied Object from this Set if it is in the Set; returns - * true if an element was removed, false otherwise - */ - public boolean remove(Object o) - { - return (map.remove(o) != null); - } - - /** - * returns the number of elements in this Set - */ - public int size() - { - return map.size(); - } - - - // PRIVATE METHODS ----------------------------------------------------------- - - /** - * adds the supplied element to this Set; this private method is used - * internally [clone()] instead of add(), because add() can be overridden - * to do unexpected things - * - * @param o the Object to add to this Set - */ - private void internalAdd(Object o) - { - map.put(o, Boolean.TRUE); - } - - /** Serialize this Object in a manner which is binary-compatible with the JDK */ - private void writeObject(ObjectOutputStream s) throws IOException - { - Iterator it = iterator(); - s.writeInt(map.capacity); - s.writeFloat(map.loadFactor); - s.writeInt(size()); - while (it.hasNext()) - s.writeObject(it.next()); - } - - /** Deserialize this Object in a manner which is binary-compatible with the JDK */ - private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException - { - int i, iSize, iCapacity; - float fLoadFactor; - Object oElement; - - iCapacity = s.readInt(); - fLoadFactor = s.readFloat(); - iSize = s.readInt(); - - map = new HashMap(iCapacity, fLoadFactor); - - for (i = 0; i < iSize; i++) - { - oElement = s.readObject(); - internalAdd(oElement); - } - } -} diff --git a/jode/jode/util/Iterator.java b/jode/jode/util/Iterator.java deleted file mode 100644 index 2984f16..0000000 --- a/jode/jode/util/Iterator.java +++ /dev/null @@ -1,66 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// Iterator.java -- Interface for iterating over collections -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -package jode.util; - -/** - * An object which iterates over a collection. An Iterator is used to return the - * items once only, in sequence, by successive calls to the next method. It is - * also possible to remove elements from the underlying collection by using the - * optional remove method. Iterator is intended as a replacement for the - * Enumeration interface of previous versions of Java, which did not have the - * remove method and had less conveniently named methods. - */ -public interface Iterator { - - /** - * Tests whether there are elements remaining in the collection. - * - * @return true if there is at least one more element in the collection, - * that is, if the next call to next will not throw NoSuchElementException. - */ - boolean hasNext(); - - /** - * Obtain the next element in the collection. - * - * @return the next element in the collection - * @exception NoSuchElementException if there are no more elements - */ - Object next(); - - /** - * Remove from the underlying collection the last element returned by next. - * This method can be called only once after each call to next. It does not - * affect what will be returned by subsequent calls to next. This operation is - * optional, it may throw an UnsupportedOperationException. - * - * @exception IllegalStateException if next has not yet been called or remove - * has already been called since the last call to next. - * @exception UnsupportedOperationException if this Iterator does not support - * the remove operation. - */ - void remove(); -} diff --git a/jode/jode/util/LinkedList.java b/jode/jode/util/LinkedList.java deleted file mode 100644 index 9fe6cce..0000000 --- a/jode/jode/util/LinkedList.java +++ /dev/null @@ -1,581 +0,0 @@ -// This class is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// LinkedList.java -- Linked list implementation of the List interface -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -package jode.util; -import java.util.NoSuchElementException; -import java.io.Serializable; -import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; -import java.io.IOException; - -// TO DO: -// ~ Doc comment for the class. -// ~ Doc comments for the non-list methods. -// ~ Some commenting on the Backing API and other general implementation notes. - -/** - * Linked list implementation of the List interface. - */ -public class LinkedList extends AbstractSequentialList - implements Serializable, Cloneable -{ - static final long serialVersionUID = 876323262645176354L; - - /** - * An Entry containing the head (in the next field) and the tail (in the - * previous field) of the list. The data field is null. If the list is empty, - * both the head and the tail point to ends itself. - */ - transient Entry ends = new Entry(); - - /** - * The current length of the list. - */ - transient int size = 0; - - /** - * Class to represent an entry in the list. Holds a single element. - */ - private static class Entry { - - /** - * The list element. - */ - Object data = null; - - /** - * The next entry in the list. If this is the last entry in the list, the - * ends field of the list is held here. - */ - Entry next; - - /** - * The previous entry in the list. If this is the first entry in the list, - * the ends field of the list is held here. - */ - Entry previous; - - /** - * Create an entry with given data and linkage. - */ - Entry(Object d, Entry n, Entry p) { - data = d; - next = n; - previous = p; - } - - /** - * Create an entry with no data and linking to itself, for use as the ends - * field of the list. - */ - Entry() { - next = previous = this; - } - - /** - * Remove this entry. - */ - Object remove() { - previous.next = next; - next.previous = previous; - return data; - } - } - - private static interface Backing { - void checkMod(int known); - void upMod(); - void incSize(int by); - void decSize(int by); - } - - private final Backing back = new Backing() { - public void checkMod(int known) { - if (known != modCount) { - throw new ConcurrentModificationException(); - } - } - public void upMod() { - modCount++; - } - public void incSize(int by) { - size += by; - } - public void decSize(int by) { - size -= by; - } - }; - - /** A ListIterator over the list. This class keeps track of its - * position in the list, the size of the list, and the two list - * entries it is between. This enables it to be used identically - * for both the list itself and a sublist of the list. - */ - private static class Iter implements ListIterator { - - /** - * The index of the element that will be returned by next(). - */ - int pos; - - /** - * The size of the backing list. - */ - int size; - - /** - * The entry containing the element that will be returned by next(). - */ - Entry next; - - /** - * The entry containing the element that will be returned by previous(). - */ - Entry previous; - - /** - * The entry that will be affected by remove() or set(). - */ - Entry recent; - - /** - * The known value of the modCount of the backing list. - */ - int knownMod; - - private final Backing b; - - /** - * Create a new Iter starting at a given Entry within the list, at a given - * position, in a list of given size. - * - * @param index the index to begin iteration. - * @exception IndexOutOfBoundsException if index < 0 || index > size. - */ - Iter(Backing backing, Entry n, int index, int s, int mc) { - b = backing; - pos = index; - size = s; - next = n; - previous = n.previous; - knownMod = mc; - } - - public int nextIndex() { - b.checkMod(knownMod); - return pos; - } - - public int previousIndex() { - b.checkMod(knownMod); - return pos - 1; - } - - public boolean hasNext() { - b.checkMod(knownMod); - return pos < size; - } - - public boolean hasPrevious() { - b.checkMod(knownMod); - return pos > 0; - } - - public Object next() { - b.checkMod(knownMod); - if (pos >= size) { - throw new NoSuchElementException(); - } else { - pos++; - recent = previous = next; - next = recent.next; - return recent.data; - } - } - - public Object previous() { - b.checkMod(knownMod); - if (pos <= 0) { - throw new NoSuchElementException(); - } else { - pos--; - recent = next = previous; - previous = recent.previous; - return recent.data; - } - } - - public void remove() { - b.checkMod(knownMod); - if (recent == null) { - throw new IllegalStateException(); - } - - // Adjust the position to before the removed element - if (recent == previous) pos--; - - // Could use recent.remove() but this way is quicker, and also correctly - // fixes next and previous. - next = recent.previous.next = recent.next; - previous = recent.next.previous = recent.previous; - size--; - b.decSize(1); - knownMod++; - b.upMod(); - recent = null; - } - - public void add(Object o) { - b.checkMod(knownMod); - previous.next = next.previous = new Entry(o, next, previous); - - // New for 1.2RC1 - the semantics changed so that the iterator is - // positioned *after* the new element. - previous = next; - next = previous.next; - pos++; - - size++; - b.incSize(1); - knownMod++; - b.upMod(); - recent = null; - } - - public void set(Object o) { - b.checkMod(knownMod); - if (recent == null) { - throw new IllegalStateException(); - } - recent.data = o; - } - } - - /** - * Obtain the Entry at a given position in a list. This method of course - * takes linear time, but it is intelligent enough to take the shorter of the - * paths to get to the Entry required. This implies that the first or last - * entry in the list is obtained in constant time, which is a very desirable - * property. - * For speed and flexibility in which ranges are valid, range checking is not - * done in this method, and if n is outside the range -1 <= n <= size, the - * result will be wrong (but no exception will be thrown). - * Note that you *can* obtain entries at position -1 and size, which are - * equal to prehead and posttail respectively. - * This method is static so that it can also be used in subList. - * - * @param n the number of the entry to get. - * @param size the size of the list to get the entry in. - * @param head the entry before the first element of the list (usually ends). - * @param tail the entry after the last element of the list (usually ends). - */ - static Entry getEntry(int n, int size, Entry head, Entry tail) { - - // n less than size/2, iterate from start - if (n < size >> 1) { - while (n-- >= 0) { - head = head.next; - } - return head; - - // n greater than size/2, iterate from end - } else { - while (++n <= size) { - tail = tail.previous; - } - return tail; - } - } - - /** - * Create an empty linked list. - */ - public LinkedList() { - super(); - } - - /** - * Create a linked list containing the elements, in order, of a given - * collection. - * - * @param c the collection to populate this list from. - */ - public LinkedList(Collection c) { - super(); - // Note: addAll could be made slightly faster, but not enough so to justify - // re-implementing it from scratch. It is just a matter of a relatively - // small constant factor. - addAll(c); - } - - public Object getFirst() { - if (size == 0) { - throw new NoSuchElementException(); - } - return ends.next.data; - } - - public Object getLast() { - if (size == 0) { - throw new NoSuchElementException(); - } - return ends.previous.data; - } - - public Object removeFirst() { - if (size == 0) { - throw new NoSuchElementException(); - } - size--; - modCount++; - return ends.next.remove(); - } - - public Object removeLast() { - if (size == 0) { - throw new NoSuchElementException(); - } - size--; - modCount++; - return ends.previous.remove(); - } - - public void addFirst(Object o) { - ends.next.previous = ends.next = new Entry(o, ends.next, ends); - size++; - modCount++; - } - - public void addLast(Object o) { - ends.previous.next = ends.previous = new Entry(o, ends, ends.previous); - size++; - modCount++; - } - - /** - * Obtain the number of elements currently in this list. - * - * @returns the number of elements currently in this list. - */ - public int size() { - return size; - } - - /** - * Remove a range of elements from this list. - * - * @param fromIndex the index, inclusive, to remove from. - * @param toIndex the index, exclusive, to remove to. - * @exception IndexOutOfBoundsException if fromIndex > toIndex || fromIndex < - * 0 || toIndex > size(). - */ - // Note: normally removeRange is provided to allow efficient ways to - // implement clear() on subLists. However, in this case clear on subLists - // works anyway, so this implementation is included just for completeness - // and because subclasses might try to use it. - protected void removeRange(int fromIndex, int toIndex) { - subList(fromIndex, toIndex).clear(); - } - - /** - * Clear the list. - */ - public void clear() { - ends.next = ends.previous = ends; - modCount++; - size = 0; - } - - /** - * Obtain a ListIterator over this list, starting at a given index. The - * ListIterator returned by this method supports the add, remove and set - * methods. - * - * @param index the index of the element to be returned by the first call to - * next(), or size() to be initially positioned at the end of the list. - * @exception IndexOutOfBoundsException if index < 0 || index > size(). - */ - public ListIterator listIterator(int index) { - - // Check bounds - if (index < 0 || index > size) { - throw new IndexOutOfBoundsException(); - } - - return new Iter(back, getEntry(index, size, ends, ends), - index, size, modCount); - } - - /** - * Obtain a List view of a subsection of this list, from fromIndex - * (inclusive) to toIndex (exclusive). The returned list is modifiable in - * every respect. Changes to the returned list are reflected in this list. If - * this list is structurally modified is any way other than through the - * returned list, any subsequent operations on the returned list will result - * in a ConcurrentModificationException (that is, the returned list is - * fail-fast). - * - * @param fromIndex the index that the returned list should start from - * (inclusive). - * @param toIndex the index that the returned list should go to (exclusive). - * @returns a List backed by a subsection of this list. - * @exception IndexOutOfBoundsException if fromIndex < 0 || toIndex > size() - * || fromIndex > toIndex. - */ - public List subList(int fromIndex, int toIndex) { - - // Check bounds - if (fromIndex > toIndex || fromIndex < 0 || toIndex > size) { - throw new IndexOutOfBoundsException(); - } - - return new SubLinkedList(back, getEntry(fromIndex - 1, size, ends, ends), - getEntry(toIndex, size, ends, ends), - toIndex - fromIndex); - } - - private static class SubLinkedList extends AbstractSequentialList { - - Entry head; // entry before the beginning - Entry tail; // entry after the end - int size; - private final Backing b; - - private final Backing back = new Backing() { - public void checkMod(int known) { - if (known != modCount) { - throw new ConcurrentModificationException(); - } - } - public void upMod() { - modCount++; - } - public void incSize(int by) { - size += by; - } - public void decSize(int by) { - size -= by; - } - }; - - SubLinkedList(Backing backing, Entry h, Entry t, int s) { - b = backing; - head = h; - tail = t; - size = s; - } - - public int size() { - b.checkMod(this.modCount); - return size; - } - - public ListIterator listIterator(int index) { - b.checkMod(this.modCount); - - // Check bounds - if (index < 0 || index > size) { - throw new IndexOutOfBoundsException(); - } - - return new Iter(back, getEntry(index, size, head, tail), - index, size, modCount); - } - - public void clear() { - b.checkMod(this.modCount); - head.next = tail; - tail.previous = head; - size = 0; - b.decSize(size); - modCount++; - b.upMod(); - } - - // No removeRange because this class cannot be publically subclassed. - - public List subList(int fromIndex, int toIndex) { - b.checkMod(this.modCount); - - // Check bounds - if (fromIndex > toIndex || fromIndex < 0 || toIndex > size) { - throw new IndexOutOfBoundsException(); - } - - return new SubLinkedList(back, getEntry(fromIndex - 1, size, head, tail), - getEntry(toIndex, size, head, tail), - toIndex - fromIndex); - } - } - - /** - * Create a shallow copy of this LinkedList. - * @return an object of the same class as this object, containing the - * same elements in the same order. - */ - public Object clone() - { - LinkedList copy; - try - { - copy = (LinkedList) super.clone(); - } - catch (CloneNotSupportedException ex) - { - throw new InternalError(ex.getMessage()); - } - copy.size = 0; - copy.ends = new Entry(); - copy.addAll(this); - return copy; - } - - /** - * Serialize an object to a stream. - * @serialdata the size of the list (int), followed by all the elements - * (Object) in proper order. - */ - private void writeObject(ObjectOutputStream s) - throws IOException - { - s.writeInt(size); - for (Iterator i = iterator(); i.hasNext(); ) - s.writeObject(i.next()); - } - - /** - * Deserialize an object from a stream. - * @serialdata the size of the list (int), followed by all the elements - * (Object) in proper order. - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - int serialSize = s.readInt(); - ends = new Entry(); - for (int i=0; i< serialSize; i++) - addLast(s.readObject()); - } -} diff --git a/jode/jode/util/List.java b/jode/jode/util/List.java deleted file mode 100644 index 7e0c9ed..0000000 --- a/jode/jode/util/List.java +++ /dev/null @@ -1,331 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// List.java -- An ordered collection which allows indexed access -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Doc comment for the interface itself needs to be put into english. -// ~ Some more @see clauses might be nice. - -package jode.util; - -/** - * [This is what this doc comment will mention: - * ~ Additional restrictions on some methods. Others included for completeness. - * ~ ListIterator and what it can do - * ~ Positional and iterated access - * ~ search (but linear time) - * ~ be careful when containing self as an element, because equals and hashCode - * loop.] - */ -public interface List extends Collection { - - /** - * Insert an element into the list at a given position. - * - * @param index the location to insert the item. - * @param o the object to insert. - * @exception UnsupportedOperationException if this list does not support the - * add operation. - * @exception IndexOutOfBoundsException if index < 0 || index > size() - * @exception ClassCastException if o cannot be added to this list due to its - * type. - * @exception IllegalArgumentException if o cannot be added to this list for - * some other reason. - */ - void add(int index, Object o); - - /** - * Add an element to the end of the list. - * - * @param o the object to add. - * @returns true, as Collection defines this method as returning true if the - * list was modified as a result of this action, and it always is for a - * list. - * @exception UnsupportedOperationException if this list does not support the - * add operation. - * @exception ClassCastException if o cannot be added to this list due to its - * type. - * @exception IllegalArgumentException if o cannot be added to this list for - * some other reason. - */ - boolean add(Object o); - - /** - * Insert the contents of a collection into the list at a given position. - * - * @param index the location to insert the collection. - * @param c the collection to insert. - * @returns true if the list was modified by this action, that is, if c is - * non-empty. - * @exception UnsupportedOperationException if this list does not support the - * addAll operation. - * @exception IndexOutOfBoundsException if index < 0 || index > size() - * @exception ClassCastException if some element of c cannot be added to this - * list due to its type. - * @exception IllegalArgumentException if some element of c cannot be added - * to this list for some other reason. - */ - boolean addAll(int index, Collection c); - - /** - * Add the contents of a collection to the end of the list. - * - * @param c the collection to add. - * @returns true if the list was modified by this action, that is, if c is - * non-empty. - * @exception UnsupportedOperationException if this list does not support the - * addAll operation. - * @exception ClassCastException if some element of c cannot be added to this - * list due to its type. - * @exception IllegalArgumentException if some element of c cannot be added - * to this list for some other reason. - */ - boolean addAll(Collection c); - - /** - * Clear the list, such that a subsequent call to isEmpty() would return - * true. - * - * @exception UnsupportedOperationException if this list does not support the - * clear operation. - */ - void clear(); - - /** - * Test whether this list contains a given object as one of its elements. - * - * @param o the element to look for. - * @returns true if this list contains an element e such that o == - * null ? e == null : o.equals(e). - */ - boolean contains(Object o); - - /** - * Test whether this list contains every element in a given collection. - * - * @param c the collection to test for. - * @returns true if for every element o in c, contains(o) would return true. - */ - boolean containsAll(Collection c); - - /** - * Test whether this list is equal to another object. A List is defined to be - * equal to an object if and only if that object is also a List, and the two - * lists are equal. Two lists l1 and l2 are defined to be equal if and only - * if l1.size() == l2.size(), and for every integer n between 0 - * and l1.size() - 1 inclusive, l1.get(n) == null ? - * l2.get(n) == null : l1.get(n).equals(l2.get(n)). - * - * @param o the object to test for equality with this list. - * @returns true if o is equal to this list. - */ - boolean equals(Object o); - - /** - * Get the element at a given index in this list. - * - * @param index the index of the element to be returned. - * @returns the element at index index in this list. - * @exception IndexOutOfBoundsException if index < 0 || index >= size() - */ - Object get(int index); - - /** - * Obtain a hash code for this list. In order to obey the general contract of - * the hashCode method of class Object, this value is calculated as follows: - *
-   *   hashCode = 1;
-   *   Iterator i = list.iterator();
-   *   while (i.hasNext()) {
-   *     Object obj = i.next();
-   *     hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
-   *   }
-   * 
- * This ensures that the general contract of Object.hashCode() is adhered to. - * - * @returns the hash code of this list. - */ - int hashCode(); - - /** - * Obtain the first index at which a given object is to be found in this - * list. - * - * @returns the least integer n such that o == null ? get(n) == null : - * o.equals(get(n)), or -1 if there is no such index. - */ - int indexOf(Object o); - - /** - * Test whether this list is empty, that is, if size() == 0. - * - * @returns true if this list contains no elements. - */ - boolean isEmpty(); - - /** - * Obtain an Iterator over this list. - * - * @returns an Iterator over the elements of this list, in order. - */ - Iterator iterator(); - - /** - * Obtain the last index at which a given object is to be found in this - * list. - * - * @returns the greatest integer n such that o == null ? get(n) == null - * : o.equals(get(n)). - */ - int lastIndexOf(Object o); - - /** - * Obtain a ListIterator over this list, starting at the beginning. - * - * @returns a ListIterator over the elements of this list, in order, starting - * at the beginning. - */ - ListIterator listIterator(); - - /** - * Obtain a ListIterator over this list, starting at a given position. - * - * @param index the position, between 0 and size() inclusive, to begin the - * iteration from. - * @returns a ListIterator over the elements of this list, in order, starting - * at index. - * @exception IndexOutOfBoundsException if index < 0 || index > size() - */ - ListIterator listIterator(int index); - - /** - * Remove the element at a given position in this list. - * - * @param index the position within the list of the object to remove. - * @returns the object that was removed. - * @exception UnsupportedOperationException if this list does not support the - * remove operation. - * @exception IndexOutOfBoundsException if index < 0 || index > size() - */ - Object remove(int index); - - /** - * Remove the first occurence of an object from this list. That is, remove - * the first element e such that o == null ? e == null : - * o.equals(e). - * - * @param o the object to remove. - * @returns true if the list changed as a result of this call, that is, if - * the list contained at least one occurrence of o. - * @exception UnsupportedOperationException if this list does not support the - * remove operation. - */ - boolean remove(Object o); - - /** - * Remove all elements of a given collection from this list. That is, remove - * every element e such that c.contains(e). - * - * @returns true if this list was modified as a result of this call. - * @exception UnsupportedOperationException if this list does not support the - * removeAll operation. - */ - boolean removeAll(Collection c); - - /** - * Remove all elements of this list that are not contained in a given - * collection. That is, remove every element e such that !c.contains(e). - * - * @returns true if this list was modified as a result of this call. - * @exception UnsupportedOperationException if this list does not support the - * retainAll operation. - */ - boolean retainAll(Collection c); - - /** - * Replace an element of this list with another object. - * - * @param index the position within this list of the element to be replaced. - * @param o the object to replace it with. - * @returns the object that was replaced. - * @exception UnsupportedOperationException if this list does not support the - * set operation. - * @exception IndexOutOfBoundsException if index < 0 || index >= size() - * @exception ClassCastException if o cannot be added to this list due to its - * type. - * @exception IllegalArgumentException if o cannot be added to this list for - * some other reason. - */ - Object set(int index, Object o); - - /** - * Get the number of elements in this list. - * - * @returns the number of elements in the list. - */ - int size(); - - /** - * Obtain a List view of a subsection of this list, from fromIndex - * (inclusive) to toIndex (exclusive). The returned list should be modifiable - * if and only if this list is modifiable. Changes to the returned list - * should be reflected in this list. If this list is structurally modified in - * any way other than through the returned list, the result of any subsequent - * operations on the returned list is undefined. - * - * @param fromIndex the index that the returned list should start from - * (inclusive). - * @param toIndex the index that the returned list should go to (exclusive). - * @returns a List backed by a subsection of this list. - * @exception IndexOutOfBoundsException if fromIndex < 0 || toIndex > size() - * || fromIndex > toIndex. - */ - List subList(int fromIndex, int toIndex); - - /** - * Copy the current contents of this list into an array. - * - * @returns an array of type Object[] and length equal to the length of this - * list, containing the elements currently in this list, in order. - */ - Object[] toArray(); - - /** - * Copy the current contents of this list into an array. If the array passed - * as an argument has length less than that of this list, an array of the - * same run-time type as a, and length equal to the length of this list, is - * allocated using Reflection. Otherwise, a itself is used. The elements of - * this list are copied into it, and if there is space in the array, the - * following element is set to null. The resultant array is returned. - * Note: The fact that the following element is set to null is only useful - * if it is known that this list does not contain any null elements. - * - * @param a the array to copy this list into. - * @returns an array containing the elements currently in this list, in - * order. - * @exception ArrayStoreException if the type of any element of the - * collection is not a subtype of the element type of a. - */ - Object[] toArray(Object[] a); -} diff --git a/jode/jode/util/ListIterator.java b/jode/jode/util/ListIterator.java deleted file mode 100644 index ad72b53..0000000 --- a/jode/jode/util/ListIterator.java +++ /dev/null @@ -1,145 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// ListIterator.java -- Extended Iterator for iterating over ordered lists -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -package jode.util; - -/** - * An extended version of Iterator to support the extra features of Lists. The - * elements may be accessed in forward or reverse order, elements may be - * replaced as well as removed, and new elements may be inserted, during the - * traversal of the list. - */ -public interface ListIterator extends Iterator { - - /** - * Tests whether there are elements remaining in the list in the forward - * direction. - * - * @return true if there is at least one more element in the list in the - * forward direction, that is, if the next call to next will not throw - * NoSuchElementException. - */ - boolean hasNext(); - - /** - * Tests whether there are elements remaining in the list in the reverse - * direction. - * - * @return true if there is at least one more element in the list in the - * reverse direction, that is, if the next call to previous will not throw - * NoSuchElementException. - */ - boolean hasPrevious(); - - /** - * Obtain the next element in the list in the forward direction. Repeated - * calls to next may be used to iterate over the entire list, or calls to next - * and previous may be used together to go forwards and backwards. Alternating - * calls to next and previous will return the same element. - * - * @return the next element in the list in the forward direction - * @exception NoSuchElementException if there are no more elements - */ - Object next(); - - /** - * Obtain the next element in the list in the reverse direction. Repeated - * calls to previous may be used to iterate backwards over the entire list, or - * calls to next and previous may be used together to go forwards and - * backwards. Alternating calls to next and previous will return the same - * element. - * - * @return the next element in the list in the reverse direction - * @exception NoSuchElementException if there are no more elements - */ - Object previous(); - - /** - * Find the index of the element that would be returned by a call to next. - * - * @return the index of the element that would be returned by a call to next, - * or list.size() if the iterator is at the end of the list. - */ - int nextIndex(); - - /** - * Find the index of the element that would be returned by a call to previous. - * - * @return the index of the element that would be returned by a call to - * previous, or -1 if the iterator is at the beginning of the list. - */ - int previousIndex(); - - /** - * Insert an element into the list at the current position of the iterator. - * The element is inserted in between the element that would be returned by - * previous and the element that would be returned by next. After the - * insertion, a subsequent call to next is unaffected, but a call to - * previous returns the item that was added. This operation is optional, it - * may throw an UnsupportedOperationException. - * - * @param o the object to insert into the list - * @exception ClassCastException the object is of a type which cannot be added - * to this list - * @exception IllegalArgumentException some other aspect of the object stops - * it being added to this list - * @exception UnsupportedOperationException if this ListIterator does not - * support the add operation - */ - void add(Object o); - - /** - * Remove from the list the element last returned by a call to next or - * previous. This method may only be called if neither add nor remove have - * been called since the last call to next or previous. This operation is - * optional, it may throw an UnsupportedOperationException. - * - * @exception IllegalStateException if neither next or previous have been - * called, or if add or remove has been called since the last call to next - * or previous. - * @exception UnsupportedOperationException if this ListIterator does not - * support the remove operation. - */ - void remove(); - - /** - * Replace the element last returned by a call to next or previous with a - * given object. This method may only be called if neither add nor remove have - * been called since the last call to next or previous. This operation is - * optional, it may throw an UnsupportedOperationException. - * - * @param o the object to replace the element with - * @exception ClassCastException the object is of a type which cannot be added - * to this list - * @exception IllegalArgumentException some other aspect of the object stops - * it being added to this list - * @exception IllegalStateException if neither next or previous have been - * called, or if add or remove has been called since the last call to next - * or previous. - * @exception UnsupportedOperationException if this ListIterator does not - * support the set operation. - */ - void set(Object o); -} diff --git a/jode/jode/util/Makefile.am b/jode/jode/util/Makefile.am index 8074039..9e7849f 100644 --- a/jode/jode/util/Makefile.am +++ b/jode/jode/util/Makefile.am @@ -11,34 +11,7 @@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) MY_JAVA_FILES = \ SimpleMap.java \ SimpleSet.java \ - ArrayEnum.java \ - AbstractCollection.java \ - AbstractList.java \ - AbstractMap.java \ - AbstractSequentialList.java \ - AbstractSet.java \ - ArrayList.java \ - Arrays.java \ - BasicMapEntry.java \ - Bucket.java \ - Collection.java \ - Collections.java \ - Comparable.java \ - Comparator.java \ - ConcurrentModificationException.java \ - HashMap.java \ - HashSet.java \ - Iterator.java \ - LinkedList.java \ - List.java \ - ListIterator.java \ - Map.java \ - Set.java \ - SortedMap.java \ - SortedSet.java \ - TreeMap.java \ - TreeSet.java \ - UnsupportedOperationException.java + ArrayEnum.java noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) diff --git a/jode/jode/util/Map.java b/jode/jode/util/Map.java deleted file mode 100644 index 6058c07..0000000 --- a/jode/jode/util/Map.java +++ /dev/null @@ -1,55 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// Map.java -- An object that maps keys to values -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Doc comments for everything. - -package jode.util; - -public interface Map -{ - public void clear(); - public boolean containsKey(Object key); - public boolean containsValue(Object value); - public Set entrySet(); - public boolean equals(Object o); - public Object get(Object key); - public Object put(Object key, Object value); - public int hashCode(); - public boolean isEmpty(); - public Set keySet(); - public void putAll(Map m); - public Object remove(Object o); - public int size(); - public Collection values(); - - public static interface Entry { - public Object getKey(); - public Object getValue(); - public Object setValue(Object value); - public int hashCode(); - public boolean equals(Object o); - } -} diff --git a/jode/jode/util/Set.java b/jode/jode/util/Set.java deleted file mode 100644 index 69896e7..0000000 --- a/jode/jode/util/Set.java +++ /dev/null @@ -1,46 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// Set.java -- A collection that prohibits duplicates -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Doc comments for everything. - -package jode.util; - -public interface Set extends Collection { - boolean add(Object o); - boolean addAll(Collection c); - void clear(); - boolean contains(Object o); - boolean containsAll(Collection c); - boolean equals(Object o); - int hashCode(); - boolean isEmpty(); - Iterator iterator(); - boolean remove(Object o); - boolean removeAll(Collection c); - boolean retainAll(Collection c); - int size(); - Object[] toArray(); -} diff --git a/jode/jode/util/SimpleMap.java b/jode/jode/util/SimpleMap.java.in similarity index 69% rename from jode/jode/util/SimpleMap.java rename to jode/jode/util/SimpleMap.java.in index 3291dcc..b0ef122 100644 --- a/jode/jode/util/SimpleMap.java +++ b/jode/jode/util/SimpleMap.java.in @@ -18,12 +18,10 @@ */ package jode.util; -///#ifdef JDK12 -///import java.util.AbstractMap; -///import java.util.Map; -///import java.util.Iterator; -///import java.util.Set; -///#endif +import @COLLECTIONS@.AbstractMap; +import @COLLECTIONS@.Map; +import @COLLECTIONS@.Iterator; +import @COLLECTIONS@.Set; /** * This is a very simple map, using a set as backing. @@ -49,11 +47,41 @@ public class SimpleMap extends AbstractMap { return backing; } - public static class SimpleEntry extends BasicMapEntry { + public static class SimpleEntry implements Map.Entry { + Object key; + Object value; + public SimpleEntry(Object key, Object value) { - super(key, value); - } - } + this.key = key; + this.value = value; + } + + public Object getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object newValue) { + Object old = value; + value = newValue; + return old; + } + + public int hashCode() { + return key.hashCode() ^ value.hashCode(); + } + + public boolean equals(Object o) { + if (o instanceof Map.Entry) { + Map.Entry e = (Map.Entry) o; + return key.equals(e.getKey()) && value.equals(e.getValue()); + } + return false; + } + } public Object put(Object key, Object value) { for (Iterator i = backing.iterator(); diff --git a/jode/jode/util/SimpleSet.java b/jode/jode/util/SimpleSet.java.in similarity index 96% rename from jode/jode/util/SimpleSet.java rename to jode/jode/util/SimpleSet.java.in index f168b04..f71cbb1 100644 --- a/jode/jode/util/SimpleSet.java +++ b/jode/jode/util/SimpleSet.java.in @@ -18,10 +18,8 @@ */ package jode.util; -///#ifdef JDK12 -///import java.util.AbstractSet; -///import java.util.Iterator; -///#endif +import @COLLECTIONS@.AbstractSet; +import @COLLECTIONS@.Iterator; public class SimpleSet extends AbstractSet implements Cloneable { diff --git a/jode/jode/util/SortedMap.java b/jode/jode/util/SortedMap.java deleted file mode 100644 index 66fb250..0000000 --- a/jode/jode/util/SortedMap.java +++ /dev/null @@ -1,38 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// SortedMap.java -- A map that makes guarantees about the order of its keys -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Doc comments for everything. - -package jode.util; - -public interface SortedMap extends Map { - Comparator comparator(); - Object firstKey(); - SortedMap headMap(Object toKey); - Object lastKey(); - SortedMap subMap(Object fromKey, Object toKey); - SortedMap tailMap(Object fromKey); -} diff --git a/jode/jode/util/SortedSet.java b/jode/jode/util/SortedSet.java deleted file mode 100644 index 46c54bd..0000000 --- a/jode/jode/util/SortedSet.java +++ /dev/null @@ -1,38 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// SortedSet.java -- A set that makes guarantees about the order of its elements -// -// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// - -// TO DO: -// ~ Doc comments for everything. - -package jode.util; - -public interface SortedSet extends Set { - Comparator comparator(); - Object first(); - SortedSet headSet(Object toElement); - Object last(); - SortedSet subSet(Object fromElement, Object toElement); - SortedSet tailSet(Object fromElement); -} diff --git a/jode/jode/util/TreeMap.java b/jode/jode/util/TreeMap.java deleted file mode 100644 index c20b255..0000000 --- a/jode/jode/util/TreeMap.java +++ /dev/null @@ -1,1380 +0,0 @@ -// This class is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// TreeMap.java -- a class providing a basic Red-Black Tree data structure, -// mapping Object --> Object; part of the JDK1.2 collections -// API -// -// This is a JDK 1.2 compliant version of TreeMap.java -// -// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com), -// Free Software Foundation, Inc. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// -package jode.util; - -import java.util.NoSuchElementException; - -import java.io.Serializable; -import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; -import java.io.IOException; - -/** - * This class provides a red-black tree implementation of the SortedMap - * interface. Elements in the Map will be sorted by either a user-provided - * Comparator object, or by the natural ordering of the keys. - * - * The algorithms are adopted from Corman, Leiserson, - * and Rivest's Introduction to Algorithms. In other words, - * I cribbed from the same pseudocode as Sun. Any similarity - * between my code and Sun's (if there is any -- I have never looked - * at Sun's) is a result of this fact. - * - * TreeMap guarantees O(log n) insertion and deletion of elements. That - * being said, there is a large enough constant coefficient in front of - * that "log n" (overhead involved in keeping the tree - * balanced), that TreeMap may not be the best choice for small - * collections. - * - * TreeMap is a part of the JDK1.2 Collections API. Null keys are allowed - * only if a Comparator is used which can deal with them. Null values are - * always allowed. - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ -public class TreeMap extends AbstractMap - implements SortedMap, Cloneable, Serializable -{ - private static final int ENTRIES = 0; - private static final int KEYS = 1; - private static final int VALUES = 2; - - private static final int RED = -1; - private static final int BLACK = 1; - - private static final RBNode NIL = new RBNode(null, null); - - /** The root node of this TreeMap */ - transient RBNode _oRoot; - - /** The size of this TreeMap */ - transient int _iSize; - - /** Number of modifications */ - transient int _iModCount; - - /** This TreeMap's comparator */ - Comparator comparator; - - static final long serialVersionUID = 919286545866124006L; - - /** - * Instantiate a new TreeMap with no elements, using the keys' - * natural ordering to sort. - * - * @see java.lang.Comparable - */ - public TreeMap() - { - this((Comparator) null); - } - - /** - * Instantiate a new TreeMap with no elements, using the provided - * comparator to sort. - * - * @param oComparator a Comparator object, used to sort - * the keys of this SortedMap - */ - public TreeMap(Comparator oComparator) - { - _oRoot = NIL; - _iSize = 0; - _iModCount = 0; - comparator = oComparator; - } - - /** - * Instantiate a new TreeMap, initializing it with all of the - * elements in the provided Map. The elements will be sorted - * using the natural ordering of the keys. - * - * @param oMap a Map, whose keys will be put into - * this TreeMap - * - * @throws ClassCastException if the keys in the provided - * Map do not implement - * Comparable - * - * @see java.lang.Comparable - */ - public TreeMap(Map oMap) - { - this((Comparator) null); - putAll(oMap); - } - - /** - * Instantiate a new TreeMap, initializing it with all of the - * elements in the provided SortedMap. The elements will be sorted - * using the same method as in the provided SortedMap. - */ - public TreeMap(SortedMap oSortedMap) - { - this(oSortedMap.comparator()); - - Map.Entry[] arEntries = new Map.Entry[oSortedMap.size()]; - Iterator itElements = oSortedMap.entrySet().iterator(); - int i = 0; - - while (itElements.hasNext()) - arEntries[i++] = (Map.Entry) itElements.next(); - - _iSize = i; - putAllLinear(arEntries); - } - - public void clear() - { - _oRoot = NIL; - _iSize = 0; - _iModCount++; - } - - public Object clone() - { - TreeMap oClone; - - try - { - oClone = (TreeMap) super.clone(); - oClone._oRoot = _oRoot; - oClone.comparator = comparator; - oClone._iSize = _iSize; - oClone._iModCount = 0; - } - catch(CloneNotSupportedException e) - { - oClone = null; - } - - return oClone; - } - - public Comparator comparator() - { - return comparator; - } - - public boolean containsKey(Object oKey) - { - return (treeSearch(_oRoot, comparator, oKey) != NIL); - } - - public boolean containsValue(Object oValue) - { - RBNode oNode = _oRoot; - Object oCurrentValue; - - while (oNode != NIL) - { - oCurrentValue = oNode.getValue(); - - if (((oValue == null) && (oCurrentValue == null)) - || oValue.equals(oCurrentValue)) - return true; - - oNode = treeSuccessor(oNode); - } - return false; - } - - public Set entrySet() - { - return new TreeMapSet(this, ENTRIES); - } - - public Object firstKey() - { - try - { - return treeMin(_oRoot).getKey(); - } - catch(NullPointerException e) - { - throw new NoSuchElementException("TreeMap is empty"); - } - } - - public Object get(Object oKey) - { - RBNode oNode = treeSearch(_oRoot, comparator, oKey); - return (oNode != NIL) ? oNode.getValue() : null; - } - - public SortedMap headMap(Object oToKey) - { - if (keyInClosedMaxRange(comparator, oToKey, null)) - return new SubTreeMap(null, oToKey); - else - throw new IllegalArgumentException(getArgumentError("create a headMap", - null, null)); - } - - public Set keySet() - { - return new TreeMapSet(this, KEYS); - } - - public Object lastKey() - { - try - { - return treeMax(_oRoot).getKey(); - } - catch(NullPointerException e) - { - throw new NoSuchElementException("TreeMap is empty"); - } - } - - public Object put(Object oKey, Object oValue) - { - Map.Entry oEntry = rbInsert(this, comparator, new RBNode(oKey, oValue)); - if (oEntry == NIL) - _iSize++; - _iModCount++; - return ((oEntry == NIL) ? null : oEntry.getValue()); - } - - public void putAll(Map oMap) - { - Iterator itEntries = oMap.entrySet().iterator(); - Map.Entry oEntry; - - while (itEntries.hasNext()) - { - oEntry = (Map.Entry) itEntries.next(); - put(oEntry.getKey(), oEntry.getValue()); - } - } - - public Object remove(Object oKey) - { - RBNode oResult = treeSearch(_oRoot, comparator, oKey); - - if (oResult != NIL) - { - oResult = rbDelete(this, oResult); - _iSize--; - _iModCount++; - return oResult.getValue(); - } - else - { - return null; - } - } - - public int size() - { - return _iSize; - } - - public SortedMap subMap(Object oFromKey, Object oToKey) - { - if (compare(comparator, oFromKey, oToKey) < 0) - return new SubTreeMap(oFromKey, oToKey); - else - throw new IllegalArgumentException(getArgumentError("create a subMap", - null, null)); - } - - public SortedMap tailMap(Object oFromKey) - { - if (keyInMinRange(comparator, oFromKey, null)) - return new SubTreeMap(oFromKey, null); - else - throw new IllegalArgumentException(getArgumentError("create a tailMap", - null, null)); - } - - public Collection values() - { - return new TreeMapCollection(this); - } - - void putAllLinear(Map.Entry[] arEntries) - { - int iHeight; - double dHeight; - boolean boComplete; - - dHeight = Math.pow((double) arEntries.length, (double) 0.5); - iHeight = (int) dHeight; - boComplete = (dHeight == ((double) iHeight)); - - _oRoot = buildTree(arEntries, iHeight, boComplete, 0, 0, arEntries.length); - } - - private void writeObject(ObjectOutputStream oOut) throws IOException - { - RBNode oNode = treeMin(_oRoot); - oOut.defaultWriteObject(); - - oOut.writeInt(_iSize); - - while (oNode != NIL) - { - oOut.writeObject(oNode.getKey()); - oOut.writeObject(oNode.getValue()); - oNode = treeSuccessor(oNode); - } - } - - private void readObject(ObjectInputStream oIn) - throws IOException, ClassNotFoundException - { - int i; - Map.Entry[] arEntries; - oIn.defaultReadObject(); - _iSize = oIn.readInt(); - _iModCount = 0; - - arEntries = new Map.Entry[_iSize]; - for (i = 0; i < _iSize; i++) - arEntries[i] = new RBNode(oIn.readObject(), oIn.readObject()); - - putAllLinear(arEntries); - } - - - private static final RBNode buildTree(Map.Entry[] arEntries, int iHeight, - boolean boComplete, int iCurrentTier, - int iStart, int iStop) - { - RBNode oNewTree; - int iRootIndex; - - if (iStart == iStop) - { - return NIL; - } - else - { - iRootIndex = (iStop + iStart) / 2; - - oNewTree = new RBNode(arEntries[iRootIndex].getKey(), - arEntries[iRootIndex].getValue()); - oNewTree._oLeft = buildTree(arEntries, iHeight, boComplete, - (iCurrentTier + 1), iStart, iRootIndex); - oNewTree._oRight = buildTree(arEntries, iHeight, boComplete, - (iCurrentTier + 1), - (iRootIndex + 1), iStop); - - if ((!boComplete) && - ((iHeight % 2) == 1) && - (iCurrentTier >= (iHeight - 2))) - oNewTree._iColor = (iCurrentTier == (iHeight - 1)) ? RED : BLACK; - else - oNewTree._iColor = ((iCurrentTier % 2) == 1) ? RED : BLACK; - - if (oNewTree._oLeft != NIL) - oNewTree._oLeft._oParent = oNewTree; - if (oNewTree._oRight != NIL) - oNewTree._oRight._oParent = oNewTree; - return oNewTree; - } - } - - static final int compare(Comparator oComparator, Object oOne, Object oTwo) - { - return ((oComparator == null) - ? ((Comparable) oOne).compareTo(oTwo) - : oComparator.compare(oOne, oTwo)); - } - - static final boolean keyInMinRange(Comparator oComparator, - Object oKey, - Object oMinKey) - { - return ((oMinKey == null) || - (compare(oComparator, oMinKey, oKey) <= 0)); - } - - static final boolean keyInMaxRange(Comparator oComparator, - Object oKey, - Object oMaxKey) - { - return ((oMaxKey == null) || - (compare(oComparator, oMaxKey, oKey) > 0)); - } - - static final boolean keyInClosedMaxRange(Comparator oComparator, - Object oKey, - Object oMaxKey) - { - return ((oMaxKey == null) || - (compare(oComparator, oMaxKey, oKey) >= 0)); - } - - static final boolean keyInRange(Comparator oComparator, - Object oKey, - Object oMinKey, - Object oMaxKey) - { - return (keyInMinRange(oComparator, oKey, oMinKey) && - keyInMaxRange(oComparator, oKey, oMaxKey)); - } - - static final boolean keyInClosedRange(Comparator oComparator, - Object oKey, - Object oMinKey, - Object oMaxKey) - { - return (keyInMinRange(oComparator, oKey, oMinKey) && - keyInClosedMaxRange(oComparator, oKey, oMaxKey)); - } - - static final RBNode treeSearch(RBNode oRoot, - Comparator oComparator, - Object oKey) - { - int iCompareResult; - - while (oRoot != NIL) - { - iCompareResult = compare(oComparator, oKey, oRoot.getKey()); - if (iCompareResult == 0) - return oRoot; - else if (iCompareResult < 0) - oRoot = oRoot._oLeft; - else - oRoot = oRoot._oRight; - } - return oRoot; - } - - static final RBNode treeMin(RBNode oRoot) - { - while (oRoot._oLeft != NIL) - oRoot = oRoot._oLeft; - - return oRoot; - } - - static final RBNode treeMinConstrained(RBNode oRoot, - Comparator oComparator, - Object oMinKey, - Object oMaxKey) - { - int iCompare; - RBNode oCurrent; - - do - { - oCurrent = oRoot; - iCompare = compare(oComparator, oMinKey, oCurrent.getKey()); - - if (iCompare == 0) - return oRoot; - else - oRoot = (iCompare < 0) ? oCurrent._oLeft : oCurrent._oRight; - } - while (oRoot != NIL); - - if (iCompare > 0) - oCurrent = treeSuccessor(oCurrent); - - return oCurrent; - } - - static final RBNode treeMax(RBNode oRoot) - { - while (oRoot._oRight != NIL) - oRoot = oRoot._oRight; - - return oRoot; - } - - static final RBNode treeMaxConstrained(RBNode oRoot, - Comparator oComparator, - Object oMinKey, - Object oMaxKey) - { - int iCompare; - RBNode oCurrent; - - do - { - oCurrent = oRoot; - iCompare = compare(oComparator, oMaxKey, oCurrent.getKey()); - - if (iCompare == 0) - return oRoot; - else - oRoot = (iCompare < 0) ? oCurrent._oLeft : oCurrent._oRight; - } - while (oRoot != NIL); - - if (iCompare < 0) - oCurrent = treePredecessor(oCurrent); - - return oCurrent; - } - - static RBNode lowerBound(RBNode oRoot, Comparator oComparator, - Object oMinKey, Object oMaxKey) - { - return ((oMinKey != null) - ? treeMinConstrained(oRoot, oComparator, oMinKey, oMaxKey) - : treeMin(oRoot)); - } - - static RBNode upperBound(RBNode oRoot, Comparator oComparator, - Object oMinKey, Object oMaxKey) - { - return ((oMaxKey != null) - ? treeMaxConstrained(oRoot, oComparator, oMinKey, oMaxKey) - : NIL); - } - - static final RBNode treeSuccessor(RBNode oNode) - { - RBNode oParent; - - if (oNode._oRight != NIL) - return treeMin(oNode._oRight); - - oParent = oNode._oParent; - while ((oParent != NIL) && (oNode == oParent._oRight)) - { - oNode = oParent; - oParent = oParent._oParent; - } - - return oParent; - } - - static final RBNode treePredecessor(RBNode oNode) - { - RBNode oParent; - - if (oNode._oLeft != NIL) - return treeMax(oNode._oLeft); - - oParent = oNode._oParent; - while ((oParent != NIL) && (oNode == oParent._oLeft)) - { - oNode = oParent; - oParent = oParent._oParent; - } - - return oParent; - } - - static final String getArgumentError(String stType, - Object oMinKey, - Object oMaxKey) - { - return ("Attempt to " + stType + " outside of range [" + - oMinKey.toString() + ", " + oMaxKey.toString() + ")."); - } - - private static final RBNode treeInsert(TreeMap oTree, - Comparator oComparator, - RBNode oNewNode) - { - int iCompareResult; - Object oNewKey = oNewNode.getKey(); - RBNode oParent = NIL; - RBNode oRoot = oTree._oRoot; - RBNode oResult; - - while (oRoot != NIL) - { - oParent = oRoot; - - iCompareResult = compare(oComparator, oNewKey, oRoot.getKey()); - - if (iCompareResult == 0) - { - oResult = new RBNode(oRoot.getKey(), oRoot.getValue()); - oRoot.key = oNewNode.key; - oRoot.value = oNewNode.value; - return oResult; - } - else - { - oRoot = (iCompareResult < 0) ? oRoot._oLeft : oRoot._oRight; - } - } - - oNewNode._oParent = oParent; - if (oParent == NIL) - oTree._oRoot = oNewNode; - else if (compare(oComparator, oNewKey, oParent.getKey()) < 0) - oParent._oLeft = oNewNode; - else - oParent._oRight = oNewNode; - - return oRoot; - } - - private static final void leftRotate(TreeMap oTree, RBNode oNode) - { - RBNode oChild = oNode._oRight; - oNode._oRight = oChild._oLeft; - - if (oChild._oLeft != NIL) - oChild._oLeft._oParent = oNode; - - oChild._oParent = oNode._oParent; - - if (oNode._oParent == NIL) - oTree._oRoot = oChild; - else if (oNode == oNode._oParent._oLeft) - oNode._oParent._oLeft = oChild; - else - oNode._oParent._oRight = oChild; - - oChild._oLeft = oNode; - oNode._oParent = oChild; - } - - private static final void rightRotate(TreeMap oTree, RBNode oNode) - { - RBNode oChild = oNode._oLeft; - oNode._oLeft = oChild._oRight; - - if (oChild._oRight != NIL) - oChild._oRight._oParent = oNode; - - oChild._oParent = oNode._oParent; - - if (oNode._oParent == NIL) - oTree._oRoot = oChild; - else if (oNode == oNode._oParent._oRight) - oNode._oParent._oRight = oChild; - else - oNode._oParent._oLeft = oChild; - - oChild._oRight = oNode; - oNode._oParent = oChild; - } - - private static final RBNode rbInsert(TreeMap oTree, - Comparator oComparator, - RBNode oNode) - { - RBNode oUncle; - RBNode oResult = treeInsert(oTree, oComparator, oNode); - - if (oResult == NIL) - { - oNode._iColor = RED; - while ((oNode != oTree._oRoot) && (oNode._oParent._iColor == RED)) - { - if (oNode._oParent == oNode._oParent._oParent._oRight) - { - oUncle = oNode._oParent._oParent._oRight; - if (oUncle._iColor == RED) - { - oNode._oParent._iColor = BLACK; - oUncle._iColor = BLACK; - oNode._oParent._oParent._iColor = RED; - oNode = oNode._oParent._oParent; - } - else - { - if (oNode == oNode._oParent._oRight) - { - oNode = oNode._oParent; - leftRotate(oTree, oNode); - } - oNode._oParent._iColor = BLACK; - oNode._oParent._oParent._iColor = RED; - rightRotate(oTree, oNode._oParent._oParent); - } - } - else - { - oUncle = oNode._oParent._oParent._oLeft; - if (oUncle._iColor == RED) - { - oNode._oParent._iColor = BLACK; - oUncle._iColor = BLACK; - oNode._oParent._oParent._iColor = RED; - oNode = oNode._oParent._oParent; - } - else - { - if (oNode == oNode._oParent._oLeft) - { - oNode = oNode._oParent; - rightRotate(oTree, oNode); - } - oNode._oParent._iColor = BLACK; - oNode._oParent._oParent._iColor = RED; - leftRotate(oTree, oNode._oParent._oParent); - } - } - } - } - oTree._oRoot._iColor = BLACK; - return oResult; - } - - private static final RBNode rbDelete(TreeMap oTree, RBNode oNode) - { - RBNode oSplice; - RBNode oChild; - RBNode oSentinelParent = NIL; - RBNode oResult = oNode; - - oSplice = (((oNode._oLeft == NIL) || (oNode._oRight == NIL)) - ? oNode : treeSuccessor(oNode)); - oChild = (oSplice._oLeft != NIL) ? oSplice._oLeft : oSplice._oRight; - - oChild._oParent = oSplice._oParent; - - if (oSplice._oParent == NIL) - oTree._oRoot = oChild; - else if (oSplice == oSplice._oParent._oLeft) - oSplice._oParent._oLeft = oChild; - else - oSplice._oParent._oRight = oChild; - - if (oSplice != oNode) - { - oResult = new RBNode(oNode.getKey(), oNode.getValue()); - oNode.key = oSplice.key; - oNode.value = oSplice.value; - } - - if (oSplice._iColor == BLACK) - rbDeleteFixup(oTree, oChild); - - return oResult; - } - - private static final void rbDeleteFixup(TreeMap oTree, RBNode oNode) - { - RBNode oSibling; - - while ((oNode != oTree._oRoot) && (oNode._iColor == BLACK)) - { - if (oNode == oNode._oParent._oLeft) - { - oSibling = oNode._oParent._oRight; - if (oSibling._iColor == RED) - { - oSibling._iColor = BLACK; - oNode._oParent._iColor = RED; - leftRotate(oTree, oNode._oParent); - oSibling = oNode._oParent._oRight; - } - if ((oSibling._oLeft._iColor == BLACK) && - (oSibling._oRight._iColor == BLACK)) - { - oSibling._iColor = RED; - oNode = oNode._oParent; - } - else - { - if (oSibling._oRight._iColor == BLACK) - { - oSibling._oLeft._iColor = BLACK; - oSibling._iColor = RED; - rightRotate(oTree, oSibling); - oSibling = oNode._oParent._oRight; - } - oSibling._iColor = oNode._oParent._iColor; - oNode._oParent._iColor = BLACK; - oSibling._oRight._iColor = BLACK; - leftRotate(oTree, oNode._oParent); - oNode = oTree._oRoot; - } - } - else - { - oSibling = oNode._oParent._oLeft; - if (oSibling._iColor == RED) - { - oSibling._iColor = BLACK; - oNode._oParent._iColor = RED; - rightRotate(oTree, oNode._oParent); - oSibling = oNode._oParent._oLeft; - } - if ((oSibling._oRight._iColor == BLACK) && - (oSibling._oLeft._iColor == BLACK)) - { - oSibling._iColor = RED; - oNode = oNode._oParent; - } - else - { - if (oSibling._oLeft._iColor == BLACK) - { - oSibling._oRight._iColor = BLACK; - oSibling._iColor = RED; - leftRotate(oTree, oSibling); - oSibling = oNode._oParent._oLeft; - } - oSibling._iColor = oNode._oParent._iColor; - oNode._oParent._iColor = BLACK; - oSibling._oLeft._iColor = BLACK; - rightRotate(oTree, oNode._oParent); - oNode = oTree._oRoot; - } - } - } - - oNode._iColor = BLACK; - } - - private static class RBNode extends BasicMapEntry implements Map.Entry - { - int _iColor; - RBNode _oLeft; - RBNode _oRight; - RBNode _oParent; - - RBNode(Object oKey, Object oValue) - { - super(oKey, oValue); - _oLeft = NIL; - _oRight = NIL; - _oParent = NIL; - _iColor = BLACK; - } - } - - private class TreeMapSet extends AbstractSet implements Set - { - SortedMap _oMap; - int _iType; - - TreeMapSet(SortedMap oMap, int iType) - { - _oMap = oMap; - _iType = iType; - } - - /** - * adding an element is unsupported; this method simply - * throws an exception - * - * @throws UnsupportedOperationException - */ - public boolean add(Object oObject) throws UnsupportedOperationException - { - throw new UnsupportedOperationException(); - } - - /** - * adding an element is unsupported; this method simply throws - * an exception - * - * @throws UnsupportedOperationException - */ - public boolean addAll(Collection oCollection) - throws UnsupportedOperationException - { - throw new UnsupportedOperationException(); - } - - /** - * clears the backing TreeMap; this is a prime example of an - * overridden implementation which is far more efficient than - * its superclass implementation (which uses an iterator - * and is O(n) -- this is an O(1) call) - */ - public void clear() - { - _oMap.clear(); - } - - /** - * returns true if the supplied object is contained by this Set - * - * @param oObject an Object being testing to see if it is in this Set - */ - public boolean contains(Object oObject) - { - Map.Entry oEntry; - Object oKey; - Object oInputValue; - Object oMapValue; - - if (_iType == KEYS) - { - return _oMap.containsKey(oObject); - } - else if (oObject instanceof Map.Entry) - { - oEntry = (Map.Entry) oObject; - oKey = oEntry.getKey(); - - if (_oMap.containsKey(oKey)) - { - oInputValue = oEntry.getValue(); - oMapValue = _oMap.get(oKey); - return ((oInputValue == null) - ? (oMapValue == null) - : (oInputValue.equals(oMapValue))); - } - } - return false; - } - - /** - * returns true if the backing Map is empty (which is the only - * case either a KEYS Set or an ENTRIES Set would be empty) - */ - public boolean isEmpty() - { - return _oMap.isEmpty(); - } - - /** - * removes the supplied Object from the Set - * - * @param o the Object to be removed - */ - public boolean remove(Object oObject) - { - if (_iType == KEYS) - return (_oMap.remove(oObject) != null); - else - return (oObject instanceof Map.Entry) - ? (_oMap.remove(((Map.Entry) oObject).getKey()) != null) - : false; - } - - /** returns the size of this Set (always equal to the size of - * the backing Hashtable) */ - public int size() - { - return _oMap.size(); - } - - /** returns an Iterator over the elements in this set */ - public Iterator iterator() - { - return new TreeMapIterator(_oMap, _iType); - } - } - - private class TreeMapCollection extends AbstractCollection - implements Collection - { - private SortedMap _oMap; - - TreeMapCollection(SortedMap oMap) - { - _oMap = oMap; - } - - /** - * adding elements is not supported by this Collection; - * this method merely throws an exception - * - * @throws UnsupportedOperationException - */ - public boolean add(Object oObject) throws UnsupportedOperationException - { - throw new UnsupportedOperationException(); - } - - /** - * adding elements is not supported by this Collection; - * this method merely throws an exception - * - * @throws UnsupportedOperationException - */ - public boolean addAll(Collection oCollection) - throws UnsupportedOperationException - { - throw new UnsupportedOperationException(); - } - - /** removes all elements from this Collection (and from the - * backing TreeMap) */ - public void clear() - { - _oMap.clear(); - } - - /** - * returns true if this Collection contains at least one Object - * which equals() the supplied Object - * - * @param o the Object to compare against those in the Set - */ - public boolean contains(Object oObject) - { - return _oMap.containsValue(oObject); - } - - /** returns true IFF the Collection has no elements */ - public boolean isEmpty() - { - return _oMap.isEmpty(); - } - - /** returns the size of this Collection */ - public int size() - { - return _oMap.size(); - } - - /** returns an Iterator over the elements in this Collection */ - public Iterator iterator() - { - return new TreeMapIterator(_oMap, VALUES); - } - } - - private class TreeMapIterator implements Iterator - { - SortedMap _oMap; - int _iType; - int _iKnownMods; - RBNode _oFirst; - RBNode _oLast; - RBNode _oPrev; - - TreeMapIterator(SortedMap oMap, int iType) - { - TreeMap oBackingMap = TreeMap.this; - - _oMap = oMap; - _iType = iType; - _iKnownMods = oBackingMap._iModCount; - _oPrev = NIL; - - if (_oMap.isEmpty()) - { - _oFirst = NIL; - } - else - { - _oFirst = TreeMap.treeSearch(oBackingMap._oRoot, - oBackingMap.comparator, - _oMap.firstKey()); - _oLast = TreeMap.treeSearch(oBackingMap._oRoot, - oBackingMap.comparator, - _oMap.lastKey()); - } - } - - - /** - * Stuart Ballard's code: if the backing TreeMap has been altered - * through anything but this Iterator's
remove()
- * method, we will give up right here, rather than risking undefined - * behavior - * - * @throws ConcurrentModificationException - */ - private void checkMod() - { - if (_iKnownMods < TreeMap.this._iModCount) - throw new ConcurrentModificationException(); - } - - public boolean hasNext() - { - checkMod(); - return (_oFirst != NIL); - } - - public Object next() - { - checkMod(); - - RBNode oResult = _oFirst; - - if (oResult == NIL) - throw new NoSuchElementException(); - else if (oResult == _oLast) - _oFirst = NIL; - else - _oFirst = TreeMap.treeSuccessor(_oFirst); - - _oPrev = oResult; - - return ((_iType == KEYS) - ? oResult.getKey() - : ((_iType == VALUES) - ? oResult.getValue() - : oResult)); - } - - public void remove() - { - checkMod(); - - Object oKey; - - if (_oPrev == NIL) - { - throw new IllegalStateException("No previous call to next(), " + - "or remove() has already been " + - "called on this iteration."); - } - else - { - oKey = _oPrev.getKey(); - if (_oMap.containsKey(oKey)) - { - _oMap.remove(oKey); - _iKnownMods++; - } - _oPrev = NIL; - } - } - } - - - private class SubTreeMap extends AbstractMap implements SortedMap - { - Object _oMinKey; - Object _oMaxKey; - - SubTreeMap(Object oMinKey, Object oMaxKey) - { - _oMinKey = oMinKey; - _oMaxKey = oMaxKey; - } - - public void clear() - { - Object oMaxKey; - RBNode oMin = TreeMap.lowerBound(TreeMap.this._oRoot, - TreeMap.this.comparator, - _oMinKey, _oMaxKey); - RBNode oMax = TreeMap.upperBound(TreeMap.this._oRoot, - TreeMap.this.comparator, - _oMinKey, _oMaxKey); - oMaxKey = oMax.getKey(); - while ((oMin != NIL) && - ((oMax == NIL) || - (TreeMap.compare(TreeMap.this.comparator, - oMin.getKey(), oMaxKey) < 0))) - { - TreeMap.this.remove(oMin.getKey()); - oMin = TreeMap.treeSuccessor(oMin); - } - } - - public boolean containsKey(Object oKey) - { - return - (keyInRange(TreeMap.this.comparator, oKey, _oMinKey, _oMaxKey) && - TreeMap.this.containsKey(oKey)); - } - - public boolean containsValue(Object oValue) - { - Object oCurrentValue; - Object oMaxKey; - RBNode oMin = TreeMap.lowerBound(TreeMap.this._oRoot, - TreeMap.this.comparator, - _oMinKey, _oMaxKey); - RBNode oMax = TreeMap.upperBound(TreeMap.this._oRoot, - TreeMap.this.comparator, - _oMinKey, _oMaxKey); - - oMaxKey = oMax.getKey(); - while ((oMin != NIL) && - ((oMax == NIL) || - (TreeMap.compare(TreeMap.this.comparator, - oMin.getKey(), oMaxKey) < 0))) - { - oCurrentValue = oMin.getValue(); - - if (((oValue == null) && (oCurrentValue == null)) - || oValue.equals(oCurrentValue)) - return true; - oMin = treeSuccessor(oMin); - } - return false; - } - - public Object get(Object oKey) - { - if (keyInRange(TreeMap.this.comparator, oKey, _oMinKey, _oMaxKey)) - return TreeMap.this.get(oKey); - else - return null; - } - - public Object put(Object oKey, Object oValue) - { - if (keyInRange(TreeMap.this.comparator, oKey, _oMinKey, _oMaxKey)) - return TreeMap.this.put(oKey, oValue); - else - throw new IllegalArgumentException(getArgumentError("insert an entry", - _oMinKey, - _oMaxKey)); - } - - public void putAll(Map oMap) - { - Map.Entry oEntry; - Iterator itElements = oMap.entrySet().iterator(); - - while (itElements.hasNext()) - { - oEntry = (Map.Entry) itElements.next(); - put(oEntry.getKey(), oEntry.getValue()); - } - } - - public Object remove(Object oKey) - { - if (keyInRange(TreeMap.this.comparator, oKey, _oMinKey, _oMaxKey)) - return TreeMap.this.remove(oKey); - else - throw new IllegalArgumentException(getArgumentError("remove an entry", - _oMinKey, - _oMaxKey)); - } - - public int size() - { - int iCount = 0; - Object oMaxKey; - RBNode oMin = TreeMap.lowerBound(TreeMap.this._oRoot, - TreeMap.this.comparator, - _oMinKey, _oMaxKey); - RBNode oMax = TreeMap.upperBound(TreeMap.this._oRoot, - TreeMap.this.comparator, - _oMinKey, _oMaxKey); - - oMaxKey = oMax.getKey(); - while ((oMin != NIL) && - ((oMax == NIL) || - (TreeMap.compare(TreeMap.this.comparator, - oMin.getKey(), oMaxKey) < 0))) - { - iCount++; - oMin = TreeMap.treeSuccessor(oMin); - } - - return iCount; - } - - public Set entrySet() - { - return new TreeMapSet(this, ENTRIES); - } - - public Set keySet() - { - return new TreeMapSet(this, KEYS); - } - - public Collection values() - { - return new TreeMapCollection(this); - } - - public Comparator comparator() - { - return TreeMap.this.comparator; - } - - public Object firstKey() - { - RBNode oFirst = TreeMap.lowerBound(TreeMap.this._oRoot, - TreeMap.this.comparator, - _oMinKey, _oMaxKey); - - return (oFirst != NIL) ? oFirst.getKey() : null; - } - - public Object lastKey() - { - RBNode oLast; - - if (_oMaxKey == null) - { - oLast = TreeMap.treeMax(TreeMap.this._oRoot); - return (oLast != NIL) ? oLast.getKey() : null; - } - else - { - oLast = TreeMap.treeMaxConstrained(TreeMap.this._oRoot, - TreeMap.this.comparator, - _oMinKey, _oMaxKey); - return (oLast != NIL) ? TreeMap.treePredecessor(oLast).getKey() : null; - } - } - - public SortedMap subMap(Object oFromKey, Object oToKey) - { - if ((compare(comparator, oFromKey, oToKey) < 0) && - keyInMinRange(TreeMap.this.comparator, - oFromKey, _oMinKey) && - keyInClosedMaxRange(TreeMap.this.comparator, - oFromKey, _oMaxKey) && - keyInMinRange(TreeMap.this.comparator, - oToKey, _oMinKey) && - keyInClosedMaxRange(TreeMap.this.comparator, - oToKey, _oMaxKey)) - return new SubTreeMap(oFromKey, oToKey); - else - throw new IllegalArgumentException(getArgumentError("create a subMap", - _oMinKey, - _oMaxKey)); - } - - public SortedMap headMap(Object oToKey) - { - if (keyInMinRange(TreeMap.this.comparator, - oToKey, _oMinKey) && - keyInClosedMaxRange(TreeMap.this.comparator, - oToKey, _oMaxKey)) - return new SubTreeMap(_oMinKey, oToKey); - else - throw new IllegalArgumentException(getArgumentError("create a subMap", - _oMinKey, - _oMaxKey)); - } - - public SortedMap tailMap(Object oFromKey) - { - if (keyInMinRange(TreeMap.this.comparator, - oFromKey, _oMinKey) && - keyInClosedMaxRange(TreeMap.this.comparator, - oFromKey, _oMaxKey)) - return new SubTreeMap(oFromKey, _oMaxKey); - else - throw new IllegalArgumentException(getArgumentError("create a subMap", - _oMinKey, - _oMaxKey)); - } - } -} diff --git a/jode/jode/util/TreeSet.java b/jode/jode/util/TreeSet.java deleted file mode 100644 index 1ccf585..0000000 --- a/jode/jode/util/TreeSet.java +++ /dev/null @@ -1,331 +0,0 @@ -// This class is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -///////////////////////////////////////////////////////////////////////////// -// TreeSet.java -- a class providing a TreeMap-backet SortedSet -// -// Copyright (c) 1999 by Jon A. Zeppieri (jon@eease.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License as published -// by the Free Software Foundation, version 2. (see COPYING.LIB) -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public License -// along with this program; if not, write to the Free Software Foundation -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -///////////////////////////////////////////////////////////////////////////// -package jode.util; - -import java.io.IOException; -import java.io.Serializable; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -/** - * This class provides a TreeMap-backed implementation of the - * SortedSet interface. - * - * Each element in the Set is a key in the backing TreeMap; each key - * maps to a static token, denoting that the key does, in fact, exist. - * - * Most operations are O(log n). - * - * TreeSet is a part of the JDK1.2 Collections API. - * - * @author Jon Zeppieri - * @version $Revision$ - * @modified $Id$ - */ - -public class TreeSet extends AbstractSet - implements SortedSet, Cloneable, Serializable -{ - // INSTANCE VARIABLES ------------------------------------------------- - - /** The TreeMap which backs this Set */ - transient SortedMap _oMap; - static final long serialVersionUID = -2479143000061671589L; - - - // CONSTRUCTORS ------------------------------------------------------- - - /** - * Construct a new TreeSet whose backing TreeMap using the "natural" ordering - * of keys. - */ - public TreeSet() - { - this((Comparator) null); - } - - /** - * Construct a new TreeSet whose backing TreeMap uses the supplied - * Comparator. - * - * @param oComparator the Comparator this Set will use - */ - public TreeSet(Comparator oComparator) - { - _oMap = new TreeMap(oComparator); - } - - /** - * Construct a new TreeSet whose backing TreeMap uses the "natural" - * orering of the keys and which contains all of the elements in the - * supplied Collection. - * - * @param oCollection the new Set will be initialized with all - * of the elements in this Collection - */ - public TreeSet(Collection oCollection) - { - this((Comparator) null); - addAll(oCollection); - } - - /** - * Construct a new TreeSet, using the same key ordering as the supplied - * SortedSet and containing all of the elements in the supplied SortedSet. - * This constructor runs in linear time. - * - * @param oSortedSet the new TreeSet will use this SortedSet's - * comparator and will initialize itself - * with all of the elements in this SortedSet - */ - public TreeSet(SortedSet oSortedSet) - { - this(oSortedSet.comparator()); - - TreeMap oMap = (TreeMap) _oMap; - int i = 0; - Map.Entry[] arEntries = new Map.Entry[oSortedSet.size()]; - Iterator itEntries = oSortedSet.iterator(); - - while (itEntries.hasNext()) - arEntries[i++] = new BasicMapEntry(itEntries.next(), Boolean.TRUE); - - oMap._iSize = i; - oMap.putAllLinear(arEntries); - } - - TreeSet(SortedMap oMap) - { - _oMap = oMap; - } - - // METHODS ----------------------------------------------------------- - - /** - * Adds the spplied Object to the Set if it is not already in the Set; - * returns true if the element is added, false otherwise - * - * @param oObject the Object to be added to this Set - */ - public boolean add(Object oObject) - { - if (_oMap.containsKey(oObject)) - { - return false; - } - else - { - internalAdd(_oMap, oObject); - return true; - } - } - - /** - * Adds all of the elements in the supplied Collection to this TreeSet. - * - * @param oCollection All of the elements in this Collection - * will be added to the Set. - * - * @return true if the Set is altered, false otherwise - */ - public boolean addAll(Collection oCollection) - { - boolean boResult = false; - Iterator itElements = oCollection.iterator(); - - while (itElements.hasNext()) - boResult = (boResult || add(itElements.next())); - - return boResult; - } - - /** - * Removes all elements in this Set. - */ - public void clear() - { - _oMap.clear(); - } - - /** Returns a shallow copy of this Set. */ - public Object clone() - { - TreeSet oClone; - - try - { - oClone = (TreeSet) super.clone(); - oClone._oMap = _oMap; - } - catch(CloneNotSupportedException e) - { - oClone = null; - } - return oClone; - } - - /** Returns this Set's comparator */ - public Comparator comparator() - { - return _oMap.comparator(); - } - - /** - * Returns true if this Set contains the supplied Object, - * false otherwise - * - * @param oObject the Object whose existence in the Set is - * being tested - */ - public boolean contains(Object oObject) - { - return _oMap.containsKey(oObject); - } - - /** Returns true if this Set has size 0, false otherwise */ - public boolean isEmpty() - { - return _oMap.isEmpty(); - } - - /** Returns the number of elements in this Set */ - public int size() - { - return _oMap.size(); - } - - /** - * If the supplied Object is in this Set, it is removed, and true is - * returned; otherwise, false is returned. - * - * @param oObject the Object we are attempting to remove - * from this Set - */ - public boolean remove(Object oObject) - { - return (_oMap.remove(oObject) != null); - } - - /** Returns the first (by order) element in this Set */ - public Object first() - { - return _oMap.firstKey(); - } - - /** Returns the last (by order) element in this Set */ - public Object last() - { - return _oMap.lastKey(); - } - - /** - * Returns a view of this Set including all elements in the interval - * [oFromElement, oToElement). - * - * @param oFromElement the resultant view will contain all - * elements greater than or equal to this - * element - * @param oToElement the resultant view will contain all - * elements less than this element - */ - public SortedSet subSet(Object oFromElement, Object oToElement) - { - return new TreeSet(_oMap.subMap(oFromElement, oToElement)); - } - - /** - * Returns a view of this Set including all elements less than oToElement - * - * @param oToElement the resultant view will contain all - * elements less than this element - */ - public SortedSet headSet(Object oToElement) - { - return new TreeSet(_oMap.headMap(oToElement)); - } - - /** - * Returns a view of this Set including all elements greater than or - * equal to oFromElement. - * - * @param oFromElement the resultant view will contain all - * elements greater than or equal to this - * element - */ - public SortedSet tailSet(Object oFromElement) - { - return new TreeSet(_oMap.tailMap(oFromElement)); - } - - - /** Returns in Iterator over the elements in this TreeSet */ - public Iterator iterator() - { - return _oMap.keySet().iterator(); - } - - private void writeObject(ObjectOutputStream oOut) throws IOException - { - Iterator itElements = iterator(); - - oOut.writeObject(comparator()); - oOut.writeInt(size()); - - while (itElements.hasNext()) - oOut.writeObject(itElements.next()); - } - - private void readObject(ObjectInputStream oIn) - throws IOException, ClassNotFoundException - { - int i; - Map.Entry[] arEntries; - TreeMap oMap; - Comparator oComparator = (Comparator) oIn.readObject(); - int iSize = oIn.readInt(); - - arEntries = new Map.Entry[iSize]; - - for (i = 0; i < iSize; i++) - arEntries[iSize] = new BasicMapEntry(oIn.readObject(), Boolean.TRUE); - - oMap = new TreeMap(oComparator); - oMap._iSize = iSize; - oMap.putAllLinear(arEntries); - _oMap = oMap; - } - - /** - * adds the supplied element to this Set; this private method is used - * internally instead of add(), because add() can be overridden - * to do unexpected things - * - * @param o the Object to add to this Set - */ - private static final void internalAdd(Map oMap, Object oObject) - { - oMap.put(oObject, Boolean.TRUE); - } -} diff --git a/jode/jode/util/UnsupportedOperationException.java b/jode/jode/util/UnsupportedOperationException.java deleted file mode 100644 index 2934959..0000000 --- a/jode/jode/util/UnsupportedOperationException.java +++ /dev/null @@ -1,54 +0,0 @@ -// This interface is taken from the Classpath project. -// Please note the different copyright holder! -// The changes I did is this comment, the package line, some -// imports from java.util and some minor jdk12 -> jdk11 fixes. -// -- Jochen Hoenicke - -/************************************************************************* -/* UnsupportedOperationException.java -- Exception thrown when an -/* unsupported operation is attempted on an object -/* -/* Copyright (c) 1998 by Free Software Foundation, Inc. -/* -/* This program is free software; you can redistribute it and/or modify -/* it under the terms of the GNU Library General Public License as published -/* by the Free Software Foundation, version 2. (see COPYING.LIB) -/* -/* This program is distributed in the hope that it will be useful, but -/* WITHOUT ANY WARRANTY; without even the implied warranty of -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -/* GNU General Public License for more details. -/* -/* You should have received a copy of the GNU General Public License -/* along with this program; if not, write to the Free Software Foundation -/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -/*************************************************************************/ - -package jode.util; - -/** - * This exception is thrown by an object when an operation is - * requested of it that it does not support. - * - * @since JDK 1.2 - */ -public class UnsupportedOperationException extends RuntimeException -{ - static final long serialVersionUID = -1242599979055084673L; - - /** - * Create an exception without a message. - */ - public UnsupportedOperationException() - { - super(); - } - - /** - * Create an exception with a message. - */ - public UnsupportedOperationException( String s ) - { - super(s); - } -}