From 27d032c272ff4b647708b9e18d8bf79c24c82ffb Mon Sep 17 00:00:00 2001 From: jzhou Date: Fri, 18 Feb 2011 01:32:38 +0000 Subject: [PATCH] Updates of the class library for MGC --- Robust/src/ClassLibrary/File.java | 5 +- Robust/src/ClassLibrary/HashSet.java | 2 +- Robust/src/ClassLibrary/MGC/Object.java | 1 + Robust/src/ClassLibrary/MGC/ServerSocket.java | 28 + Robust/src/ClassLibrary/MGC/Set.java | 2 +- Robust/src/ClassLibrary/MGC/Socket.java | 83 +++ Robust/src/ClassLibrary/MGC/System.java | 29 +- Robust/src/ClassLibrary/MGC/Thread.java | 2 + Robust/src/ClassLibrary/MGC/Vector.java | 25 +- .../src/ClassLibrary/MGC/gnu/ArrayList.java | 6 + .../MGC/gnu/ArrayListIterator.java | 64 +++ .../src/ClassLibrary/MGC/gnu/BigInteger.java | 2 +- .../ClassLibrary/MGC/gnu/BufferedReader.java | 2 +- .../src/ClassLibrary/MGC/gnu/Cloneable.java | 78 +++ .../ClassLibrary/MGC/gnu/ConsoleHandler.java | 127 +++++ .../ClassLibrary/MGC/gnu/DecimalFormat.java | 32 +- Robust/src/ClassLibrary/MGC/gnu/File.java | 60 +++ .../ClassLibrary/MGC/gnu/FilenameFilter.java | 76 +++ Robust/src/ClassLibrary/MGC/gnu/Handler.java | 4 +- .../MGC/gnu/InputStreamReader.java | 499 ++++++++++++++++++ Robust/src/ClassLibrary/MGC/gnu/Level.java | 2 +- .../src/ClassLibrary/MGC/gnu/LogManager.java | 8 +- Robust/src/ClassLibrary/MGC/gnu/Logger.java | 16 +- .../src/ClassLibrary/MGC/gnu/PrintWriter.java | 10 +- .../src/ClassLibrary/MGC/gnu/Properties.java | 2 +- Robust/src/ClassLibrary/MGC/gnu/Short.java | 4 +- Robust/src/ClassLibrary/MGC/gnu/Stack.java | 160 ++++++ Robust/src/ClassLibrary/MGC/gnu/TreeMap.java | 9 +- .../ClassLibrary/MGC/gnu/TreeMapIterator.java | 15 +- Robust/src/ClassLibrary/MGC/gnu/TreeNode.java | 137 +++-- .../src/ClassLibrary/MGC/gnu/TreeSubMap.java | 2 +- Robust/src/ClassLibrary/String.java | 9 + Robust/src/ClassLibrary/StringBuffer.java | 50 ++ 33 files changed, 1462 insertions(+), 89 deletions(-) create mode 100644 Robust/src/ClassLibrary/MGC/ServerSocket.java create mode 100644 Robust/src/ClassLibrary/MGC/Socket.java create mode 100644 Robust/src/ClassLibrary/MGC/gnu/ArrayListIterator.java create mode 100644 Robust/src/ClassLibrary/MGC/gnu/Cloneable.java create mode 100644 Robust/src/ClassLibrary/MGC/gnu/ConsoleHandler.java create mode 100644 Robust/src/ClassLibrary/MGC/gnu/File.java create mode 100644 Robust/src/ClassLibrary/MGC/gnu/FilenameFilter.java create mode 100644 Robust/src/ClassLibrary/MGC/gnu/InputStreamReader.java create mode 100644 Robust/src/ClassLibrary/MGC/gnu/Stack.java diff --git a/Robust/src/ClassLibrary/File.java b/Robust/src/ClassLibrary/File.java index a0de2367..d4f0da39 100644 --- a/Robust/src/ClassLibrary/File.java +++ b/Robust/src/ClassLibrary/File.java @@ -1,6 +1,9 @@ +import java.io.FileSystem; +import java.io.FilenameFilter; +import java.util.ArrayList; + public class File { String path; - private static final char separator = '\n'; public File(String path) { this.path=path; diff --git a/Robust/src/ClassLibrary/HashSet.java b/Robust/src/ClassLibrary/HashSet.java index d3fe4fd5..4145f636 100644 --- a/Robust/src/ClassLibrary/HashSet.java +++ b/Robust/src/ClassLibrary/HashSet.java @@ -25,6 +25,6 @@ public class HashSet { return map.size(); } public HashMapIterator iterator() { - return map.iterator(0); + return (HashMapIterator)map.iterator(0); } } diff --git a/Robust/src/ClassLibrary/MGC/Object.java b/Robust/src/ClassLibrary/MGC/Object.java index 278d5c83..e94c34dc 100644 --- a/Robust/src/ClassLibrary/MGC/Object.java +++ b/Robust/src/ClassLibrary/MGC/Object.java @@ -35,5 +35,6 @@ public class Object { } public final native void notify(); + public final native void notifyAll(); public final native void wait(); } diff --git a/Robust/src/ClassLibrary/MGC/ServerSocket.java b/Robust/src/ClassLibrary/MGC/ServerSocket.java new file mode 100644 index 00000000..1cf07f29 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/ServerSocket.java @@ -0,0 +1,28 @@ +public class ServerSocket { + /* File Descriptor */ + int fd; + + private native int createSocket(int port); + + public ServerSocket(int port) { + this.fd=createSocket(port); + } + + public Socket accept() { + Socket s=new Socket(); + int newfd=nativeaccept(s); + s.setFD(newfd); + return s; + } + + /* Lets caller pass in their own Socket object. */ + public void accept(Socket s) { + int newfd=nativeaccept(s); + s.setFD(newfd); + } + + private native int nativeaccept(Socket s); + + public void close(); + +} diff --git a/Robust/src/ClassLibrary/MGC/Set.java b/Robust/src/ClassLibrary/MGC/Set.java index 8e59b91f..577b0e81 100644 --- a/Robust/src/ClassLibrary/MGC/Set.java +++ b/Robust/src/ClassLibrary/MGC/Set.java @@ -189,7 +189,7 @@ public interface Set// extends Collection * @throws NullPointerException if o is null and this set doesn't allow * the removal of a null value. */ - boolean remove(Object o); + //boolean remove(Object o); /** * Removes from this set all elements contained in the specified collection diff --git a/Robust/src/ClassLibrary/MGC/Socket.java b/Robust/src/ClassLibrary/MGC/Socket.java new file mode 100644 index 00000000..b4f54be4 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/Socket.java @@ -0,0 +1,83 @@ +public class Socket { + /* File Descriptor */ + int fd; + SocketInputStream sin; + SocketOutputStream sout; + + public Socket() { + sin=new SocketInputStream(this); + sout=new SocketOutputStream(this); + } + + public InputStream getInputStream() { + return sin; + } + + public OutputStream getOutputStream() { + return sout; + } + + public Socket(String host, int port) { + InetAddress address=InetAddress.getByName(host); + fd=nativeBind(address.getAddress(), port); + nativeConnect(fd, address.getAddress(), port); + sin=new SocketInputStream(this); + sout=new SocketOutputStream(this); + } + + public Socket(InetAddress address, int port) { + fd=nativeBind(address.getAddress(), port); + nativeConnect(fd, address.getAddress(), port); + sin=new SocketInputStream(this); + sout=new SocketOutputStream(this); + } + + public int connect(String host, int port) { + InetAddress address=InetAddress.getByName(host); + if (address != null) { + fd=nativeBind(address.getAddress(), port); + nativeConnect(fd, address.getAddress(), port); + return 0; + } + else { + return -1; + } + } + + public static native int nativeBind(byte[] address, int port); + + public static native int nativeConnect(int fd, byte[] address, int port); + + int setFD(int filed) { + fd=filed; + } + + public int read(byte[] b) { + return nativeRead(b); + } + public int write(byte[] b) { + nativeWrite(b, 0, b.length); + if(fd==-1) { + System.out.println("here: " + "fd= " + fd); + return -1; + } else { + return 0; + } + } + + public int write(byte[] b, int offset, int len) { + nativeWrite(b, offset, len); + if(fd==-1) + return -1; + else + return 0; + } + + private native int nativeRead(byte[] b); + private native void nativeWrite(byte[] b, int offset, int len); + private native void nativeClose(); + + public void close() { + nativeClose(); + } +} diff --git a/Robust/src/ClassLibrary/MGC/System.java b/Robust/src/ClassLibrary/MGC/System.java index 74a6c66f..01d46c81 100644 --- a/Robust/src/ClassLibrary/MGC/System.java +++ b/Robust/src/ClassLibrary/MGC/System.java @@ -1,10 +1,9 @@ -import java.util.Properties; - public class System { - PrintStream out; + public static PrintStream out = new PrintStream("System.out"); + public static PrintStream err = new PrintStream("System.err"); + public static InputStream in = new InputStream(); public System() { - out = new PrintStream("System.out"); } public static void printInt(int x) { @@ -101,4 +100,26 @@ public class System { public static Properties getProperties() { return props; } + + public static String getProperty(String key) { + if(props != null) { + return (String)props.getProperty(key); + } + return ""; + } + + public static String setProperty(String key, String value) { + if(props != null) { + return (String)props.setProperty(key, value); + } + return ""; + } + + public static void setOut(PrintStream out) { + out = out; + } + + public static void setErr(PrintStream err) { + err = err; + } } diff --git a/Robust/src/ClassLibrary/MGC/Thread.java b/Robust/src/ClassLibrary/MGC/Thread.java index af67dbf7..14ed23e5 100644 --- a/Robust/src/ClassLibrary/MGC/Thread.java +++ b/Robust/src/ClassLibrary/MGC/Thread.java @@ -37,5 +37,7 @@ public class Thread implements Runnable { } private native void nativeCreate(); + + public final native boolean isAlive(); } diff --git a/Robust/src/ClassLibrary/MGC/Vector.java b/Robust/src/ClassLibrary/MGC/Vector.java index 5f506edf..738b78a6 100644 --- a/Robust/src/ClassLibrary/MGC/Vector.java +++ b/Robust/src/ClassLibrary/MGC/Vector.java @@ -1,3 +1,5 @@ +import java.util.NoSuchElementException; + public class Vector implements Set { Object[] array; int size; @@ -40,10 +42,23 @@ public class Vector implements Set { return indexOf(e)!=-1; } - public void remove(Object o) { + /*public boolean remove(Object o) { int in=indexOf(o); - if (in!=-1) + if (in!=-1) { removeElementAt(in); + return true; + } else { + return false; + } + }*/ + + public Object remove(int index) { + Object r = null; + if (index!=-1) { + r = array[index]; + removeElementAt(index); + } + return r; } public Object elementAt(int index) { @@ -154,4 +169,10 @@ public class Vector implements Set { array=sarray; } + public synchronized Object firstElement() { + if (size == 0) { + throw new /*NoSuchElement*/Exception("NoSuchElement"); + } + return array[0]; + } } diff --git a/Robust/src/ClassLibrary/MGC/gnu/ArrayList.java b/Robust/src/ClassLibrary/MGC/gnu/ArrayList.java index 607a40cc..08bb4c64 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/ArrayList.java +++ b/Robust/src/ClassLibrary/MGC/gnu/ArrayList.java @@ -612,4 +612,10 @@ public class ArrayList for (int i = 0; i < size; i++) data[i] = (E) s.readObject(); }*/ + + public ArrayListIterator iterator() + { + // Bah, Sun's implementation forbids using listIterator(0). + return new ArrayListIterator(this); + } } diff --git a/Robust/src/ClassLibrary/MGC/gnu/ArrayListIterator.java b/Robust/src/ClassLibrary/MGC/gnu/ArrayListIterator.java new file mode 100644 index 00000000..cb3b226d --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/gnu/ArrayListIterator.java @@ -0,0 +1,64 @@ +public class ArrayListIterator extends Iterator { + private int pos; + private int size; + private int last; + private ArrayList list; + + public ArrayListIterator(ArrayList list) { + this.list = list; + this.pos = 0; + this.size = this.list.size(); + this.last = -1; + } + + /** + * Tests to see if there are any more objects to + * return. + * + * @return True if the end of the list has not yet been + * reached. + */ + public boolean hasNext() + { + return pos < size; + } + + /** + * Retrieves the next object from the list. + * + * @return The next object. + * @throws NoSuchElementException if there are + * no more objects to retrieve. + * @throws ConcurrentModificationException if the + * list has been modified elsewhere. + */ + public Object next() + { + if (pos == size) + throw new /*NoSuchElement*/Exception("NoSuchElementException"); + last = pos; + return this.list.get(pos++); + } + + /** + * Removes the last object retrieved by next() + * from the list, if the list supports object removal. + * + * @throws ConcurrentModificationException if the list + * has been modified elsewhere. + * @throws IllegalStateException if the iterator is positioned + * before the start of the list or the last object has already + * been removed. + * @throws UnsupportedOperationException if the list does + * not support removing elements. + */ + public void remove() + { + if (last < 0) + throw new /*IllegalState*/Exception("IllegalStateException"); + this.list.remove(last); + pos--; + size--; + last = -1; + } +} \ No newline at end of file diff --git a/Robust/src/ClassLibrary/MGC/gnu/BigInteger.java b/Robust/src/ClassLibrary/MGC/gnu/BigInteger.java index f9762df3..c61d4895 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/BigInteger.java +++ b/Robust/src/ClassLibrary/MGC/gnu/BigInteger.java @@ -695,7 +695,7 @@ public class BigInteger //extends Number implements Comparable private void set(BigInteger y) { if (y.words == null) - set(y.ival); + set((long)y.ival); else if (this != y) { realloc(y.ival); diff --git a/Robust/src/ClassLibrary/MGC/gnu/BufferedReader.java b/Robust/src/ClassLibrary/MGC/gnu/BufferedReader.java index f91bc4c8..d4d16297 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/BufferedReader.java +++ b/Robust/src/ClassLibrary/MGC/gnu/BufferedReader.java @@ -540,7 +540,7 @@ public class BufferedReader extends Reader if (count < avail) { - pos += count; + pos += (int)count; return count; } diff --git a/Robust/src/ClassLibrary/MGC/gnu/Cloneable.java b/Robust/src/ClassLibrary/MGC/gnu/Cloneable.java new file mode 100644 index 00000000..10f20ce3 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/gnu/Cloneable.java @@ -0,0 +1,78 @@ +/* Cloneable.java -- Interface for marking objects cloneable by Object.clone() + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * This interface should be implemented by classes wishing to + * support of override Object.clone(). The default + * behaviour of clone() performs a shallow copy, but + * subclasses often change this to perform a deep copy. Therefore, + * it is a good idea to document how deep your clone will go. + * If clone() is called on an object which does not + * implement this interface, a CloneNotSupportedException + * will be thrown. + * + *

