Commit f18590c6 by Tom Tromey Committed by Tom Tromey

Externalizable.java, [...]: New versions from Classpath.

	* java/io/Externalizable.java, java/io/FilePermission.java,
	java/io/ObjectStreamConstants.java, java/io/Serializable.java,
	java/io/SerializablePermission.java, java/text/Format.java,
	java/util/AbstractMap.java, java/util/HashMap.java,
	java/util/LinkedHashMap.java, javax/naming/BinaryRefAddr.java: New
	versions from Classpath.

From-SVN: r58996
parent 99c49d11
2002-11-10 Tom Tromey <tromey@redhat.com>
* java/io/Externalizable.java, java/io/FilePermission.java,
java/io/ObjectStreamConstants.java, java/io/Serializable.java,
java/io/SerializablePermission.java, java/text/Format.java,
java/util/AbstractMap.java, java/util/HashMap.java,
java/util/LinkedHashMap.java, javax/naming/BinaryRefAddr.java: New
versions from Classpath.
2002-11-10 Anthony Green <green@redhat.com> 2002-11-10 Anthony Green <green@redhat.com>
* java/util/jar/Attributes.java (Name): Fix name check. * java/util/jar/Attributes.java (Name): Fix name check.
......
...@@ -62,6 +62,7 @@ package java.io; ...@@ -62,6 +62,7 @@ package java.io;
*/ */
public interface Externalizable extends Serializable public interface Externalizable extends Serializable
{ {
static final long serialVersionUID = -282491828744381764L;
/** /**
* This method restores an object's state by reading in the instance data * This method restores an object's state by reading in the instance data
......
...@@ -41,7 +41,10 @@ package java.io; ...@@ -41,7 +41,10 @@ package java.io;
import java.security.*; import java.security.*;
public final class FilePermission extends Permission implements Serializable { public final class FilePermission extends Permission implements Serializable
{
static final long serialVersionUID = 7930732926638008763L;
private static final String CURRENT_DIRECTORY = System.getProperty("user.dir"); private static final String CURRENT_DIRECTORY = System.getProperty("user.dir");
private boolean usingPerms = false; private boolean usingPerms = false;
private boolean readPerm = false; private boolean readPerm = false;
......
...@@ -70,7 +70,7 @@ public interface ObjectStreamConstants ...@@ -70,7 +70,7 @@ public interface ObjectStreamConstants
final static byte TC_PROXYCLASSDESC = (byte)125; //0x7D final static byte TC_PROXYCLASSDESC = (byte)125; //0x7D
final static byte TC_BASE = TC_NULL; final static byte TC_BASE = TC_NULL;
final static byte TC_MAX = TC_EXCEPTION; final static byte TC_MAX = TC_PROXYCLASSDESC;
final static int baseWireHandle = 0x7e0000; final static int baseWireHandle = 0x7e0000;
......
...@@ -51,4 +51,5 @@ package java.io; ...@@ -51,4 +51,5 @@ package java.io;
*/ */
public interface Serializable public interface Serializable
{ {
static final long serialVersionUID = 1196656838076753133L;
} // interface Serializable } // interface Serializable
...@@ -61,7 +61,8 @@ import java.security.BasicPermission; ...@@ -61,7 +61,8 @@ import java.security.BasicPermission;
*/ */
public final class SerializablePermission extends BasicPermission public final class SerializablePermission extends BasicPermission
{ {
static final long serialVersionUID = 8537212141160296410L;
/* /*
* Class Variables * Class Variables
*/ */
......
...@@ -59,6 +59,8 @@ import java.io.Serializable; ...@@ -59,6 +59,8 @@ import java.io.Serializable;
*/ */
public abstract class Format implements Serializable, Cloneable public abstract class Format implements Serializable, Cloneable
{ {
static final long serialVersionUID = -299282585814624189L;
/** /**
* This method initializes a new instance of <code>Format</code>. * This method initializes a new instance of <code>Format</code>.
* It performs no actions, but acts as a default constructor for * It performs no actions, but acts as a default constructor for
......
...@@ -466,6 +466,11 @@ public abstract class AbstractMap implements Map ...@@ -466,6 +466,11 @@ public abstract class AbstractMap implements Map
return AbstractMap.this.size(); return AbstractMap.this.size();
} }
public boolean contains(Object value)
{
return containsValue(value);
}
public Iterator iterator() public Iterator iterator()
{ {
return new Iterator() return new Iterator()
...@@ -527,8 +532,9 @@ public abstract class AbstractMap implements Map ...@@ -527,8 +532,9 @@ public abstract class AbstractMap implements Map
* @author Jon Zeppieri * @author Jon Zeppieri
* @author Eric Blake <ebb9@email.byu.edu> * @author Eric Blake <ebb9@email.byu.edu>
*/ */
// XXX - FIXME Use fully qualified implements as gcj 3.1 workaround.
static class BasicMapEntry implements Map.Entry static class BasicMapEntry implements Map.Entry
{ // XXX - FIXME Use fully qualified implements as gcj 3.1 workaround. {
/** /**
* The key. Package visible for direct manipulation. * The key. Package visible for direct manipulation.
*/ */
...@@ -553,16 +559,14 @@ public abstract class AbstractMap implements Map ...@@ -553,16 +559,14 @@ public abstract class AbstractMap implements Map
/** /**
* Compares the specified object with this entry. Returns true only if * Compares the specified object with this entry. Returns true only if
* the object is a mapping of identical key and value. In other words, * the object is a mapping of identical key and value. In other words,
* this must be: * this must be:<br>
* * <pre>(o instanceof Map.Entry)
<pre>(o instanceof Map.Entry) && * && (getKey() == null ? ((HashMap) o).getKey() == null
(getKey() == null ? ((HashMap) o).getKey() == null * : getKey().equals(((HashMap) o).getKey()))
: getKey().equals(((HashMap) o).getKey())) && * && (getValue() == null ? ((HashMap) o).getValue() == null
(getValue() == null ? ((HashMap) o).getValue() == null * : getValue().equals(((HashMap) o).getValue()))</pre>
: getValue().equals(((HashMap) o).getValue()))</pre>
* *
* @param o the object to compare * @param o the object to compare
*
* @return <code>true</code> if it is equal * @return <code>true</code> if it is equal
*/ */
public final boolean equals(Object o) public final boolean equals(Object o)
...@@ -605,10 +609,9 @@ public abstract class AbstractMap implements Map ...@@ -605,10 +609,9 @@ public abstract class AbstractMap implements Map
/** /**
* Returns the hash code of the entry. This is defined as the exclusive-or * 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 * of the hashcodes of the key and value (using 0 for null). In other
* words, this must be: * words, this must be:<br>
* * <pre>(getKey() == null ? 0 : getKey().hashCode())
<pre>(getKey() == null ? 0 : getKey().hashCode()) * ^ (getValue() == null ? 0 : getValue().hashCode())</pre>
^ (getValue() == null ? 0 : getValue().hashCode())</pre>
* *
* @return the hash code * @return the hash code
*/ */
......
...@@ -180,6 +180,15 @@ public class HashMap extends AbstractMap ...@@ -180,6 +180,15 @@ public class HashMap extends AbstractMap
} }
/** /**
* Called when this entry is accessed via {@link #put(Object, Object)}.
* This version does nothing, but in LinkedHashMap, it must do some
* bookkeeping for access-traversal mode.
*/
void access()
{
}
/**
* Called when this entry is removed from the map. This version simply * Called when this entry is removed from the map. This version simply
* returns the value, but in LinkedHashMap, it must also do bookkeeping. * returns the value, but in LinkedHashMap, it must also do bookkeeping.
* *
...@@ -338,8 +347,12 @@ public class HashMap extends AbstractMap ...@@ -338,8 +347,12 @@ public class HashMap extends AbstractMap
while (e != null) while (e != null)
{ {
if (equals(key, e.key)) if (equals(key, e.key))
// Must use this method for necessary bookkeeping in LinkedHashMap. {
return e.setValue(value); e.access(); // Must call this for bookkeeping in LinkedHashMap.
Object r = e.value;
e.value = value;
return r;
}
else else
e = e.next; e = e.next;
} }
...@@ -368,8 +381,8 @@ public class HashMap extends AbstractMap ...@@ -368,8 +381,8 @@ public class HashMap extends AbstractMap
public void putAll(Map m) public void putAll(Map m)
{ {
Iterator itr = m.entrySet().iterator(); Iterator itr = m.entrySet().iterator();
int msize = m.size();
for (int msize = m.size(); msize > 0; msize--) while (msize-- > 0)
{ {
Map.Entry e = (Map.Entry) itr.next(); Map.Entry e = (Map.Entry) itr.next();
// Optimize in case the Entry is one of our own. // Optimize in case the Entry is one of our own.
...@@ -379,9 +392,7 @@ public class HashMap extends AbstractMap ...@@ -379,9 +392,7 @@ public class HashMap extends AbstractMap
put(entry.key, entry.value); put(entry.key, entry.value);
} }
else else
{ put(e.getKey(), e.getValue());
put(e.getKey(), e.getValue());
}
} }
} }
...@@ -520,7 +531,7 @@ public class HashMap extends AbstractMap ...@@ -520,7 +531,7 @@ public class HashMap extends AbstractMap
public boolean remove(Object o) public boolean remove(Object o)
{ {
// Test against the size of the HashMap to determine if anything // Test against the size of the HashMap to determine if anything
// really got removed. This is neccessary because the return value // really got removed. This is necessary because the return value
// of HashMap.remove() is ambiguous in the null case. // of HashMap.remove() is ambiguous in the null case.
int oldsize = size; int oldsize = size;
HashMap.this.remove(o); HashMap.this.remove(o);
...@@ -634,7 +645,6 @@ public class HashMap extends AbstractMap ...@@ -634,7 +645,6 @@ public class HashMap extends AbstractMap
void addEntry(Object key, Object value, int idx, boolean callRemove) void addEntry(Object key, Object value, int idx, boolean callRemove)
{ {
HashEntry e = new HashEntry(key, value); HashEntry e = new HashEntry(key, value);
e.next = buckets[idx]; e.next = buckets[idx];
buckets[idx] = e; buckets[idx] = e;
} }
...@@ -648,17 +658,18 @@ public class HashMap extends AbstractMap ...@@ -648,17 +658,18 @@ public class HashMap extends AbstractMap
* @see #entrySet() * @see #entrySet()
*/ */
// Package visible, for use in nested classes. // Package visible, for use in nested classes.
HashEntry getEntry(Object o) final HashEntry getEntry(Object o)
{ {
if (!(o instanceof Map.Entry)) if (! (o instanceof Map.Entry))
return null; return null;
Map.Entry me = (Map.Entry) o; Map.Entry me = (Map.Entry) o;
int idx = hash(me.getKey()); Object key = me.getKey();
int idx = hash(key);
HashEntry e = buckets[idx]; HashEntry e = buckets[idx];
while (e != null) while (e != null)
{ {
if (e.equals(me)) if (equals(e.key, key))
return e; return equals(e.value, me.getValue()) ? e : null;
e = e.next; e = e.next;
} }
return null; return null;
...@@ -699,9 +710,8 @@ public class HashMap extends AbstractMap ...@@ -699,9 +710,8 @@ public class HashMap extends AbstractMap
{ {
Iterator itr = m.entrySet().iterator(); Iterator itr = m.entrySet().iterator();
int msize = m.size(); int msize = m.size();
this.size = msize; size = msize;
while (msize-- > 0)
for (; msize > 0; msize--)
{ {
Map.Entry e = (Map.Entry) itr.next(); Map.Entry e = (Map.Entry) itr.next();
Object key = e.getKey(); Object key = e.getKey();
...@@ -742,9 +752,7 @@ public class HashMap extends AbstractMap ...@@ -742,9 +752,7 @@ public class HashMap extends AbstractMap
dest.next = e; dest.next = e;
} }
else else
{ buckets[idx] = e;
buckets[idx] = e;
}
HashEntry next = e.next; HashEntry next = e.next;
e.next = null; e.next = null;
...@@ -797,13 +805,14 @@ public class HashMap extends AbstractMap ...@@ -797,13 +805,14 @@ public class HashMap extends AbstractMap
// Read the threshold and loadFactor fields. // Read the threshold and loadFactor fields.
s.defaultReadObject(); s.defaultReadObject();
// Read and use capacity. // Read and use capacity, followed by key/value pairs.
buckets = new HashEntry[s.readInt()]; buckets = new HashEntry[s.readInt()];
int len = s.readInt(); int len = s.readInt();
while (len-- > 0)
// Read and use key/value pairs. {
for ( ; len > 0; len--) Object key = s.readObject();
put(s.readObject(), s.readObject()); addEntry(key, s.readObject(), hash(key), false);
}
} }
/** /**
......
...@@ -51,7 +51,7 @@ import java.util.Arrays; ...@@ -51,7 +51,7 @@ import java.util.Arrays;
public class BinaryRefAddr extends RefAddr public class BinaryRefAddr extends RefAddr
{ {
static final long serialVersionUID = -3415254970957330361L; static final long serialVersionUID = -3415254970957330361L;
/** /**
* The possibly null content of this RefAddr. * The possibly null content of this RefAddr.
* Set by the constructor and returned by getContent. * Set by the constructor and returned by getContent.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment