+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;
return map.size();
}
public HashMapIterator iterator() {
- return map.iterator(0);
+ return (HashMapIterator)map.iterator(0);
}
}
}
public final native void notify();
+ public final native void notifyAll();
public final native void wait();
}
--- /dev/null
+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();
+
+}
* @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
--- /dev/null
+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();
+ }
+}
-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) {
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;
+ }
}
}
private native void nativeCreate();
+
+ public final native boolean isAlive();
}
+import java.util.NoSuchElementException;
+
public class Vector implements Set {
Object[] array;
int size;
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) {
array=sarray;
}
+ public synchronized Object firstElement() {
+ if (size == 0) {
+ throw new /*NoSuchElement*/Exception("NoSuchElement");
+ }
+ return array[0];
+ }
}
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);
+ }
}
--- /dev/null
+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 <code>next()</code>
+ * 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
private void set(BigInteger y)
{
if (y.words == null)
- set(y.ival);
+ set((long)y.ival);
else if (this != y)
{
realloc(y.ival);
if (count < avail)
{
- pos += count;
+ pos += (int)count;
return count;
}
--- /dev/null
+/* 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 <code>Object.clone()</code>. The default
+ * behaviour of <code>clone()</code> 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 <code>clone()</code> is called on an object which does not
+ * implement this interface, a <code>CloneNotSupportedException</code>
+ * will be thrown.
+ *
+ * <p>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 <code>equals</code>,
+ * <code>hashCode</code>, and <code>clone</code>, sometimes
+ * increasing the accessibility of clone to be public. The typical
+ * implementation of <code>clone</code> invokes <code>super.clone()</code>
+ * rather than a constructor, but this is not a requirement.
+ *
+ * <p>If an object that implement Cloneable should not be cloned,
+ * simply override the <code>clone</code> method to throw a
+ * <code>CloneNotSupportedException</code>.
+ *
+ * <p>All array types implement Cloneable, and have a public
+ * <code>clone</code> method that will never fail with a
+ * <code>CloneNotSupportedException</code>.
+ *
+ * @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.
+}
--- /dev/null
+/* 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 <code>ConsoleHandler</code> publishes log records to
+ * <code>System.err</code>.
+ *
+ * <p><strong>Configuration:</strong> Values of the subsequent
+ * <code>LogManager</code> properties are taken into consideration
+ * when a <code>ConsoleHandler</code> is initialized.
+ * If a property is not defined, or if it has an invalid
+ * value, a default is taken without an exception being thrown.
+ *
+ * <ul>
+ *
+ * <li><code>java.util.logging.ConsoleHandler.level</code> - specifies
+ * the initial severity level threshold. Default value:
+ * <code>Level.INFO</code>.</li>
+ *
+ * <li><code>java.util.logging.ConsoleHandler.filter</code> - specifies
+ * the name of a Filter class. Default value: No Filter.</li>
+ *
+ * <li><code>java.util.logging.ConsoleHandler.formatter</code> - specifies
+ * the name of a Formatter class. Default value:
+ * <code>java.util.logging.SimpleFormatter</code>.</li>
+ *
+ * <li><code>java.util.logging.ConsoleHandler.encoding</code> - specifies
+ * the name of the character encoding. Default value:
+ * the default platform encoding.</li>
+ *
+ * </ul>
+ *
+ * @author Sascha Brawer (brawer@acm.org)
+ */
+public class ConsoleHandler
+ extends StreamHandler
+{
+ /**
+ * Constructs a <code>StreamHandler</code> that publishes
+ * log records to <code>System.err</code>. The initial
+ * configuration is determined by the <code>LogManager</code>
+ * 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 <i>not</i> close <code>System.err</code>.
+ *
+ * <p>In case of an I/O failure, the <code>ErrorManager</code>
+ * of this <code>ConsoleHandler</code> 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 <code>LogRecord</code> to the console, provided the
+ * record passes all tests for being loggable.
+ *
+ * <p>Most applications do not need to call this method directly.
+ * Instead, they will use use a <code>Logger</code>, which will
+ * create LogRecords and distribute them to registered handlers.
+ *
+ * <p>In case of an I/O failure, the <code>ErrorManager</code>
+ * of this <code>SocketHandler</code> will be informed, but the caller
+ * of this method will not receive an exception.
+ *
+ * <p>The GNU implementation of <code>ConsoleHandler.publish</code>
+ * 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)");
+ }
+}
*
* @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("");
}
/**
* 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();
(this.groupingUsed && this.groupingSize != 0) &&
(gPos % groupingSize == 0))
dest.append(gSeparator);
- }
+ }*/
/**
* Append src to <code>dest</code>.
* Grouping is added if <code>groupingUsed</code> is set
* to <code>true</code>.
*/
- private void appendDigit(String src, StringBuffer dest,
+ /*private void appendDigit(String src, StringBuffer dest,
boolean groupingUsed)
{
int zero = symbols.getZeroDigit() - '0';
dest.append((char) (zero + ch));
}
- }
+ }*/
/**
* Calculate the exponent to use if eponential notation is used.
* <code>number</code> 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;
}
return exponent;
- }
+ }*/
/**
* Remove contiguos zeros from the end of the <code>src</code> string,
// 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 = "";
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;
this.decimalSeparatorAlwaysShown = false;
this.showDecimalSeparator = false;
this.useExponentialNotation = false;
- this.groupingUsed = false;
+ //this.groupingUsed = false;
this.groupingSeparatorInPattern = false;
this.useCurrencySeparator = false;
--- /dev/null
+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;
+ }
+}
--- /dev/null
+/* 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
+ * <code>File.list(FilenameFilter)</code> method and by the filename
+ * dialog in AWT.
+ * <p>
+ * 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 <code>File</code> instance for the directory being read
+ * @param name The name of the file to test
+ *
+ * @return <code>true</code> if the file should be included in the list,
+ * <code>false</code> otherwise.
+ */
+ boolean accept(File dir, String name);
+
+} // interface FilenameFilter
+
* of this <code>Handler</code> will be informed, but the caller
* of this method will not receive an exception.
*/
- //public abstract void flush();
+ public /*abstract */void flush(){}
/**
* the caller is not granted the permission to control
* the logging infrastructure.
*/
- //public abstract void close()
+ public /*abstract*/ void close(){}
// throws SecurityException;
--- /dev/null
+/* 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
+ * <code>file.encoding</code>. 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.
+ * <p>
+ * Here is a list of standard encoding names that may be available:
+ * <p>
+ * <ul>
+ * <li>8859_1 (ISO-8859-1/Latin-1)</li>
+ * <li>8859_2 (ISO-8859-2/Latin-2)</li>
+ * <li>8859_3 (ISO-8859-3/Latin-3)</li>
+ * <li>8859_4 (ISO-8859-4/Latin-4)</li>
+ * <li>8859_5 (ISO-8859-5/Latin-5)</li>
+ * <li>8859_6 (ISO-8859-6/Latin-6)</li>
+ * <li>8859_7 (ISO-8859-7/Latin-7)</li>
+ * <li>8859_8 (ISO-8859-8/Latin-8)</li>
+ * <li>8859_9 (ISO-8859-9/Latin-9)</li>
+ * <li>ASCII (7-bit ASCII)</li>
+ * <li>UTF8 (UCS Transformation Format-8)</li>
+ * <li>More later</li>
+ * </ul>
+ * <p>
+ * It is recommended that applications do not use
+ * <code>InputStreamReader</code>'s
+ * directly. Rather, for efficiency purposes, an object of this class
+ * should be wrapped by a <code>BufferedReader</code>.
+ * <p>
+ * 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 <code>InputStreamReader</code>
+ * to read from the specified stream using the default encoding.
+ *
+ * @param in The <code>InputStream</code> 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 <code>InputStreamReader</code>
+ * 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 <code>InputStream</code> 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
+ * <code>InputStream</code>.
+ *
+ * @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 <code>null</code>.
+ *
+ * @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 <code>true</code> if is, or <code>false</code> 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 <code>true</code> if the stream is ready to be read,
+ * <code>false</code> 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 <code>length</code> characters from the stream into
+ * the specified array starting at index <code>offset</code> 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<read;i++)
+ buf[offset+i] = (char)(bytes[i]&0xFF);
+
+ // Put back byte array into cache if appropriate.
+ synchronized (cacheLock)
+ {
+ if (bytesCache == null || bytesCache.length < bytes.length)
+ bytesCache = bytes;
+ }
+ return read;
+ }
+ }*/
+
+ /**
+ * Reads an char from the input stream and returns it
+ * as an int in the range of 0-65535. This method also will return -1 if
+ * the end of the stream has been reached.
+ * <p>
+ * 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);
+ }*/
+}
*
* @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 = {
* 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();
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();
&& childName.startsWith(candName)
&& childName.charAt(candNameLength) == '.')
{
- cand = loggers.get(candName);//.get();
+ cand = (Logger)loggers.get(candName);//.get();
if ((cand == null) || (cand == child))
continue;
* 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);
}*/
/**
* {@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
* 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)
{
* 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
* to
*/
protected Writer out;
+
+ protected Object lock;
/**
* This method intializes a new <code>PrintWriter</code> object to write
{
//super(wr.lock);
this.out = wr;
+ this.lock = wr;
}
/**
//super(wr.lock);
this.out = wr;
this.autoflush = autoflush;
+ this.lock = wr;
}
/**
* 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
{
try
{
- out.write(ch);
+ out.write(new String((char)ch));
}
catch (/*IO*/Exception ex)
{
{
try
{
- out.write(charArray, offset, count);
+ out.write(new String(charArray, offset, count));
}
catch (/*IO*/Exception ex)
{
}
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());
*/
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;
*/
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);
--- /dev/null
+/* 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/*<T>*/ extends Vector/*<T>*/
+{
+ // 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;
+ }
+}
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
* @status updated to 1.6
*/
public class TreeMap//<K, V> extends AbstractMap<K, V>
- implements Map, SortedMap //NavigableMap<K, V>, Cloneable, Serializable
+ implements Map//, SortedMap //NavigableMap<K, V>, Cloneable, Serializable
{
// Implementation note:
// A red-black tree is a binary search tree with the additional properties
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);
}
/**
-public final class TreeMapIterator implements Iterator
+public final class TreeMapIterator extends Iterator
{
/**
* The type of this Iterator: {@link #KEYS}, {@link #VALUES},
*/
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(). */
*/
TreeMapIterator(TreeMap map, int type)
{
- this(type, map, map.firstNode(), nil);
+ this(map, type, map.firstNode(), TreeMap.nil);
}
/**
* @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;
}
/**
*/
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);
{
if (last == null)
throw new /*IllegalState*/Exception("IllegalStateException");
- if (knownMod != modCount)
+ if (knownMod != this.map.modCount)
throw new /*ConcurrentModification*/Exception("ConcurrentModificationException");
map.removeNode(last);
-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//<K, V> extends AbstractMap.SimpleEntry<K, V>
+{
+ // 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:<br>
+ * <pre>(getKey() == null ? 0 : getKey().hashCode())
+ * ^ (getValue() == null ? 0 : getValue().hashCode())</pre>
+ *
+ * @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
+ * <code>put()</code>.
+ * @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//<K, V> extends AbstractMap.SimpleEntry<K, V>
+ 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
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;
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
}
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);
+ }
}
}
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;
+ }
}