This interface is simply a tagging interface; it carries no + * requirements on methods to implement. However, it is typical for + * a Cloneable class to implement at least equals, + * hashCode, and clone, sometimes + * increasing the accessibility of clone to be public. The typical + * implementation of clone invokes super.clone() + * rather than a constructor, but this is not a requirement. + * + *

If an object that implement Cloneable should not be cloned, + * simply override the clone method to throw a + * CloneNotSupportedException. + * + *

All array types implement Cloneable, and have a public + * clone method that will never fail with a + * CloneNotSupportedException. + * + * @author Paul Fisher + * @author Eric Blake (ebb9@email.byu.edu) + * @author Warren Levy (warrenl@cygnus.com) + * @see Object#clone() + * @see CloneNotSupportedException + * @since 1.0 + * @status updated to 1.4 + */ +public interface Cloneable +{ + // Tagging interface only. +} diff --git a/Robust/src/ClassLibrary/MGC/gnu/ConsoleHandler.java b/Robust/src/ClassLibrary/MGC/gnu/ConsoleHandler.java new file mode 100644 index 00000000..d064c547 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/gnu/ConsoleHandler.java @@ -0,0 +1,127 @@ +/* ConsoleHandler.java -- a class for publishing log messages to System.err + Copyright (C) 2002, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.util.logging; + +/** + * A ConsoleHandler publishes log records to + * System.err. + * + *

Configuration: Values of the subsequent + * LogManager properties are taken into consideration + * when a ConsoleHandler is initialized. + * If a property is not defined, or if it has an invalid + * value, a default is taken without an exception being thrown. + * + *

    + * + *
  • java.util.logging.ConsoleHandler.level - specifies + * the initial severity level threshold. Default value: + * Level.INFO.
  • + * + *
  • java.util.logging.ConsoleHandler.filter - specifies + * the name of a Filter class. Default value: No Filter.
  • + * + *
  • java.util.logging.ConsoleHandler.formatter - specifies + * the name of a Formatter class. Default value: + * java.util.logging.SimpleFormatter.
  • + * + *
  • java.util.logging.ConsoleHandler.encoding - specifies + * the name of the character encoding. Default value: + * the default platform encoding.
  • + * + *
+ * + * @author Sascha Brawer (brawer@acm.org) + */ +public class ConsoleHandler + extends StreamHandler +{ + /** + * Constructs a StreamHandler that publishes + * log records to System.err. The initial + * configuration is determined by the LogManager + * properties described above. + */ + public ConsoleHandler() + { + super(System.out, "java.util.logging.ConsoleHandler", Level.INFO, + /* formatter */ null/*, SimpleFormatter.class*/); + } + + + /** + * Forces any data that may have been buffered to the underlying + * output device, but does not close System.err. + * + *

In case of an I/O failure, the ErrorManager + * of this ConsoleHandler will be informed, but the caller + * of this method will not receive an exception. + */ + public void close() + { + //flush(); + System.println("Unimplemented ConsoleHandler.close()"); + } + + + /** + * Publishes a LogRecord to the console, provided the + * record passes all tests for being loggable. + * + *

Most applications do not need to call this method directly. + * Instead, they will use use a Logger, which will + * create LogRecords and distribute them to registered handlers. + * + *

In case of an I/O failure, the ErrorManager + * of this SocketHandler will be informed, but the caller + * of this method will not receive an exception. + * + *

The GNU implementation of ConsoleHandler.publish + * calls flush() for every request to publish a record, so + * they appear immediately on the console. + * + * @param record the log event to be published. + */ + public void publish(LogRecord record) + { + /*super.publish(record); + flush();*/ + System.println("Unimplemented ConsoleHandler.publish(LogRecord)"); + } +} diff --git a/Robust/src/ClassLibrary/MGC/gnu/DecimalFormat.java b/Robust/src/ClassLibrary/MGC/gnu/DecimalFormat.java index 57cd7b93..5cafa937 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/DecimalFormat.java +++ b/Robust/src/ClassLibrary/MGC/gnu/DecimalFormat.java @@ -299,13 +299,19 @@ public class DecimalFormat //extends NumberFormat * * @return A hash code. */ - public int hashCode() + /*public int hashCode() { return toPattern().hashCode(); - } + }*/ public StringBuffer format(long l) { - return null; + System.println("Unimplemented DecimalFormat.format(long)"); + return new StringBuffer(""); + } + + public StringBuffer format(double l) { + System.println("Unimplemented DecimalFormat.format(double)"); + return new StringBuffer(""); } /** @@ -2096,7 +2102,7 @@ public class DecimalFormat //extends NumberFormat * The integer totalDigitCount defines the total number of digits * of the number to which we are appending zeroes. */ - private void appendZero(StringBuffer dest, int zeroes, int totalDigitCount) + /*private void appendZero(StringBuffer dest, int zeroes, int totalDigitCount) { char ch = symbols.getZeroDigit(); char gSeparator = symbols.getGroupingSeparator(); @@ -2118,7 +2124,7 @@ public class DecimalFormat //extends NumberFormat (this.groupingUsed && this.groupingSize != 0) && (gPos % groupingSize == 0)) dest.append(gSeparator); - } + }*/ /** * Append src to dest. @@ -2126,7 +2132,7 @@ public class DecimalFormat //extends NumberFormat * Grouping is added if groupingUsed is set * to true. */ - private void appendDigit(String src, StringBuffer dest, + /*private void appendDigit(String src, StringBuffer dest, boolean groupingUsed) { int zero = symbols.getZeroDigit() - '0'; @@ -2144,7 +2150,7 @@ public class DecimalFormat //extends NumberFormat dest.append((char) (zero + ch)); } - } + }*/ /** * Calculate the exponent to use if eponential notation is used. @@ -2152,7 +2158,7 @@ public class DecimalFormat //extends NumberFormat * number should be positive, if is zero, or less than zero, * zero is returned. */ - private long getExponent(BigDecimal number) + /*private long getExponent(BigDecimal number) { long exponent = 0; @@ -2176,7 +2182,7 @@ public class DecimalFormat //extends NumberFormat } return exponent; - } + }*/ /** * Remove contiguos zeros from the end of the src string, @@ -2252,7 +2258,7 @@ public class DecimalFormat //extends NumberFormat // Anyway, these seem to be good values for a default in most languages. // Note that most of these will change based on the format string. - this.negativePrefix = String.valueOf(symbols.getMinusSign()); + this.negativePrefix = "-";//String.valueOf(symbols.getMinusSign()); this.negativeSuffix = ""; this.positivePrefix = ""; this.positiveSuffix = ""; @@ -2263,10 +2269,10 @@ public class DecimalFormat //extends NumberFormat this.hasNegativePrefix = false; - this.minimumIntegerDigits = 1; + /*this.minimumIntegerDigits = 1; this.maximumIntegerDigits = DEFAULT_INTEGER_DIGITS; this.minimumFractionDigits = 0; - this.maximumFractionDigits = DEFAULT_FRACTION_DIGITS; + this.maximumFractionDigits = DEFAULT_FRACTION_DIGITS;*/ this.minExponentDigits = 0; this.groupingSize = 0; @@ -2274,7 +2280,7 @@ public class DecimalFormat //extends NumberFormat this.decimalSeparatorAlwaysShown = false; this.showDecimalSeparator = false; this.useExponentialNotation = false; - this.groupingUsed = false; + //this.groupingUsed = false; this.groupingSeparatorInPattern = false; this.useCurrencySeparator = false; diff --git a/Robust/src/ClassLibrary/MGC/gnu/File.java b/Robust/src/ClassLibrary/MGC/gnu/File.java new file mode 100644 index 00000000..5ecf4d32 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/gnu/File.java @@ -0,0 +1,60 @@ +import java.io.FileSystem; +import java.io.FilenameFilter; +import java.util.ArrayList; + +public class File { + String path; + private static final char separator = '\n'; + private static final char separatorChar = '\n'; + private static final char pathSeparatorChar = ';'; + + public File(String path) { + this.path=path; + } + + String getPath() { + return path; + } + + long length() { + return nativeLength(path.getBytes()); + } + + private static native long nativeLength(byte[] pathname); + + public boolean exists() { + System.println("Unimplemented File.exists()"); + return false; + } + + public boolean isDirectory() { + System.println("Unimplemented File.isDirectory()"); + return false; + } + + public boolean mkdirs() { + System.println("Unimplemented File.mkdirs()"); + return false; + } + + public boolean delete() { + System.println("Unimplemented File.delete()"); + return false; + } + + public String[] list(FilenameFilter filter) { + /*String names[] = list(); + if ((names == null) || (filter == null)) { + return names; + } + ArrayList v = new ArrayList(); + for (int i = 0 ; i < names.length ; i++) { + if (filter.accept(this, names[i])) { + v.add(names[i]); + } + } + return (String[])(v.toArray(new String[0]));*/ + System.println("Unimplemented File.list()"); + return null; + } +} diff --git a/Robust/src/ClassLibrary/MGC/gnu/FilenameFilter.java b/Robust/src/ClassLibrary/MGC/gnu/FilenameFilter.java new file mode 100644 index 00000000..57b4d3b1 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/gnu/FilenameFilter.java @@ -0,0 +1,76 @@ +/* FilenameFilter.java -- Filter a list of filenames + Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.io; + +/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 + * "The Java Language Specification", ISBN 0-201-63451-1 + * Status: Complete to 1.1. + */ + +/** + * This interface has one method which is used for filtering filenames + * returned in a directory listing. It is currently used by the + * File.list(FilenameFilter) method and by the filename + * dialog in AWT. + *

+ * The method in this interface determines if a particular file should + * or should not be included in the file listing. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) + * + * @see File#listFiles(java.io.FilenameFilter) + * @see java.awt.FileDialog#setFilenameFilter(java.io.FilenameFilter) + */ +public interface FilenameFilter +{ + /** + * This method determines whether or not a given file should be included + * in a directory listing. + * + * @param dir The File instance for the directory being read + * @param name The name of the file to test + * + * @return true if the file should be included in the list, + * false otherwise. + */ + boolean accept(File dir, String name); + +} // interface FilenameFilter + diff --git a/Robust/src/ClassLibrary/MGC/gnu/Handler.java b/Robust/src/ClassLibrary/MGC/gnu/Handler.java index 09d5a8e8..774d39a5 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/Handler.java +++ b/Robust/src/ClassLibrary/MGC/gnu/Handler.java @@ -116,7 +116,7 @@ h.setFormatter(h.getFormatter()); * of this Handler will be informed, but the caller * of this method will not receive an exception. */ - //public abstract void flush(); + public /*abstract */void flush(){} /** @@ -135,7 +135,7 @@ h.setFormatter(h.getFormatter()); * the caller is not granted the permission to control * the logging infrastructure. */ - //public abstract void close() + public /*abstract*/ void close(){} // throws SecurityException; diff --git a/Robust/src/ClassLibrary/MGC/gnu/InputStreamReader.java b/Robust/src/ClassLibrary/MGC/gnu/InputStreamReader.java new file mode 100644 index 00000000..0db5b71b --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/gnu/InputStreamReader.java @@ -0,0 +1,499 @@ +/* InputStreamReader.java -- Reader than transforms bytes to chars + Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.io; + +/** + * This class reads characters from a byte input stream. The characters + * read are converted from bytes in the underlying stream by a + * decoding layer. The decoding layer transforms bytes to chars according + * to an encoding standard. There are many available encodings to choose + * from. The desired encoding can either be specified by name, or if no + * encoding is selected, the system default encoding will be used. The + * system default encoding name is determined from the system property + * file.encoding. The only encodings that are guaranteed to + * be availalbe are "8859_1" (the Latin-1 character set) and "UTF8". + * Unforunately, Java does not provide a mechanism for listing the + * ecodings that are supported in a given implementation. + *

+ * Here is a list of standard encoding names that may be available: + *

+ *

    + *
  • 8859_1 (ISO-8859-1/Latin-1)
  • + *
  • 8859_2 (ISO-8859-2/Latin-2)
  • + *
  • 8859_3 (ISO-8859-3/Latin-3)
  • + *
  • 8859_4 (ISO-8859-4/Latin-4)
  • + *
  • 8859_5 (ISO-8859-5/Latin-5)
  • + *
  • 8859_6 (ISO-8859-6/Latin-6)
  • + *
  • 8859_7 (ISO-8859-7/Latin-7)
  • + *
  • 8859_8 (ISO-8859-8/Latin-8)
  • + *
  • 8859_9 (ISO-8859-9/Latin-9)
  • + *
  • ASCII (7-bit ASCII)
  • + *
  • UTF8 (UCS Transformation Format-8)
  • + *
  • More later
  • + *
+ *

+ * It is recommended that applications do not use + * InputStreamReader's + * directly. Rather, for efficiency purposes, an object of this class + * should be wrapped by a BufferedReader. + *

+ * Due to a deficiency the Java class library design, there is no standard + * way for an application to install its own byte-character encoding. + * + * @see BufferedReader + * @see InputStream + * + * @author Robert Schuster + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Per Bothner (bothner@cygnus.com) + * @date April 22, 1998. + */ +public class InputStreamReader extends Reader +{ + /** + * The input stream. + */ + private InputStream in; + + /** + * The charset decoder. + */ + //private CharsetDecoder decoder; + + /** + * End of stream reached. + */ + private boolean isDone = false; + + /** + * Need this. + */ + //private float maxBytesPerChar; + + /** + * Buffer holding surplus loaded bytes (if any) + */ + //private ByteBuffer byteBuffer; + + /** + * java.io canonical name of the encoding. + */ + //private String encoding; + + /** + * We might decode to a 2-char UTF-16 surrogate, which won't fit in the + * output buffer. In this case we need to save the surrogate char. + */ + //private char savedSurrogate; + //private boolean hasSavedSurrogate = false; + + /** + * A byte array to be reused in read(byte[], int, int). + */ + //private byte[] bytesCache; + + /** + * Locks the bytesCache above in read(byte[], int, int). + */ + //private Object cacheLock = new Object(); + + /** + * This method initializes a new instance of InputStreamReader + * to read from the specified stream using the default encoding. + * + * @param in The InputStream to read from + */ + public InputStreamReader(InputStream in) + { + if (in == null) + throw new /*NullPointer*/Exception("NullPointerException"); + this.in = in; + /*try + { + encoding = SystemProperties.getProperty("file.encoding"); + // Don't use NIO if avoidable + if(EncodingHelper.isISOLatin1(encoding)) + { + encoding = "ISO8859_1"; + maxBytesPerChar = 1f; + decoder = null; + return; + } + Charset cs = EncodingHelper.getCharset(encoding); + decoder = cs.newDecoder(); + encoding = EncodingHelper.getOldCanonical(cs.name()); + try { + maxBytesPerChar = cs.newEncoder().maxBytesPerChar(); + } catch(UnsupportedOperationException _){ + maxBytesPerChar = 1f; + } + decoder.onMalformedInput(CodingErrorAction.REPLACE); + decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); + decoder.reset(); + } catch(RuntimeException e) { + encoding = "ISO8859_1"; + maxBytesPerChar = 1f; + decoder = null; + } catch(UnsupportedEncodingException e) { + encoding = "ISO8859_1"; + maxBytesPerChar = 1f; + decoder = null; + }*/ + } + + /** + * This method initializes a new instance of InputStreamReader + * to read from the specified stream using a caller supplied character + * encoding scheme. Note that due to a deficiency in the Java language + * design, there is no way to determine which encodings are supported. + * + * @param in The InputStream to read from + * @param encoding_name The name of the encoding scheme to use + * + * @exception UnsupportedEncodingException If the encoding scheme + * requested is not available. + */ + /*public InputStreamReader(InputStream in, String encoding_name) + throws UnsupportedEncodingException + { + if (in == null + || encoding_name == null) + throw new NullPointerException(); + + this.in = in; + // Don't use NIO if avoidable + if(EncodingHelper.isISOLatin1(encoding_name)) + { + encoding = "ISO8859_1"; + maxBytesPerChar = 1f; + decoder = null; + return; + } + try { + Charset cs = EncodingHelper.getCharset(encoding_name); + try { + maxBytesPerChar = cs.newEncoder().maxBytesPerChar(); + } catch(UnsupportedOperationException _){ + maxBytesPerChar = 1f; + } + + decoder = cs.newDecoder(); + decoder.onMalformedInput(CodingErrorAction.REPLACE); + decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); + decoder.reset(); + + // The encoding should be the old name, if such exists. + encoding = EncodingHelper.getOldCanonical(cs.name()); + } catch(RuntimeException e) { + encoding = "ISO8859_1"; + maxBytesPerChar = 1f; + decoder = null; + } + }*/ + + /** + * Creates an InputStreamReader that uses a decoder of the given + * charset to decode the bytes in the InputStream into + * characters. + * + * @since 1.4 + */ + /*public InputStreamReader(InputStream in, Charset charset) { + if (in == null) + throw new NullPointerException(); + this.in = in; + decoder = charset.newDecoder(); + + try { + maxBytesPerChar = charset.newEncoder().maxBytesPerChar(); + } catch(UnsupportedOperationException _){ + maxBytesPerChar = 1f; + } + + decoder.onMalformedInput(CodingErrorAction.REPLACE); + decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); + decoder.reset(); + encoding = EncodingHelper.getOldCanonical(charset.name()); + }*/ + + /** + * Creates an InputStreamReader that uses the given charset decoder + * to decode the bytes in the InputStream into characters. + * + * @since 1.4 + */ + /*public InputStreamReader(InputStream in, CharsetDecoder decoder) { + if (in == null) + throw new NullPointerException(); + this.in = in; + this.decoder = decoder; + + Charset charset = decoder.charset(); + try { + if (charset == null) + maxBytesPerChar = 1f; + else + maxBytesPerChar = charset.newEncoder().maxBytesPerChar(); + } catch(UnsupportedOperationException _){ + maxBytesPerChar = 1f; + } + + decoder.onMalformedInput(CodingErrorAction.REPLACE); + decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); + decoder.reset(); + if (charset == null) + encoding = "US-ASCII"; + else + encoding = EncodingHelper.getOldCanonical(decoder.charset().name()); + }*/ + + /** + * This method closes this stream, as well as the underlying + * InputStream. + * + * @exception IOException If an error occurs + */ + /*public void close() //throws IOException + { + synchronized (lock) + { + // Makes sure all intermediate data is released by the decoder. + if (decoder != null) + decoder.reset(); + if (in != null) + in.close(); + in = null; + isDone = true; + decoder = null; + } + }*/ + + /** + * This method returns the name of the encoding that is currently in use + * by this object. If the stream has been closed, this method is allowed + * to return null. + * + * @return The current encoding name + */ + /*public String getEncoding() + { + return in != null ? encoding : null; + }*/ + + /** + * This method checks to see if the stream is ready to be read. It + * will return true if is, or false if it is not. + * If the stream is not ready to be read, it could (although is not required + * to) block on the next read attempt. + * + * @return true if the stream is ready to be read, + * false otherwise + * + * @exception IOException If an error occurs + */ + /*public boolean ready() throws IOException + { + if (in == null) + throw new IOException("Reader has been closed"); + + return in.available() != 0; + }*/ + + /** + * This method reads up to length characters from the stream into + * the specified array starting at index offset into the + * array. + * + * @param buf The character array to recieve the data read + * @param offset The offset into the array to start storing characters + * @param length The requested number of characters to read. + * + * @return The actual number of characters read, or -1 if end of stream. + * + * @exception IOException If an error occurs + */ + /*public int read(char[] buf, int offset, int length) throws IOException + { + if (in == null) + throw new IOException("Reader has been closed"); + if (isDone) + return -1; + if(decoder != null) + { + int totalBytes = (int)((double) length * maxBytesPerChar); + if (byteBuffer != null) + totalBytes = Math.max(totalBytes, byteBuffer.remaining()); + byte[] bytes; + // Fetch cached bytes array if available and big enough. + synchronized(cacheLock) + { + bytes = bytesCache; + if (bytes == null || bytes.length < totalBytes) + bytes = new byte[totalBytes]; + else + bytesCache = null; + } + + int remaining = 0; + if(byteBuffer != null) + { + remaining = byteBuffer.remaining(); + byteBuffer.get(bytes, 0, remaining); + } + int read; + if(totalBytes - remaining > 0) + { + read = in.read(bytes, remaining, totalBytes - remaining); + if(read == -1){ + read = remaining; + isDone = true; + } else + read += remaining; + } else + read = remaining; + byteBuffer = ByteBuffer.wrap(bytes, 0, read); + CharBuffer cb = CharBuffer.wrap(buf, offset, length); + int startPos = cb.position(); + + if(hasSavedSurrogate){ + hasSavedSurrogate = false; + cb.put(savedSurrogate); + read++; + } + + CoderResult cr = decoder.decode(byteBuffer, cb, isDone); + decoder.reset(); + // 1 char remains which is the first half of a surrogate pair. + if(cr.isOverflow() && cb.hasRemaining()){ + CharBuffer overflowbuf = CharBuffer.allocate(2); + cr = decoder.decode(byteBuffer, overflowbuf, isDone); + overflowbuf.flip(); + if(overflowbuf.hasRemaining()) + { + cb.put(overflowbuf.get()); + savedSurrogate = overflowbuf.get(); + hasSavedSurrogate = true; + isDone = false; + } + } + + if(byteBuffer.hasRemaining()) { + byteBuffer.compact(); + byteBuffer.flip(); + isDone = false; + } else + byteBuffer = null; + + read = cb.position() - startPos; + + // Put cached bytes array back if we are finished and the cache + // is null or smaller than the used bytes array. + synchronized (cacheLock) + { + if (byteBuffer == null + && (bytesCache == null || bytesCache.length < bytes.length)) + bytesCache = bytes; + } + return (read <= 0) ? -1 : read; + } + else + { + byte[] bytes; + // Fetch cached bytes array if available and big enough. + synchronized (cacheLock) + { + bytes = bytesCache; + if (bytes == null || length < bytes.length) + bytes = new byte[length]; + else + bytesCache = null; + } + + int read = in.read(bytes); + for(int i=0;i + * This method will block until the char can be read. + * + * @return The char read or -1 if end of stream + * + * @exception IOException If an error occurs + */ + /*public int read() throws IOException + { + char[] buf = new char[1]; + int count = read(buf, 0, 1); + return count > 0 ? buf[0] : -1; + }*/ + + /** + * Skips the specified number of chars in the stream. It + * returns the actual number of chars skipped, which may be less than the + * requested amount. + * + * @param count The requested number of chars to skip + * + * @return The actual number of chars skipped. + * + * @exception IOException If an error occurs + */ + /*public long skip(long count) throws IOException + { + if (in == null) + throw new IOException("Reader has been closed"); + + return super.skip(count); + }*/ +} diff --git a/Robust/src/ClassLibrary/MGC/gnu/Level.java b/Robust/src/ClassLibrary/MGC/gnu/Level.java index 70cf86ed..9b150fe4 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/Level.java +++ b/Robust/src/ClassLibrary/MGC/gnu/Level.java @@ -139,7 +139,7 @@ public class Level //implements Serializable * * @see Logger#setLevel(java.util.logging.Level) */ - public static final Level ALL = new Level ("ALL", Integer.MIN_VALUE); + public static final Level ALL = new Level ("ALL", 0x80000000/*Integer.MIN_VALUE*/); private static final Level[] knownLevels = { diff --git a/Robust/src/ClassLibrary/MGC/gnu/LogManager.java b/Robust/src/ClassLibrary/MGC/gnu/LogManager.java index 3e4a61de..9365cd37 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/LogManager.java +++ b/Robust/src/ClassLibrary/MGC/gnu/LogManager.java @@ -319,7 +319,7 @@ public class LogManager * When adding "foo.bar", the logger "foo.bar.baz" should change * its parent to "foo.bar". */ - for (HashMapIterator iter = loggers./*.keySet().*/iterator(0); iter.hasNext();) + for (HashMapIterator iter = (HashMapIterator)loggers./*.keySet().*/iterator(0); iter.hasNext();) { Logger possChild = (Logger) /*((WeakReference) */loggers.get(iter.next());//) // .get(); @@ -369,7 +369,7 @@ public class LogManager return null; //for (String candName : loggers.keySet()) - HashMapIterator it_key = loggers.iterator(0); + HashMapIterator it_key = (HashMapIterator)loggers.iterator(0); while(it_key.hasNext()) { String candName = (String)it_key.next(); @@ -380,7 +380,7 @@ public class LogManager && childName.startsWith(candName) && childName.charAt(candNameLength) == '.') { - cand = loggers.get(candName);//.get(); + cand = (Logger)loggers.get(candName);//.get(); if ((cand == null) || (cand == child)) continue; @@ -615,7 +615,7 @@ public class LogManager * be determined that the Sun J2SE 1.4 reference * implementation uses null for the property name. */ - pcs.firePropertyChange(null, null, null); + /*pcs.firePropertyChange(null, null, null); }*/ /** diff --git a/Robust/src/ClassLibrary/MGC/gnu/Logger.java b/Robust/src/ClassLibrary/MGC/gnu/Logger.java index 26e949d3..d173b7d5 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/Logger.java +++ b/Robust/src/ClassLibrary/MGC/gnu/Logger.java @@ -1041,17 +1041,19 @@ public class Logger * {@link #setUseParentHandlers(boolean) setUseParentHandlers}, the log * record will be passed to the parent's handlers. */ - /*public Handler[] getHandlers() + public Handler[] getHandlers() { - synchronized (lock) + /*synchronized (lock) { /* * We cannot return our internal handlers array because we do not have * any guarantee that the caller would not change the array entries. */ /*return (Handler[]) handlerList.toArray(new Handler[handlerList.size()]); - } - }*/ + }*/ + System.println("Unimplemented Logger.getHandlers()"); + return new Handler[0]; + } /** * Returns whether or not this Logger forwards log records to handlers @@ -1086,7 +1088,7 @@ public class Logger * anonymous logger through the static factory method * {@link #getAnonymousLogger(java.lang.String) getAnonymousLogger}. */ - /*public void setUseParentHandlers(boolean useParentHandlers) + public void setUseParentHandlers(boolean useParentHandlers) { synchronized (lock) { @@ -1095,11 +1097,11 @@ public class Logger * having the permission to control the logging infrastructure. */ /*if (! anonymous) - LogManager.getLogManager().checkAccess(); + LogManager.getLogManager().checkAccess();*/ this.useParentHandlers = useParentHandlers; } - }*/ + } /** * Returns the parent of this logger. By default, the parent is assigned by diff --git a/Robust/src/ClassLibrary/MGC/gnu/PrintWriter.java b/Robust/src/ClassLibrary/MGC/gnu/PrintWriter.java index 6ea297f4..12007a59 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/PrintWriter.java +++ b/Robust/src/ClassLibrary/MGC/gnu/PrintWriter.java @@ -80,6 +80,8 @@ public class PrintWriter extends Writer * to */ protected Writer out; + + protected Object lock; /** * This method intializes a new PrintWriter object to write @@ -92,6 +94,7 @@ public class PrintWriter extends Writer { //super(wr.lock); this.out = wr; + this.lock = wr; } /** @@ -109,6 +112,7 @@ public class PrintWriter extends Writer //super(wr.lock); this.out = wr; this.autoflush = autoflush; + this.lock = wr; } /** @@ -380,7 +384,7 @@ public class PrintWriter extends Writer * This is the system dependent line separator */ private static final char[] line_separator - = {"\n"}; //System.getProperty("line.separator", "\n").toCharArray(); + = {'\n'}; //System.getProperty("line.separator", "\n").toCharArray(); /** * This method prints a line separator sequence to the stream. The value @@ -568,7 +572,7 @@ public class PrintWriter extends Writer { try { - out.write(ch); + out.write(new String((char)ch)); } catch (/*IO*/Exception ex) { @@ -588,7 +592,7 @@ public class PrintWriter extends Writer { try { - out.write(charArray, offset, count); + out.write(new String(charArray, offset, count)); } catch (/*IO*/Exception ex) { diff --git a/Robust/src/ClassLibrary/MGC/gnu/Properties.java b/Robust/src/ClassLibrary/MGC/gnu/Properties.java index 97737886..e71684aa 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/Properties.java +++ b/Robust/src/ClassLibrary/MGC/gnu/Properties.java @@ -522,7 +522,7 @@ label = Name:\\u0020 } public Set keySet() { - HashMapIterator it = this.proptbl.iterator(0); + HashMapIterator it = (HashMapIterator)this.proptbl.iterator(0); Set keys = new Vector(); while(it.hasNext()) { keys.add(it.next()); diff --git a/Robust/src/ClassLibrary/MGC/gnu/Short.java b/Robust/src/ClassLibrary/MGC/gnu/Short.java index 887fdb3b..d0cf2372 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/Short.java +++ b/Robust/src/ClassLibrary/MGC/gnu/Short.java @@ -170,7 +170,7 @@ public final class Short */ public static short parseShort(String s, int radix) { - int i = Integer.parseInt(s, radix, false); + int i = Integer.parseInt(s, radix); if ((short) i != i) throw new /*NumberFormat*/Exception("NumberFormatException"); return (short) i; @@ -258,7 +258,7 @@ public final class Short */ public static Short decode(String s) { - int i = Integer.parseInt(s, 10, true); + int i = Integer.parseInt(s, 10); if ((short) i != i) throw new /*NumberFormat*/Exception("NumberFormatException"); return valueOf((short) i); diff --git a/Robust/src/ClassLibrary/MGC/gnu/Stack.java b/Robust/src/ClassLibrary/MGC/gnu/Stack.java new file mode 100644 index 00000000..b9fb3949 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/gnu/Stack.java @@ -0,0 +1,160 @@ +/* Stack.java - Class that provides a Last In First Out (LIFO) + datatype, known more commonly as a Stack + Copyright (C) 1998, 1999, 2001, 2004, 2005 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.util; + +/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 + * "The Java Language Specification", ISBN 0-201-63451-1 + * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. + * Status: Believed complete and correct + +/** + * Stack provides a Last In First Out (LIFO) data type, commonly known + * as a Stack. Stack itself extends Vector and provides the additional + * methods for stack manipulation (push, pop, peek). You can also seek for + * the 1-based position of an element on the stack. + * + * @author Warren Levy (warrenl@cygnus.com) + * @author Eric Blake (ebb9@email.byu.edu) + * @see List + * @see AbstractList + * @see LinkedList + * @since 1.0 + * @status updated to 1.4 + */ +public class Stack/**/ extends Vector/**/ +{ + // We could use Vector methods internally for the following methods, + // but have used Vector fields directly for efficiency (i.e. this + // often reduces out duplicate bounds checking). + + /** + * Compatible with JDK 1.0+. + */ + private static final long serialVersionUID = 1224463164541339165L; + + /** + * This constructor creates a new Stack, initially empty + */ + public Stack() + { + } + + /** + * Pushes an Object onto the top of the stack. This method is effectively + * the same as addElement(item). + * + * @param item the Object to push onto the stack + * @return the Object pushed onto the stack + * @see Vector#addElement(Object) + */ + public Object push(Object item) + { + // When growing the Stack, use the Vector routines in case more + // memory is needed. + // Note: spec indicates that this method *always* returns obj passed in! + + addElement(item); + return item; + } + + /** + * Pops an item from the stack and returns it. The item popped is + * removed from the Stack. + * + * @return the Object popped from the stack + * @throws EmptyStackException if the stack is empty + */ + //@SuppressWarnings("unchecked") + public synchronized Object pop() + { + if (size == 0) + throw new /*EmptyStack*/Exception("EmptyStackException"); + + Object obj = array[--size]; + + // Set topmost element to null to assist the gc in cleanup. + array[size] = null; + return obj; + } + + /** + * Returns the top Object on the stack without removing it. + * + * @return the top Object on the stack + * @throws EmptyStackException if the stack is empty + */ + //@SuppressWarnings("unchecked") + public synchronized Object peek() + { + if (size == 0) + throw new /*EmptyStack*/Exception("EmptyStackException"); + + return array[size - 1]; + } + + /** + * Tests if the stack is empty. + * + * @return true if the stack contains no items, false otherwise + */ + public synchronized boolean empty() + { + return size == 0; + } + + /** + * Returns the position of an Object on the stack, with the top + * most Object being at position 1, and each Object deeper in the + * stack at depth + 1. + * + * @param o The object to search for + * @return The 1 based depth of the Object, or -1 if the Object + * is not on the stack + */ + public synchronized int search(Object o) + { + int i = size; + while (--i >= 0) + if (o.equals(array[i])) + return size - i; + return -1; + } +} diff --git a/Robust/src/ClassLibrary/MGC/gnu/TreeMap.java b/Robust/src/ClassLibrary/MGC/gnu/TreeMap.java index 2a0b3f62..54b23c02 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/TreeMap.java +++ b/Robust/src/ClassLibrary/MGC/gnu/TreeMap.java @@ -39,9 +39,6 @@ exception statement from your version. */ package java.util; -import java.util.TreeMap.Node; - - /** * This class provides a red-black tree implementation of the SortedMap * interface. Elements in the Map will be sorted by either a user-provided @@ -90,7 +87,7 @@ import java.util.TreeMap.Node; * @status updated to 1.6 */ public class TreeMap// extends AbstractMap - implements Map, SortedMap //NavigableMap, Cloneable, Serializable + implements Map//, SortedMap //NavigableMap, Cloneable, Serializable { // Implementation note: // A red-black tree is a binary search tree with the additional properties @@ -994,9 +991,9 @@ public class TreeMap// extends AbstractMap node.parent = child; } - public TreeMap subMap(Object fromKey, Object toKey) + public TreeSubMap subMap(Object fromKey, Object toKey) { - new SubMap(fromKey, toKey) + return new TreeSubMap(this, fromKey, toKey); } /** diff --git a/Robust/src/ClassLibrary/MGC/gnu/TreeMapIterator.java b/Robust/src/ClassLibrary/MGC/gnu/TreeMapIterator.java index dfb49964..19b15da6 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/TreeMapIterator.java +++ b/Robust/src/ClassLibrary/MGC/gnu/TreeMapIterator.java @@ -1,4 +1,4 @@ -public final class TreeMapIterator implements Iterator +public final class TreeMapIterator extends Iterator { /** * The type of this Iterator: {@link #KEYS}, {@link #VALUES}, @@ -6,7 +6,7 @@ public final class TreeMapIterator implements Iterator */ private final int type; /** The number of modifications to the backing Map that we know about. */ - private int knownMod = modCount; + private int knownMod; /** The last Entry returned by a next() call. */ private TreeNode last; /** The next entry that should be returned by next(). */ @@ -25,7 +25,7 @@ public final class TreeMapIterator implements Iterator */ TreeMapIterator(TreeMap map, int type) { - this(type, map, map.firstNode(), nil); + this(map, type, map.firstNode(), TreeMap.nil); } /** @@ -36,12 +36,13 @@ public final class TreeMapIterator implements Iterator * @param first where to start iteration, nil for empty iterator * @param max the cutoff for iteration, nil for all remaining nodes */ - TreeIterator(int type, TreeMap map, TreeNode first, TreeNode max) + TreeMapIterator(TreeMap map, int type, TreeNode first, TreeNode max) { this.map = map; this.type = type; this.next = first; this.max = max; + this.knownMod = this.map.modCount; } /** @@ -61,10 +62,10 @@ public final class TreeMapIterator implements Iterator */ public Object next() { - if (knownMod != modCount) + if (knownMod != this.map.modCount) throw new /*ConcurrentModification*/Exception("ConcurrentModificationException"); if (next == max) - throw new /*NoSuchElementException*/("NoSuchElementException"); + throw new /*NoSuchElement*/Exception("NoSuchElementException"); last = next; next = map.successor(last); @@ -85,7 +86,7 @@ public final class TreeMapIterator implements Iterator { if (last == null) throw new /*IllegalState*/Exception("IllegalStateException"); - if (knownMod != modCount) + if (knownMod != this.map.modCount) throw new /*ConcurrentModification*/Exception("ConcurrentModificationException"); map.removeNode(last); diff --git a/Robust/src/ClassLibrary/MGC/gnu/TreeNode.java b/Robust/src/ClassLibrary/MGC/gnu/TreeNode.java index cccd08ae..1c985f93 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/TreeNode.java +++ b/Robust/src/ClassLibrary/MGC/gnu/TreeNode.java @@ -1,35 +1,110 @@ -import TreeMap.Node; - /** - * Class to represent an entry in the tree. Holds a single key-value pair, - * plus pointers to parent and child nodes. + * Class to represent an entry in the tree. Holds a single key-value pair, + * plus pointers to parent and child nodes. + * + * @author Eric Blake (ebb9@email.byu.edu) + */ +public static final class TreeNode// extends AbstractMap.SimpleEntry +{ + // All fields package visible for use by nested classes. + /** The color of this node. */ + int color; + Object key; + Object value; + + /** The left child node. */ + TreeNode left = TreeMap.nil; + /** The right child node. */ + TreeNode right = TreeMap.nil; + /** The parent node. */ + TreeNode parent = TreeMap.nil; + + /** + * Simple constructor. + * @param key the key + * @param value the value + */ + TreeNode(Object key, Object value, int color) + { + key = key; + value = value; + this.color = color; + } + + public boolean equals(Object o) + { + if (! (o instanceof TreeNode)) + return false; + // Optimize for our own entries. + TreeNode e = (TreeNode) o; + return (key.equals(e.key) && value.equals(e.value)); + } + + /** + * Get the key corresponding to this entry. + * + * @return the key + */ + public Object getKey() + { + return key; + } + + /** + * Get the value corresponding to this entry. If you already called + * Iterator.remove(), the behavior undefined, but in this case it works. + * + * @return the value + */ + public Object getValue() + { + return value; + } + + /** + * Returns the hash code of the entry. This is defined as the exclusive-or + * of the hashcodes of the key and value (using 0 for null). In other + * words, this must be:
+ *

(getKey() == null ? 0 : getKey().hashCode())
+   *       ^ (getValue() == null ? 0 : getValue().hashCode())
+ * + * @return the hash code + */ + public int hashCode() + { + return (key.hashCode() ^ value.hashCode()); + } + + /** + * Replaces the value with the specified object. This writes through + * to the map, unless you have already called Iterator.remove(). It + * may be overridden to restrict a null value. + * + * @param newVal the new value to store + * @return the old value + * @throws NullPointerException if the map forbids null values. + * @throws UnsupportedOperationException if the map doesn't support + * put(). + * @throws ClassCastException if the value is of a type unsupported + * by the map. + * @throws IllegalArgumentException if something else about this + * value prevents it being stored in the map. + */ + public Object setValue(Object newVal) + { + Object r = value; + value = newVal; + return r; + } + + /** + * This provides a string representation of the entry. It is of the form + * "key=value", where string concatenation is used on key and value. * - * @author Eric Blake (ebb9@email.byu.edu) + * @return the string representation */ - public static final class TreeNode// extends AbstractMap.SimpleEntry + public String toString() { - // All fields package visible for use by nested classes. - /** The color of this node. */ - int color; - Object key; - Object value; - - /** The left child node. */ - TreeNode left = nil; - /** The right child node. */ - TreeNode right = nil; - /** The parent node. */ - TreeNode parent = nil; - - /** - * Simple constructor. - * @param key the key - * @param value the value - */ - TreeNode(Object key, Object value, int color) - { - key = key; - value = value; - this.color = color; - } - } \ No newline at end of file + return key + "=" + value; + } +} \ No newline at end of file diff --git a/Robust/src/ClassLibrary/MGC/gnu/TreeSubMap.java b/Robust/src/ClassLibrary/MGC/gnu/TreeSubMap.java index 1bdea0a1..4489e379 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/TreeSubMap.java +++ b/Robust/src/ClassLibrary/MGC/gnu/TreeSubMap.java @@ -25,7 +25,7 @@ public final class TreeSubMap TreeSubMap(TreeMap map, Object minKey, Object maxKey) { this.map = map; - if (minKey != nil && maxKey != nil && map.compare(minKey, maxKey) > 0) + if (minKey != TreeMap.nil && maxKey != TreeMap.nil && map.compare(minKey, maxKey) > 0) throw new /*IllegalArgument*/Exception("IllegalArgumentException: fromKey > toKey"); this.minKey = minKey; this.maxKey = maxKey; diff --git a/Robust/src/ClassLibrary/String.java b/Robust/src/ClassLibrary/String.java index b685780a..e6845035 100644 --- a/Robust/src/ClassLibrary/String.java +++ b/Robust/src/ClassLibrary/String.java @@ -256,6 +256,10 @@ public class String { return str; } + public void getChars(char dst[], int dstBegin) { + getChars(0, count, dst, dstBegin); + } + public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) { if((srcBegin < 0) || (srcEnd > count) || (srcBegin > srcEnd)) { // FIXME @@ -505,4 +509,9 @@ public class String { } return ((st > 0) || (len < count)) ? substring(st, len) : this; } + + public boolean matches(String regex) { + System.println("String.matches() is not fully supported"); + return this.equals(regex); + } } diff --git a/Robust/src/ClassLibrary/StringBuffer.java b/Robust/src/ClassLibrary/StringBuffer.java index 88e6c0cc..74d4a305 100644 --- a/Robust/src/ClassLibrary/StringBuffer.java +++ b/Robust/src/ClassLibrary/StringBuffer.java @@ -85,8 +85,58 @@ public class StringBuffer { } return this; } + + public int indexOf(String str) { + return indexOf(str, 0); + } + + public synchronized int indexOf(String str, int fromIndex) { + String vstr = new String(value, 0, count); + return vstr.indexOf(str, fromIndex); + } public String toString() { return new String(this); } + + public synchronized StringBuffer replace(int start, int end, String str) { + if (start < 0) { + // FIXME + System.printString("StringIndexOutOfBoundsException: "+start+"\n"); + } + if (start > count) { + // FIXME + System.printString("StringIndexOutOfBoundsException: start > length()\n"); + } + if (start > end) { + // FIXME + System.printString("StringIndexOutOfBoundsException: start > end\n"); + } + if (end > count) + end = count; + + if (end > count) + end = count; + int len = str.length(); + int newCount = count + len - (end - start); + if (newCount > value.length) + expandCapacity(newCount); + + System.arraycopy(value, end, value, start + len, count - end); + str.getChars(value, start); + count = newCount; + return this; + } + + void expandCapacity(int minimumCapacity) { + int newCapacity = (value.length + 1) * 2; + if (newCapacity < 0) { + newCapacity = 0x7fffffff/*Integer.MAX_VALUE*/; + } else if (minimumCapacity > newCapacity) { + newCapacity = minimumCapacity; + } + char newValue[] = new char[newCapacity]; + System.arraycopy(value, 0, newValue, 0, count); + value = newValue; + } } -- 2.34.1