harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [114/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/URLStreamHandler.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/URLStreamHandler.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/URLStreamHandler.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/URLStreamHandler.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,383 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.IOException;
+
+/**
+ * The abstract superclass of all classes that implement Protocol Handler.
+ */
+public abstract class URLStreamHandler {
+	/**
+	 * Establishes a connection to the resource specified by <code>URL</code>.
+	 * Since different protocols may have unique ways of connecting, it must be
+	 * overwritten by the subclass.
+	 * 
+	 * @return java.net.URLConnection
+	 * @param u
+	 *            java.net.URL
+	 * 
+	 * @exception IOException
+	 *                thrown if an IO error occurs during connection
+	 *                establishment
+	 */
+	protected abstract URLConnection openConnection(URL u) throws IOException;
+
+	/**
+	 * Parse the <code>string</code>str into <code>URL</code> using u's
+	 * context. URL strings generally have the following format:
+	 * <code><center>//www.company.com/java/file1.java#reference </center></code>
+	 * The string is parsed in HTTP format. If the protocol has a different URL
+	 * format this method must be overridden.
+	 * 
+	 * @param u
+	 *            java.net.URL The URL to receive parsed values.
+	 * @param str
+	 *            java.lang.String The string URL spec from which u is derived
+	 * @param start
+	 *            int The index in the string from which to begin parsing
+	 * @param end
+	 *            int The index to stop parsing
+	 * 
+	 * @see #toExternalForm
+	 * @see URL
+	 */
+	protected void parseURL(URL u, String str, int start, int end) {
+		if (end < start)
+			return;
+		String parseString = "";
+		if (start < end)
+			parseString = str.substring(start, end);
+		end -= start;
+		int fileIdx = 0;
+
+		// Default is to use info from context
+		String host = u.getHost();
+		int port = u.getPort();
+		String ref = u.getRef();
+		String file = u.getPath();
+		String query = u.getQuery();
+		String authority = u.getAuthority();
+		String userInfo = u.getUserInfo();
+
+		int refIdx = parseString.indexOf('#', 0);
+		if (parseString.startsWith("//")) {
+			int hostIdx = 2, portIdx = -1;
+			port = -1;
+			fileIdx = parseString.indexOf('/', hostIdx);
+			if (fileIdx == -1) {
+				fileIdx = end;
+				// Use default
+				file = "";
+			}
+			int hostEnd = fileIdx;
+			if (refIdx != -1 && refIdx < fileIdx)
+				hostEnd = refIdx;
+			int userIdx = parseString.lastIndexOf('@', hostEnd);
+			authority = parseString.substring(hostIdx, hostEnd);
+			if (userIdx > -1) {
+				userInfo = parseString.substring(hostIdx, userIdx);
+				hostIdx = userIdx + 1;
+			}
+
+			portIdx = parseString.indexOf(':', userIdx == -1 ? hostIdx
+					: userIdx);
+			int endOfIPv6Addr = parseString.indexOf(']');
+			// if there are square braces, ie. IPv6 address, use last ':'
+			if (endOfIPv6Addr != -1) {
+				try {
+					if (parseString.length() > endOfIPv6Addr + 1) {
+						char c = parseString.charAt(endOfIPv6Addr + 1);
+						if (c == ':') {
+							portIdx = endOfIPv6Addr + 1;
+						} else {
+							portIdx = -1;
+						}
+					} else {
+						portIdx = -1;
+					}
+				} catch (Exception e) {
+					System.out.println("***********");
+					e.printStackTrace();
+				}
+			}
+
+			if (portIdx == -1 || portIdx > fileIdx)
+				host = parseString.substring(hostIdx, hostEnd);
+			else {
+				host = parseString.substring(hostIdx, portIdx);
+				String portString = parseString.substring(portIdx + 1, hostEnd);
+				if (portString.length() == 0)
+					port = -1;
+				else
+					port = Integer.parseInt(portString);
+			}
+		}
+
+		if (refIdx > -1)
+			ref = parseString.substring(refIdx + 1, end);
+		int fileEnd = (refIdx == -1 ? end : refIdx);
+
+		int queryIdx = parseString.lastIndexOf('?', fileEnd);
+		if (queryIdx > -1) {
+			query = parseString.substring(queryIdx + 1, fileEnd);
+			// Don't inherit file if query is changed
+			if (queryIdx == 0 && file != null)
+				file = "/";
+			fileEnd = queryIdx;
+		} else
+		// Don't inherit query unless only the ref is changed
+		if (refIdx != 0)
+			query = null;
+
+		boolean canonicalize = false;
+		if (fileIdx > -1) {
+			if (fileIdx < end && parseString.charAt(fileIdx) == '/')
+				file = parseString.substring(fileIdx, fileEnd);
+			else if (fileEnd > fileIdx) {
+				if (file == null)
+					file = "";
+				else if (file.equals(""))
+					file = "/";
+				else if (file.startsWith("/"))
+					canonicalize = true;
+				int last = file.lastIndexOf('/') + 1;
+				if (last == 0)
+					file = parseString.substring(fileIdx, fileEnd);
+				else
+					file = file.substring(0, last)
+							+ parseString.substring(fileIdx, fileEnd);
+			}
+		}
+		if (file == null)
+			file = "";
+
+		if (host == null)
+			host = "";
+
+		if (canonicalize) {
+			// modify file if there's any relative referencing
+			int dirIndex;
+			while ((dirIndex = file.indexOf("/./")) >= 0)
+				file = file.substring(0, dirIndex + 1)
+						+ file.substring(dirIndex + 3);
+			if (file.endsWith("/."))
+				file = file.substring(0, file.length() - 1);
+			while ((dirIndex = file.indexOf("/../")) >= 0) {
+				if (dirIndex != 0) {
+					file = file.substring(0, file
+							.lastIndexOf('/', dirIndex - 1))
+							+ file.substring(dirIndex + 3);
+				} else
+					file = file.substring(dirIndex + 3);
+			}
+			if (file.endsWith("/..") && file.length() > 3)
+				file = file.substring(0, file.lastIndexOf('/',
+						file.length() - 4) + 1);
+		}
+
+		setURL(u, u.getProtocol(), host, port, authority, userInfo, file,
+				query, ref);
+	}
+
+	/**
+	 * Sets the fields of the <code>URL</code> with the supplied arguments
+	 * 
+	 * @param u
+	 *            java.net.URL The non-null URL to be set
+	 * @param protocol
+	 *            java.lang.String The protocol
+	 * @param host
+	 *            java.lang.String The host name
+	 * @param port
+	 *            int The port number
+	 * @param file
+	 *            java.lang.String The file component
+	 * @param ref
+	 *            java.lang.String The reference
+	 * 
+	 * @see java.util.Set
+	 * 
+	 * @deprecated use setURL(URL, String String, int, String, String, String,
+	 *             String, String)
+	 */
+	protected void setURL(URL u, String protocol, String host, int port,
+			String file, String ref) {
+		if (this != u.strmHandler)
+			throw new SecurityException();
+		u.set(protocol, host, port, file, ref);
+	}
+
+	/**
+	 * Sets the fields of the <code>URL</code> with the supplied arguments
+	 * 
+	 * @param u
+	 *            java.net.URL The non-null URL to be set
+	 * @param protocol
+	 *            java.lang.String The protocol
+	 * @param host
+	 *            java.lang.String The host name
+	 * @param port
+	 *            int The port number
+	 * @param authority
+	 *            java.lang.String The authority
+	 * @param userInfo
+	 *            java.lang.String The user info
+	 * @param file
+	 *            java.lang.String The file component
+	 * @param query
+	 *            java.lang.String The query
+	 * @param ref
+	 *            java.lang.String The reference
+	 * 
+	 * @see java.util.Set
+	 */
+	protected void setURL(URL u, String protocol, String host, int port,
+			String authority, String userInfo, String file, String query,
+			String ref) {
+		if (this != u.strmHandler)
+			throw new SecurityException();
+		u.set(protocol, host, port, authority, userInfo, file, query, ref);
+	}
+
+	/**
+	 * Answers the string equivalent of an URL using HTTP parsinf format.
+	 * 
+	 * @return java.lang.String the string representation of this URL
+	 * @param url
+	 *            java.net.URL the url object to be processed
+	 * 
+	 * @see #parseURL
+	 * @see URL#toExternalForm()
+	 */
+	protected String toExternalForm(URL url) {
+		StringBuffer answer = new StringBuffer(url.getProtocol().length()
+				+ url.getFile().length() + 16);
+		answer.append(url.getProtocol());
+		answer.append(':');
+		String authority = url.getAuthority();
+		if (authority != null && authority.length() > 0) {
+			answer.append("//");
+			answer.append(url.getAuthority());
+		}
+
+		String file = url.getFile();
+		String ref = url.getRef();
+		// file is never null
+		answer.append(file);
+		if (ref != null) {
+			answer.append('#');
+			answer.append(ref);
+		}
+		return answer.toString();
+	}
+
+	/**
+	 * Compares the two urls, and answers true if they represent the same URL.
+	 * Two URLs are equal if they have the same file, host, port, protocol,
+	 * query, and ref components.
+	 * 
+	 * @param url1
+	 *            URL the first URL to compare
+	 * @param url2
+	 *            URL the second URL to compare
+	 * @return <code>true</code> if the URLs are the same <code>false</code>
+	 *         if the URLs are different
+	 * 
+	 * @see #hashCode
+	 */
+	protected boolean equals(URL url1, URL url2) {
+		if (!sameFile(url1, url2))
+			return false;
+		String s1 = url1.getRef(), s2 = url2.getRef();
+		if (s1 != s2 && (s1 == null || !s1.equals(s2)))
+			return false;
+		s1 = url1.getQuery();
+		s2 = url2.getQuery();
+		return s1 == s2 || (s1 != null && s1.equals(s2));
+	}
+
+	/**
+	 * Return the default port.
+	 */
+	protected int getDefaultPort() {
+		return -1;
+	}
+
+	/**
+	 * Return the InetAddress for the host of the URL, or null.
+	 */
+	protected InetAddress getHostAddress(URL url) {
+		try {
+			String host = url.getHost();
+			if (host == null || host.length() == 0)
+				return null;
+			return InetAddress.getByName(host);
+		} catch (UnknownHostException e) {
+			return null;
+		}
+	}
+
+	/**
+	 * Answers a hash code for the URL object.
+	 * 
+	 * @return int the hashcode for hashtable indexing
+	 */
+	protected int hashCode(URL url) {
+		return toExternalForm(url).hashCode();
+	}
+
+	/**
+	 * Compares the two urls, and answers true if they have the same host
+	 * components.
+	 * 
+	 * @return <code>true</code> if the hosts of the URLs are the same
+	 *         <code>false</code> if the hosts are different
+	 */
+	protected boolean hostsEqual(URL url1, URL url2) {
+		String host1 = url1.getHost(), host2 = url2.getHost();
+		return host1 == host2
+				|| (host1 != null && host1.equalsIgnoreCase(host2));
+	}
+
+	/**
+	 * Answers true if the urls refer to the same file. Compares the protocol,
+	 * host, port and file components.
+	 * 
+	 * @return boolean true if the same resource, false otherwise
+	 */
+	protected boolean sameFile(URL url1, URL url2) {
+		String s1 = url1.getProtocol();
+		String s2 = url2.getProtocol();
+		if (s1 != s2 && (s1 == null || !s1.equals(s2)))
+			return false;
+
+		s1 = url1.getFile();
+		s2 = url2.getFile();
+		if (s1 != s2 && (s1 == null || !s1.equals(s2)))
+			return false;
+		if (!hostsEqual(url1, url2))
+			return false;
+		int p1 = url1.getPort();
+		if (p1 == -1)
+			p1 = getDefaultPort();
+		int p2 = url2.getPort();
+		if (p2 == -1)
+			p2 = getDefaultPort();
+		return p1 == p2;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/URLStreamHandlerFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/URLStreamHandlerFactory.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/URLStreamHandlerFactory.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/URLStreamHandlerFactory.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,33 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+/**
+ * Defines a factory which creates URL Stream (protocol) Handler It is used by
+ * the classes <code>URL</code>
+ */
+
+public interface URLStreamHandlerFactory {
+	/**
+	 * Creates a new <code>URL Stream Handler</code> instance.
+	 * 
+	 * @return java.net.URLStreamHandler
+	 * @param protocol
+	 *            java.lang.String
+	 */
+	URLStreamHandler createURLStreamHandler(String protocol);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/UnknownHostException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/UnknownHostException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/UnknownHostException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/UnknownHostException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,45 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.IOException;
+
+/**
+ * This UnknownHostException is thrown when an IP address resolution is attemped
+ * and no host or resolver may be found.
+ */
+public class UnknownHostException extends IOException {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public UnknownHostException() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public UnknownHostException(String detailMessage) {
+		super(detailMessage);
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/UnknownServiceException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/UnknownServiceException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/UnknownServiceException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/UnknownServiceException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,46 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.IOException;
+
+/**
+ * This UnknownServiceException is thrown when a particular service requested
+ * isn't support by the URL. Examples are attempts to read from an URL via an
+ * <code>InputStream</code> or write to an URL via an
+ * <code>OutputStream</code>
+ */
+public class UnknownServiceException extends IOException {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public UnknownServiceException() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public UnknownServiceException(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractCollection.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractCollection.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractCollection.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractCollection.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,287 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util;
+
+
+import java.lang.reflect.Array;
+
+/**
+ * AbstractCollection is an abstract implementation of the Collection interface.
+ * This implemetation does not support adding. A subclass must implement the
+ * abstract methods iterator() and size().
+ */
+
+public abstract class AbstractCollection implements Collection {
+
+	/**
+	 * Constructs a new instance of this AbstractCollection.
+	 */
+	protected AbstractCollection() {
+		// Empty
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Collection#add(java.lang.Object)
+	 */
+	public boolean add(Object object) {
+		throw new UnsupportedOperationException();
+	}
+
+	/**
+	 * Adds the objects in the specified Collection to this Collection.
+	 * 
+	 * @param collection
+	 *            the Collection of objects
+	 * @return true if this Collection is modified, false otherwise
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when adding to this Collection is not supported
+	 * @exception ClassCastException
+	 *                when the class of an object is inappropriate for this
+	 *                Collection
+	 * @exception IllegalArgumentException
+	 *                when an object cannot be added to this Collection
+	 */
+	public boolean addAll(Collection collection) {
+		boolean result = false;
+		Iterator it = collection.iterator();
+		while (it.hasNext())
+			if (add(it.next()))
+				result = true;
+		return result;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Collection#clear()
+	 */
+	public void clear() {
+		Iterator it = iterator();
+		while (it.hasNext()) {
+			it.next();
+			it.remove();
+		}
+	}
+
+	/**
+	 * Searches this Collection for the specified object.
+	 * 
+	 * @param object
+	 *            the object to search for
+	 * @return true if <code>object</code> is an element of this Collection,
+	 *         false otherwise
+	 */
+	public boolean contains(Object object) {
+		Iterator it = iterator();
+		if (object != null) {
+			while (it.hasNext())
+				if (object.equals(it.next()))
+					return true;
+		} else {
+			while (it.hasNext())
+				if (it.next() == null)
+					return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Searches this Collection for all objects in the specified Collection.
+	 * 
+	 * @param collection
+	 *            the Collection of objects
+	 * @return true if all objects in the specified Collection are elements of
+	 *         this Collection, false otherwise
+	 */
+	public boolean containsAll(Collection collection) {
+		Iterator it = collection.iterator();
+		while (it.hasNext())
+			if (!contains(it.next()))
+				return false;
+		return true;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Collection#isEmpty()
+	 */
+	public boolean isEmpty() {
+		return size() == 0;
+	}
+
+	/**
+	 * Answers an Iterator on the elements of this Collection. A subclass must
+	 * implement the abstract methods iterator() and size().
+	 * 
+	 * @return an Iterator on the elements of this Collection
+	 * 
+	 * @see Iterator
+	 */
+	public abstract Iterator iterator();
+
+	/**
+	 * Removes the first occurrence of the specified object from this
+	 * Collection.
+	 * 
+	 * @param object
+	 *            the object to remove
+	 * @return true if this Collection is modified, false otherwise
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this Collection is not supported
+	 */
+	public boolean remove(Object object) {
+		Iterator it = iterator();
+		if (object != null) {
+			while (it.hasNext()) {
+				if (object.equals(it.next())) {
+					it.remove();
+					return true;
+				}
+			}
+		} else {
+			while (it.hasNext()) {
+				if (it.next() == null) {
+					it.remove();
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+	/**
+	 * Removes all occurrences in this Collection of each object in the
+	 * specified Collection.
+	 * 
+	 * @param collection
+	 *            the Collection of objects to remove
+	 * @return true if this Collection is modified, false otherwise
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this Collection is not supported
+	 */
+	public boolean removeAll(Collection collection) {
+		boolean result = false;
+		Iterator it = iterator();
+		while (it.hasNext()) {
+			if (collection.contains(it.next())) {
+				it.remove();
+				result = true;
+			}
+		}
+		return result;
+	}
+
+	/**
+	 * Removes all objects from this Collection that are not contained in the
+	 * specified Collection.
+	 * 
+	 * @param collection
+	 *            the Collection of objects to retain
+	 * @return true if this Collection is modified, false otherwise
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this Collection is not supported
+	 */
+	public boolean retainAll(Collection collection) {
+		boolean result = false;
+		Iterator it = iterator();
+		while (it.hasNext()) {
+			if (!collection.contains(it.next())) {
+				it.remove();
+				result = true;
+			}
+		}
+		return result;
+	}
+
+	/**
+	 * Answers the number of elements in this Collection.
+	 * 
+	 * @return the number of elements in this Collection
+	 */
+	public abstract int size();
+
+	/**
+	 * Answers a new array containing all elements contained in this Collection.
+	 * 
+	 * @return an array of the elements from this Collection
+	 */
+	public Object[] toArray() {
+		int size = size(), index = 0;
+		Iterator it = iterator();
+		Object[] array = new Object[size];
+		while (index < size)
+			array[index++] = it.next();
+		return array;
+	}
+
+	/**
+	 * Answers an array containing all elements contained in this Collection. If
+	 * the specified array is large enough to hold the elements, the specified
+	 * array is used, otherwise an array of the same type is created. If the
+	 * specified array is used and is larger than this Collection, the array
+	 * element following the collection elements is set to null.
+	 * 
+	 * @param contents
+	 *            the array
+	 * @return an array of the elements from this Collection
+	 * 
+	 * @exception ArrayStoreException
+	 *                when the type of an element in this Collection cannot be
+	 *                stored in the type of the specified array
+	 */
+	public Object[] toArray(Object[] contents) {
+		int size = size(), index = 0;
+		Iterator it = iterator();
+		if (size > contents.length)
+			contents = (Object[]) Array.newInstance(contents.getClass()
+					.getComponentType(), size);
+		while (index < size)
+			contents[index++] = it.next();
+		if (index < contents.length)
+			contents[index] = null;
+		return contents;
+	}
+
+	/**
+	 * Answers the string representation of this Collection.
+	 * 
+	 * @return the string representation of this Collection
+	 */
+	public String toString() {
+		if (isEmpty())
+			return "[]"; //$NON-NLS-1$
+
+		StringBuffer buffer = new StringBuffer(size() * 16);
+		buffer.append('[');
+		Iterator it = iterator();
+		while (it.hasNext()) {
+			buffer.append(it.next());
+			buffer.append(", "); //$NON-NLS-1$
+		}
+		// Remove the trailing ", "
+		if (buffer.length() > 1)
+			buffer.setLength(buffer.length() - 2);
+		buffer.append(']');
+		return buffer.toString();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractList.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractList.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractList.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractList.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,658 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util;
+
+
+/**
+ * AbstractList is an abstract implementation of the List interface, optimized
+ * for a backing store which supports random access. This implementation does
+ * not support adding or replacing. A subclass must implement the abstract
+ * methods get() and size().
+ */
+public abstract class AbstractList extends AbstractCollection implements List {
+
+	protected transient int modCount = 0;
+
+	private class SimpleListIterator implements Iterator {
+		int pos = -1, expectedModCount;
+
+		int lastPosition = -1;
+
+		SimpleListIterator() {
+			expectedModCount = modCount;
+		}
+
+		public boolean hasNext() {
+			return pos + 1 < size();
+		}
+
+		public Object next() {
+			if (expectedModCount == modCount) {
+				try {
+					Object result = get(pos + 1);
+					lastPosition = ++pos;
+					return result;
+				} catch (IndexOutOfBoundsException e) {
+					throw new NoSuchElementException();
+				}
+			}
+			throw new ConcurrentModificationException();
+		}
+
+		public void remove() {
+			if (expectedModCount == modCount) {
+				try {
+					AbstractList.this.remove(lastPosition);
+				} catch (IndexOutOfBoundsException e) {
+					throw new IllegalStateException();
+				}
+				if (modCount != expectedModCount)
+					expectedModCount++;
+				if (pos == lastPosition)
+					pos--;
+				lastPosition = -1;
+			} else
+				throw new ConcurrentModificationException();
+		}
+	}
+
+	private final class FullListIterator extends SimpleListIterator implements
+			ListIterator {
+		FullListIterator(int start) {
+			if (0 <= start && start <= size())
+				pos = start - 1;
+			else
+				throw new IndexOutOfBoundsException();
+		}
+
+		public void add(Object object) {
+			if (expectedModCount == modCount) {
+				try {
+					AbstractList.this.add(pos + 1, object);
+				} catch (IndexOutOfBoundsException e) {
+					throw new NoSuchElementException();
+				}
+				pos++;
+				lastPosition = -1;
+				if (modCount != expectedModCount)
+					expectedModCount++;
+			} else
+				throw new ConcurrentModificationException();
+		}
+
+		public boolean hasPrevious() {
+			return pos >= 0;
+		}
+
+		public int nextIndex() {
+			return pos + 1;
+		}
+
+		public Object previous() {
+			if (expectedModCount == modCount) {
+				try {
+					Object result = get(pos);
+					lastPosition = pos;
+					pos--;
+					return result;
+				} catch (IndexOutOfBoundsException e) {
+					throw new NoSuchElementException();
+				}
+			}
+			throw new ConcurrentModificationException();
+		}
+
+		public int previousIndex() {
+			return pos;
+		}
+
+		public void set(Object object) {
+			if (expectedModCount == modCount) {
+				try {
+					AbstractList.this.set(lastPosition, object);
+				} catch (IndexOutOfBoundsException e) {
+					throw new IllegalStateException();
+				}
+			} else
+				throw new ConcurrentModificationException();
+		}
+	}
+
+	private static final class SubAbstractListRandomAccess extends
+			SubAbstractList implements RandomAccess {
+		SubAbstractListRandomAccess(AbstractList list, int start, int end) {
+			super(list, start, end);
+		}
+	}
+
+	private static class SubAbstractList extends AbstractList {
+		private AbstractList fullList;
+
+		private int offset, size;
+
+		private static final class SubAbstractListIterator implements
+				ListIterator {
+			private SubAbstractList subList;
+
+			private ListIterator iterator;
+
+			private int start, end;
+
+			SubAbstractListIterator(ListIterator it, SubAbstractList list,
+					int offset, int length) {
+				iterator = it;
+				subList = list;
+				start = offset;
+				end = start + length;
+			}
+
+			public void add(Object object) {
+				iterator.add(object);
+				subList.sizeChanged(true);
+				end++;
+			}
+
+			public boolean hasNext() {
+				return iterator.nextIndex() < end;
+			}
+
+			public boolean hasPrevious() {
+				return iterator.previousIndex() >= start;
+			}
+
+			public Object next() {
+				if (iterator.nextIndex() < end)
+					return iterator.next();
+				throw new NoSuchElementException();
+			}
+
+			public int nextIndex() {
+				return iterator.nextIndex() - start;
+			}
+
+			public Object previous() {
+				if (iterator.previousIndex() >= start)
+					return iterator.previous();
+				throw new NoSuchElementException();
+			}
+
+			public int previousIndex() {
+				int previous = iterator.previousIndex();
+				if (previous >= start)
+					return previous - start;
+				return -1;
+			}
+
+			public void remove() {
+				iterator.remove();
+				subList.sizeChanged(false);
+				end--;
+			}
+
+			public void set(Object object) {
+				iterator.set(object);
+			}
+		}
+
+		SubAbstractList(AbstractList list, int start, int end) {
+			fullList = list;
+			modCount = fullList.modCount;
+			offset = start;
+			size = end - start;
+		}
+
+		public void add(int location, Object object) {
+			if (modCount == fullList.modCount) {
+				if (0 <= location && location <= size) {
+					fullList.add(location + offset, object);
+					size++;
+					modCount = fullList.modCount;
+				} else
+					throw new IndexOutOfBoundsException();
+			} else
+				throw new ConcurrentModificationException();
+		}
+
+		public boolean addAll(int location, Collection collection) {
+			if (modCount == fullList.modCount) {
+				if (0 <= location && location <= size) {
+					boolean result = fullList.addAll(location + offset,
+							collection);
+					if (result) {
+						size += collection.size();
+						modCount = fullList.modCount;
+					}
+					return result;
+				}
+				throw new IndexOutOfBoundsException();
+			}
+			throw new ConcurrentModificationException();
+		}
+
+		public boolean addAll(Collection collection) {
+			if (modCount == fullList.modCount) {
+				boolean result = fullList.addAll(size, collection);
+				if (result) {
+					size += collection.size();
+					modCount = fullList.modCount;
+				}
+				return result;
+			}
+			throw new ConcurrentModificationException();
+		}
+
+		public Object get(int location) {
+			if (modCount == fullList.modCount) {
+				if (0 <= location && location <= size)
+					return fullList.get(location + offset);
+				throw new IndexOutOfBoundsException();
+			}
+			throw new ConcurrentModificationException();
+		}
+
+		public Iterator iterator() {
+			return listIterator(0);
+		}
+
+		public ListIterator listIterator(int location) {
+			if (modCount == fullList.modCount) {
+				if (0 <= location && location <= size)
+					return new SubAbstractListIterator(fullList
+							.listIterator(location + offset), this, offset,
+							size);
+				throw new IndexOutOfBoundsException();
+			}
+			throw new ConcurrentModificationException();
+		}
+
+		public Object remove(int location) {
+			if (modCount == fullList.modCount) {
+				if (0 <= location && location <= size) {
+					Object result = fullList.remove(location + offset);
+					size--;
+					modCount = fullList.modCount;
+					return result;
+				}
+				throw new IndexOutOfBoundsException();
+			}
+			throw new ConcurrentModificationException();
+		}
+
+		protected void removeRange(int start, int end) {
+			if (start != end) {
+				if (modCount == fullList.modCount) {
+					fullList.removeRange(start + offset, end + offset);
+					size -= end - start;
+					modCount = fullList.modCount;
+				} else
+					throw new ConcurrentModificationException();
+			}
+		}
+
+		public Object set(int location, Object object) {
+			if (modCount == fullList.modCount) {
+				if (0 <= location && location <= size)
+					return fullList.set(location + offset, object);
+				throw new IndexOutOfBoundsException();
+			}
+			throw new ConcurrentModificationException();
+		}
+
+		public int size() {
+			return size;
+		}
+
+		void sizeChanged(boolean increment) {
+			if (increment)
+				size++;
+			else
+				size--;
+			modCount = fullList.modCount;
+		}
+	}
+
+	/**
+	 * Constructs a new instance of this AbstractList.
+	 * 
+	 */
+	protected AbstractList() {
+	}
+
+	/**
+	 * Inserts the specified object into this List at the specified location.
+	 * The object is inserted before any previous element at the specified
+	 * location. If the location is equal to the size of this List, the object
+	 * is added at the end.
+	 * 
+	 * 
+	 * @param location
+	 *            the index at which to insert
+	 * @param object
+	 *            the object to add
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when adding to this List is not supported
+	 * @exception ClassCastException
+	 *                when the class of the object is inappropriate for this
+	 *                List
+	 * @exception IllegalArgumentException
+	 *                when the object cannot be added to this List
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public void add(int location, Object object) {
+		throw new UnsupportedOperationException();
+	}
+
+	/**
+	 * Adds the specified object at the end of this List.
+	 * 
+	 * 
+	 * @param object
+	 *            the object to add
+	 * @return true
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when adding to this List is not supported
+	 * @exception ClassCastException
+	 *                when the class of the object is inappropriate for this
+	 *                List
+	 * @exception IllegalArgumentException
+	 *                when the object cannot be added to this List
+	 */
+	public boolean add(Object object) {
+		add(size(), object);
+		return true;
+	}
+
+	/**
+	 * Inserts the objects in the specified Collection at the specified location
+	 * in this List. The objects are added in the order they are returned from
+	 * the Collection iterator.
+	 * 
+	 * 
+	 * @param location
+	 *            the index at which to insert
+	 * @param collection
+	 *            the Collection of objects
+	 * @return true if this List is modified, false otherwise
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when adding to this List is not supported
+	 * @exception ClassCastException
+	 *                when the class of an object is inappropriate for this List
+	 * @exception IllegalArgumentException
+	 *                when an object cannot be added to this List
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public boolean addAll(int location, Collection collection) {
+		Iterator it = collection.iterator();
+		while (it.hasNext())
+			add(location++, it.next());
+		return !collection.isEmpty();
+	}
+
+	/**
+	 * Removes all elements from this List, leaving it empty.
+	 * 
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this List is not supported
+	 * 
+	 * @see List#isEmpty
+	 * @see List#size
+	 */
+	public void clear() {
+		removeRange(0, size());
+	}
+
+	/**
+	 * Compares the specified object to this List and answer if they are equal.
+	 * The object must be a List which contains the same objects in the same
+	 * order.
+	 * 
+	 * 
+	 * @param object
+	 *            the object to compare with this object
+	 * @return true if the specified object is equal to this List, false
+	 *         otherwise
+	 * 
+	 * @see #hashCode
+	 */
+	public boolean equals(Object object) {
+		if (this == object)
+			return true;
+		if (object instanceof List) {
+			List list = (List) object;
+			if (list.size() != size())
+				return false;
+
+			Iterator it1 = iterator(), it2 = list.iterator();
+			while (it1.hasNext()) {
+				Object e1 = it1.next(), e2 = it2.next();
+				if (!(e1 == null ? e2 == null : e1.equals(e2)))
+					return false;
+			}
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Answers the element at the specified location in this List.
+	 * 
+	 * 
+	 * @param location
+	 *            the index of the element to return
+	 * @return the element at the specified index
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public abstract Object get(int location);
+
+	/**
+	 * Answers an integer hash code for the receiver. Objects which are equal
+	 * answer the same value for this method.
+	 * 
+	 * 
+	 * @return the receiver's hash
+	 * 
+	 * @see #equals
+	 */
+	public int hashCode() {
+		int result = 1;
+		Iterator it = iterator();
+		while (it.hasNext()) {
+			Object object = it.next();
+			result = (31 * result) + (object == null ? 0 : object.hashCode());
+		}
+		return result;
+	}
+
+	/**
+	 * Searches this List for the specified object and returns the index of the
+	 * first occurrence.
+	 * 
+	 * 
+	 * @param object
+	 *            the object to search for
+	 * @return the index of the first occurrence of the object
+	 */
+	public int indexOf(Object object) {
+		ListIterator it = listIterator();
+		if (object != null) {
+			while (it.hasNext())
+				if (object.equals(it.next()))
+					return it.previousIndex();
+		} else {
+			while (it.hasNext())
+				if (it.next() == null)
+					return it.previousIndex();
+		}
+		return -1;
+	}
+
+	/**
+	 * Answers an Iterator on the elements of this List. The elements are
+	 * iterated in the same order that they occur in the List.
+	 * 
+	 * 
+	 * @return an Iterator on the elements of this List
+	 * 
+	 * @see Iterator
+	 */
+	public Iterator iterator() {
+		return new SimpleListIterator();
+	}
+
+	/**
+	 * Searches this List for the specified object and returns the index of the
+	 * last occurrence.
+	 * 
+	 * 
+	 * @param object
+	 *            the object to search for
+	 * @return the index of the last occurrence of the object
+	 */
+	public int lastIndexOf(Object object) {
+		ListIterator it = listIterator(size());
+		if (object != null) {
+			while (it.hasPrevious())
+				if (object.equals(it.previous()))
+					return it.nextIndex();
+		} else {
+			while (it.hasPrevious())
+				if (it.previous() == null)
+					return it.nextIndex();
+		}
+		return -1;
+	}
+
+	/**
+	 * Answers a ListIterator on the elements of this List. The elements are
+	 * iterated in the same order that they occur in the List.
+	 * 
+	 * 
+	 * @return a ListIterator on the elements of this List
+	 * 
+	 * @see ListIterator
+	 */
+	public ListIterator listIterator() {
+		return listIterator(0);
+	}
+
+	/**
+	 * Answers a ListIterator on the elements of this List. The elements are
+	 * iterated in the same order that they occur in the List. The iteration
+	 * starts at the specified location.
+	 * 
+	 * 
+	 * @param location
+	 *            the index at which to start the iteration
+	 * @return a ListIterator on the elements of this List
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 * 
+	 * @see ListIterator
+	 */
+	public ListIterator listIterator(int location) {
+		return new FullListIterator(location);
+	}
+
+	/**
+	 * Removes the object at the specified location from this List.
+	 * 
+	 * 
+	 * @param location
+	 *            the index of the object to remove
+	 * @return the removed object
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this List is not supported
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public Object remove(int location) {
+		throw new UnsupportedOperationException();
+	}
+
+	/**
+	 * Removes the objects in the specified range from the start to the, but not
+	 * including, end index.
+	 * 
+	 * 
+	 * @param start
+	 *            the index at which to start removing
+	 * @param end
+	 *            the index one past the end of the range to remove
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this List is not supported
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>start < 0
+	 */
+	protected void removeRange(int start, int end) {
+		Iterator it = listIterator(start);
+		for (int i = start; i < end; i++) {
+			it.next();
+			it.remove();
+		}
+	}
+
+	/**
+	 * Replaces the element at the specified location in this List with the
+	 * specified object.
+	 * 
+	 * 
+	 * @param location
+	 *            the index at which to put the specified object
+	 * @param object
+	 *            the object to add
+	 * @return the previous element at the index
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when replacing elements in this List is not supported
+	 * @exception ClassCastException
+	 *                when the class of an object is inappropriate for this List
+	 * @exception IllegalArgumentException
+	 *                when an object cannot be added to this List
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public Object set(int location, Object object) {
+		throw new UnsupportedOperationException();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.List#subList(int, int)
+	 */
+	public List subList(int start, int end) {
+		if (0 <= start && end <= size()) {
+			if (start <= end) {
+				if (this instanceof RandomAccess)
+					return new SubAbstractListRandomAccess(this, start, end);
+				return new SubAbstractList(this, start, end);
+			}
+			throw new IllegalArgumentException();
+		}
+		throw new IndexOutOfBoundsException();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractMap.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractMap.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractMap.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractMap.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,394 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util;
+
+
+/**
+ * AbstractMap is an abstract implementation of the Map iterface. This
+ * implemenation does not support adding. A subclass must implement the abstract
+ * method entrySet().
+ */
+public abstract class AbstractMap implements Map {
+
+	// Lazily initialized key set.
+	Set keySet = null;
+
+	Collection valuesCollection = null;
+
+	/**
+	 * Constructs a new instance of this AbstractMap.
+	 */
+	protected AbstractMap() {
+		/*empty */
+	}
+
+	/**
+	 * Removes all elements from this Map, leaving it empty.
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this Map is not supported
+	 * 
+	 * @see #isEmpty
+	 * @see #size
+	 */
+	public void clear() {
+		entrySet().clear();
+	}
+
+	/**
+	 * Searches this Map for the specified key.
+	 * 
+	 * @param key
+	 *            the object to search for
+	 * @return true if <code>key</code> is a key of this Map, false otherwise
+	 */
+	public boolean containsKey(Object key) {
+		Iterator it = entrySet().iterator();
+		if (key != null) {
+			while (it.hasNext())
+				if (key.equals(((Map.Entry) it.next()).getKey()))
+					return true;
+		} else {
+			while (it.hasNext())
+				if (((Map.Entry) it.next()).getKey() == null)
+					return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Searches this Map for the specified value.
+	 * 
+	 * @param value
+	 *            the object to search for
+	 * @return true if <code>value</code> is a value of this Map, false
+	 *         otherwise
+	 */
+	public boolean containsValue(Object value) {
+		Iterator it = entrySet().iterator();
+		if (value != null) {
+			while (it.hasNext())
+				if (value.equals(((Map.Entry) it.next()).getValue()))
+					return true;
+		} else {
+			while (it.hasNext())
+				if (((Map.Entry) it.next()).getValue() == null)
+					return true;
+		}
+		return false;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Map#entrySet()
+	 */
+	abstract public Set entrySet();
+
+	/**
+	 * Compares the specified object to this Map and answer if they are equal.
+	 * The object must be an instance of Map and contain the same key/value
+	 * pairs.
+	 * 
+	 * @param object
+	 *            the object to compare with this object
+	 * @return true if the specified object is equal to this Map, false
+	 *         otherwise
+	 * 
+	 * @see #hashCode
+	 */
+	public boolean equals(Object object) {
+		if (this == object)
+			return true;
+		if (object instanceof Map) {
+			Map map = (Map) object;
+			if (size() != map.size())
+				return false;
+
+			Set objectSet = map.entrySet();
+			Iterator it = entrySet().iterator();
+			while (it.hasNext())
+				if (!objectSet.contains(it.next()))
+					return false;
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Answers the value of the mapping with the specified key.
+	 * 
+	 * @param key
+	 *            the key
+	 * @return the value of the mapping with the specified key
+	 */
+	public Object get(Object key) {
+		Iterator it = entrySet().iterator();
+		if (key != null) {
+			while (it.hasNext()) {
+				Map.Entry entry = (Map.Entry) it.next();
+				if (key.equals(entry.getKey()))
+					return entry.getValue();
+			}
+		} else {
+			while (it.hasNext()) {
+				Map.Entry entry = (Map.Entry) it.next();
+				if (entry.getKey() == null)
+					return entry.getValue();
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Answers an integer hash code for the receiver. Objects which are equal
+	 * answer the same value for this method.
+	 * 
+	 * @return the receiver's hash
+	 * 
+	 * @see #equals
+	 */
+	public int hashCode() {
+		int result = 0;
+		Iterator it = entrySet().iterator();
+		while (it.hasNext())
+			result += it.next().hashCode();
+		return result;
+	}
+
+	/**
+	 * Answers if this Map has no elements, a size of zero.
+	 * 
+	 * @return true if this Map has no elements, false otherwise
+	 * 
+	 * @see #size
+	 */
+	public boolean isEmpty() {
+		return size() == 0;
+	}
+
+	/**
+	 * Answers a Set of the keys contained in this Map. The set is backed by
+	 * this Map so changes to one are relected by the other. The set does not
+	 * support adding.
+	 * 
+	 * @return a Set of the keys
+	 */
+	public Set keySet() {
+		if (keySet == null) {
+			keySet = new AbstractSet() {
+				public boolean contains(Object object) {
+					return containsKey(object);
+				}
+
+				public int size() {
+					return AbstractMap.this.size();
+				}
+
+				public Iterator iterator() {
+					return new Iterator() {
+						Iterator setIterator = entrySet().iterator();
+
+						public boolean hasNext() {
+							return setIterator.hasNext();
+						}
+
+						public Object next() {
+							return ((Map.Entry) setIterator.next()).getKey();
+						}
+
+						public void remove() {
+							setIterator.remove();
+						}
+					};
+				}
+			};
+		}
+		return keySet;
+	}
+
+	/**
+	 * Maps the specified key to the specified value.
+	 * 
+	 * @param key
+	 *            the key
+	 * @param value
+	 *            the value
+	 * @return the value of any previous mapping with the specified key or null
+	 *         if there was no mapping
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when adding to this Map is not supported
+	 * @exception ClassCastException
+	 *                when the class of the key or value is inappropriate for
+	 *                this Map
+	 * @exception IllegalArgumentException
+	 *                when the key or value cannot be added to this Map
+	 * @exception NullPointerException
+	 *                when the key or value is null and this Map does not
+	 *                support null keys or values
+	 */
+	public Object put(Object key, Object value) {
+		throw new UnsupportedOperationException();
+	}
+
+	/**
+	 * Copies every mapping in the specified Map to this Map.
+	 * 
+	 * @param map
+	 *            the Map to copy mappings from
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when adding to this Map is not supported
+	 * @exception ClassCastException
+	 *                when the class of a key or value is inappropriate for this
+	 *                Map
+	 * @exception IllegalArgumentException
+	 *                when a key or value cannot be added to this Map
+	 * @exception NullPointerException
+	 *                when a key or value is null and this Map does not support
+	 *                null keys or values
+	 */
+	public void putAll(Map map) {
+		Iterator it = map.entrySet().iterator();
+		while (it.hasNext()) {
+			Map.Entry entry = (Map.Entry) it.next();
+			put(entry.getKey(), entry.getValue());
+		}
+	}
+
+	/**
+	 * Removes a mapping with the specified key from this Map.
+	 * 
+	 * @param key
+	 *            the key of the mapping to remove
+	 * @return the value of the removed mapping or null if key is not a key in
+	 *         this Map
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this Map is not supported
+	 */
+	public Object remove(Object key) {
+		Iterator it = entrySet().iterator();
+		if (key != null) {
+			while (it.hasNext()) {
+				Map.Entry entry = (Map.Entry) it.next();
+				if (key.equals(entry.getKey())) {
+					it.remove();
+					return entry.getValue();
+				}
+			}
+		} else {
+			while (it.hasNext()) {
+				Map.Entry entry = (Map.Entry) it.next();
+				if (entry.getKey() == null) {
+					it.remove();
+					return entry.getValue();
+				}
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Answers the number of elements in this Map.
+	 * 
+	 * @return the number of elements in this Map
+	 */
+	public int size() {
+		return entrySet().size();
+	}
+
+	/**
+	 * Answers the string representation of this Map.
+	 * 
+	 * @return the string representation of this Map
+	 */
+	public String toString() {
+		if (isEmpty())
+			return "{}"; //$NON-NLS-1$
+
+		StringBuffer buffer = new StringBuffer(size() * 28);
+		buffer.append('{');
+		Iterator it = entrySet().iterator();
+		while (it.hasNext()) {
+			Map.Entry entry = (Map.Entry) it.next();
+			buffer.append(entry.getKey());
+			buffer.append('=');
+			buffer.append(entry.getValue());
+			buffer.append(", "); //$NON-NLS-1$
+		}
+		// Remove the trailing ", "
+		if (buffer.length() > 1)
+			buffer.setLength(buffer.length() - 2);
+		buffer.append('}');
+		return buffer.toString();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Map#values()
+	 */
+	public Collection values() {
+		if (valuesCollection == null) {
+			valuesCollection = new AbstractCollection() {
+				public int size() {
+					return AbstractMap.this.size();
+				}
+
+				public boolean contains(Object object) {
+					return containsValue(object);
+				}
+
+				public Iterator iterator() {
+					return new Iterator() {
+						Iterator setIterator = entrySet().iterator();
+
+						public boolean hasNext() {
+							return setIterator.hasNext();
+						}
+
+						public Object next() {
+							return ((Map.Entry) setIterator.next()).getValue();
+						}
+
+						public void remove() {
+							setIterator.remove();
+						}
+					};
+				}
+			};
+		}
+		return valuesCollection;
+	}
+
+	/**
+	 * Answers a new instance of the same class as the receiver, whose slots
+	 * have been filled in with the values in the slots of the receiver.
+	 * 
+	 * @return Object a shallow copy of this object.
+	 * @exception CloneNotSupportedException
+	 *                if the receiver's class does not implement the interface
+	 *                Cloneable.
+	 */
+	protected Object clone() throws CloneNotSupportedException {
+		AbstractMap result = (AbstractMap) super.clone();
+		result.keySet = null;
+		result.valuesCollection = null;
+		return result;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractSequentialList.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractSequentialList.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractSequentialList.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractSequentialList.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,186 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util;
+
+
+/**
+ * AbstractSequentialList is an abstract implementation of the List interface.
+ * This implementation does not support adding. A subclass must implement the
+ * abstract method listIterator().
+ */
+public abstract class AbstractSequentialList extends AbstractList {
+
+	/**
+	 * Constructs a new instance of this AbstractSequentialList.
+	 */
+	protected AbstractSequentialList() {
+		/*empty*/
+	}
+
+	/**
+	 * Inserts the specified object into this List at the specified location.
+	 * The object is inserted before any previous element at the specified
+	 * location. If the location is equal to the size of this List, the object
+	 * is added at the end.
+	 * 
+	 * @param location
+	 *            the index at which to insert
+	 * @param object
+	 *            the object to add
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when adding to this List is not supported
+	 * @exception ClassCastException
+	 *                when the class of the object is inappropriate for this
+	 *                List
+	 * @exception IllegalArgumentException
+	 *                when the object cannot be added to this List
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 * @exception NullPointerException
+	 *                when the object is null and this List does not support
+	 *                null elements
+	 */
+	public void add(int location, Object object) {
+		listIterator(location).add(object);
+	}
+
+	/**
+	 * Inserts the objects in the specified Collection at the specified location
+	 * in this List. The objects are added in the order they are returned from
+	 * the Collection iterator.
+	 * 
+	 * @param location
+	 *            the index at which to insert
+	 * @param collection
+	 *            the Collection of objects
+	 * @return true if this List is modified, false otherwise
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when adding to this List is not supported
+	 * @exception ClassCastException
+	 *                when the class of an object is inappropriate for this List
+	 * @exception IllegalArgumentException
+	 *                when an object cannot be added to this List
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public boolean addAll(int location, Collection collection) {
+		ListIterator it = listIterator(location);
+		Iterator colIt = collection.iterator();
+		int next = it.nextIndex();
+		while (colIt.hasNext()) {
+			it.add(colIt.next());
+			it.previous();
+		}
+		return next != it.nextIndex();
+	}
+
+	/**
+	 * Answers the element at the specified location in this List.
+	 * 
+	 * @param location
+	 *            the index of the element to return
+	 * @return the element at the specified location
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public Object get(int location) {
+		try {
+			return listIterator(location).next();
+		} catch (NoSuchElementException e) {
+			throw new IndexOutOfBoundsException();
+		}
+	}
+
+	/**
+	 * Answers an Iterator on the elements of this List. The elements are
+	 * iterated in the same order that they occur in the List.
+	 * 
+	 * @return an Iterator on the elements of this List
+	 * 
+	 * @see Iterator
+	 */
+	public Iterator iterator() {
+		return listIterator(0);
+	}
+
+	/**
+	 * Answers a ListIterator on the elements of this List. The elements are
+	 * iterated in the same order that they occur in the List. The iteration
+	 * starts at the specified location.
+	 * 
+	 * @param location
+	 *            the index at which to start the iteration
+	 * @return a ListIterator on the elements of this List
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 * 
+	 * @see ListIterator
+	 */
+	public abstract ListIterator listIterator(int location);
+
+	/**
+	 * Removes the object at the specified location from this List.
+	 * 
+	 * @param location
+	 *            the index of the object to remove
+	 * @return the removed object
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this List is not supported
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public Object remove(int location) {
+		try {
+			ListIterator it = listIterator(location);
+			Object result = it.next();
+			it.remove();
+			return result;
+		} catch (NoSuchElementException e) {
+			throw new IndexOutOfBoundsException();
+		}
+	}
+
+	/**
+	 * Replaces the element at the specified location in this List with the
+	 * specified object.
+	 * 
+	 * @param location
+	 *            the index at which to put the specified object
+	 * @param object
+	 *            the object to add
+	 * @return the previous element at the index
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when replacing elements in this List is not supported
+	 * @exception ClassCastException
+	 *                when the class of an object is inappropriate for this List
+	 * @exception IllegalArgumentException
+	 *                when an object cannot be added to this List
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public Object set(int location, Object object) {
+		ListIterator it = listIterator(location);
+		Object result = it.next();
+		it.set(object);
+		return result;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractSet.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractSet.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/AbstractSet.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,100 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util;
+
+
+/**
+ * AbstractSet is an abstract implementation of the Set iterface. This
+ * implemenation does not support adding. A subclass must implement the abstract
+ * methods iterator() and size().
+ */
+public abstract class AbstractSet extends AbstractCollection implements Set {
+	
+	/**
+	 * Constructs a new instance of this AbstractSet.
+	 */
+	protected AbstractSet() {
+		/*empty*/
+	}
+
+	/**
+	 * Compares the specified object to this Set and answer if they are equal.
+	 * The object must be an instance of Set and contain the same objects.
+	 * 
+	 * @param object
+	 *            the object to compare with this object
+	 * @return true if the specified object is equal to this Set, false
+	 *         otherwise
+	 * 
+	 * @see #hashCode
+	 */
+	public boolean equals(Object object) {
+		if (this == object)
+			return true;
+		if (object instanceof Set) {
+			Set s = (Set) object;
+			return size() == s.size() && containsAll(s);
+		}
+		return false;
+	}
+
+	/**
+	 * Answers an integer hash code for the receiver. Objects which are equal
+	 * answer the same value for this method.
+	 * 
+	 * @return the receiver's hash
+	 * 
+	 * @see #equals
+	 */
+	public int hashCode() {
+		int result = 0;
+		Iterator it = iterator();
+		while (it.hasNext()) {
+			Object next = it.next();
+			result += next == null ? 0 : next.hashCode();
+		}
+		return result;
+	}
+
+	/**
+	 * Removes all occurrences in this Collection of each object in the
+	 * specified Collection.
+	 * 
+	 * @param collection
+	 *            the Collection of objects to remove
+	 * @return true if this Collection is modified, false otherwise
+	 * 
+	 * @exception UnsupportedOperationException
+	 *                when removing from this Collection is not supported
+	 */
+	public boolean removeAll(Collection collection) {
+		boolean result = false;
+		if (size() <= collection.size()) {
+			Iterator it = iterator();
+			while (it.hasNext()) {
+				if (collection.contains(it.next())) {
+					it.remove();
+					result = true;
+				}
+			}
+		} else {
+			Iterator it = collection.iterator();
+			while (it.hasNext())
+				result = remove(it.next()) || result;
+		}
+		return result;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/ArrayList.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/ArrayList.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/ArrayList.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/ArrayList.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,615 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util;
+
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+import java.lang.reflect.Array;
+
+/**
+ * ArrayList is an implemenation of List, backed by an array. All optional
+ * operations are supported, adding, removing, and replacing. The elements can
+ * be any objects.
+ */
+public class ArrayList extends AbstractList implements List, Cloneable,
+		Serializable, RandomAccess {
+
+	static final long serialVersionUID = 8683452581122892189L;
+
+	transient private int firstIndex, lastIndex;
+
+	transient private Object[] array;
+
+	/**
+	 * Contructs a new instance of ArrayList with zero capacity.
+	 */
+	public ArrayList() {
+		this(0);
+	}
+
+	/**
+	 * Constructs a new instance of ArrayList with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            the initial capacity of this ArrayList
+	 */
+	public ArrayList(int capacity) {
+		firstIndex = lastIndex = 0;
+		try {
+			array = new Object[capacity];
+		} catch (NegativeArraySizeException e) {
+			throw new IllegalArgumentException();
+		}
+	}
+
+	/**
+	 * Constructs a new instance of ArrayList containing the elements in the
+	 * specified collection. The ArrayList will have an initial cacacity which
+	 * is 110% of the size of the collection. The order of the elements in this
+	 * ArrayList is the order they are returned by the collection iterator.
+	 * 
+	 * @param collection
+	 *            the collection of elements to add
+	 */
+	public ArrayList(Collection collection) {
+		int size = collection.size();
+		firstIndex = lastIndex = 0;
+		array = new Object[size + (size / 10)];
+		addAll(collection);
+	}
+
+	/**
+	 * Inserts the specified object into this ArrayList at the specified
+	 * location. The object is inserted before any previous element at the
+	 * specified location. If the location is equal to the size of this
+	 * ArrayList, the object is added at the end.
+	 * 
+	 * @param location
+	 *            the index at which to insert
+	 * @param object
+	 *            the object to add
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public void add(int location, Object object) {
+		int size = size();
+		if (0 < location && location < size) {
+			if (firstIndex == 0 && lastIndex == array.length) {
+				growForInsert(location, 1);
+			} else if ((location < size / 2 && firstIndex > 0)
+					|| lastIndex == array.length) {
+				System.arraycopy(array, firstIndex, array, --firstIndex,
+						location);
+			} else {
+				int index = location + firstIndex;
+				System.arraycopy(array, index, array, index + 1, size
+						- location);
+				lastIndex++;
+			}
+			array[location + firstIndex] = object;
+		} else if (location == 0) {
+			if (firstIndex == 0)
+				growAtFront(1);
+			array[--firstIndex] = object;
+		} else if (location == size) {
+			if (lastIndex == array.length)
+				growAtEnd(1);
+			array[lastIndex++] = object;
+		} else
+			throw new IndexOutOfBoundsException();
+
+		modCount++;
+	}
+
+	/**
+	 * Adds the specified object at the end of this ArrayList.
+	 * 
+	 * @param object
+	 *            the object to add
+	 * @return true
+	 */
+	public boolean add(Object object) {
+		if (lastIndex == array.length)
+			growAtEnd(1);
+		array[lastIndex++] = object;
+		modCount++;
+		return true;
+	}
+
+	/**
+	 * Inserts the objects in the specified Collection at the specified location
+	 * in this ArrayList. The objects are added in the order they are returned
+	 * from the Collection iterator.
+	 * 
+	 * @param location
+	 *            the index at which to insert
+	 * @param collection
+	 *            the Collection of objects
+	 * @return true if this ArrayList is modified, false otherwise
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public boolean addAll(int location, Collection collection) {
+		int size = size();
+		int growSize = collection.size();
+		if (0 < location && location < size) {
+			if (array.length - size < growSize) {
+				growForInsert(location, growSize);
+			} else if ((location < size / 2 && firstIndex > 0)
+					|| lastIndex > array.length - growSize) {
+				int newFirst = firstIndex - growSize;
+				if (newFirst < 0) {
+					int index = location + firstIndex;
+					System.arraycopy(array, index, array, index - newFirst,
+							size - location);
+					lastIndex -= newFirst;
+					newFirst = 0;
+				}
+				System.arraycopy(array, firstIndex, array, newFirst, location);
+				firstIndex = newFirst;
+			} else {
+				int index = location + firstIndex;
+				System.arraycopy(array, index, array, index + growSize, size
+						- location);
+				lastIndex += growSize;
+			}
+		} else if (location == 0) {
+			if (firstIndex == 0)
+				growAtFront(growSize);
+			firstIndex -= growSize;
+		} else if (location == size) {
+			if (lastIndex > array.length - growSize)
+				growAtEnd(growSize);
+			lastIndex += growSize;
+		} else
+			throw new IndexOutOfBoundsException();
+
+		if (growSize > 0) {
+			Iterator it = collection.iterator();
+			int index = location + firstIndex;
+			int end = index + growSize;
+			while (index < end)
+				array[index++] = it.next();
+			modCount++;
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Adds the objects in the specified Collection to this ArrayList.
+	 * 
+	 * @param collection
+	 *            the Collection of objects
+	 * @return true if this ArrayList is modified, false otherwise
+	 */
+	public boolean addAll(Collection collection) {
+		int growSize = collection.size();
+		if (growSize > 0) {
+			if (lastIndex > array.length - growSize)
+				growAtEnd(growSize);
+			Iterator it = collection.iterator();
+			int end = lastIndex + growSize;
+			while (lastIndex < end)
+				array[lastIndex++] = it.next();
+			modCount++;
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Removes all elements from this ArrayList, leaving it empty.
+	 * 
+	 * @see #isEmpty
+	 * @see #size
+	 */
+	public void clear() {
+		if (firstIndex != lastIndex) {
+			Arrays.fill(array, firstIndex, lastIndex, null);
+			firstIndex = lastIndex = 0;
+			modCount++;
+		}
+	}
+
+	/**
+	 * Answers a new ArrayList with the same elements, size and capacity as this
+	 * ArrayList.
+	 * 
+	 * @return a shallow copy of this ArrayList
+	 * 
+	 * @see java.lang.Cloneable
+	 */
+	public Object clone() {
+		try {
+			ArrayList newList = (ArrayList) super.clone();
+			newList.array = (Object[]) array.clone();
+			return newList;
+		} catch (CloneNotSupportedException e) {
+			return null;
+		}
+	}
+
+	/**
+	 * Searches this ArrayList for the specified object.
+	 * 
+	 * @param object
+	 *            the object to search for
+	 * @return true if <code>object</code> is an element of this ArrayList,
+	 *         false otherwise
+	 */
+	public boolean contains(Object object) {
+		if (object != null) {
+			for (int i = firstIndex; i < lastIndex; i++)
+				if (object.equals(array[i]))
+					return true;
+		} else {
+			for (int i = firstIndex; i < lastIndex; i++)
+				if (array[i] == null)
+					return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Ensures that this ArrayList can hold the specified number of elements
+	 * without growing.
+	 * 
+	 * @param minimumCapacity
+	 *            the minimum number of elements that this ArrayList will hold
+	 *            before growing
+	 */
+	public void ensureCapacity(int minimumCapacity) {
+		if (array.length < minimumCapacity) {
+			if (firstIndex > 0)
+				growAtFront(minimumCapacity - array.length);
+			else
+				growAtEnd(minimumCapacity - array.length);
+		}
+	}
+
+	/**
+	 * Answers the element at the specified location in this ArrayList.
+	 * 
+	 * @param location
+	 *            the index of the element to return
+	 * @return the element at the specified index
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public Object get(int location) {
+		if (0 <= location && location < size())
+			return array[firstIndex + location];
+		throw new IndexOutOfBoundsException();
+	}
+
+	private void growAtEnd(int required) {
+		int size = size();
+		if (firstIndex >= required - (array.length - lastIndex)) {
+			int newLast = lastIndex - firstIndex;
+			if (size > 0) {
+				System.arraycopy(array, firstIndex, array, 0, size);
+				int start = newLast < firstIndex ? firstIndex : newLast;
+				Arrays.fill(array, start, array.length, null);
+			}
+			firstIndex = 0;
+			lastIndex = newLast;
+		} else {
+			int increment = size / 2;
+			if (required > increment)
+				increment = required;
+			if (increment < 12)
+				increment = 12;
+			Object[] newArray = new Object[size + increment];
+			if (size > 0)
+				System.arraycopy(array, firstIndex, newArray, firstIndex, size);
+			array = newArray;
+		}
+	}
+
+	private void growAtFront(int required) {
+		int size = size();
+		if (array.length - lastIndex >= required) {
+			int newFirst = array.length - lastIndex;
+			if (size > 0) {
+				System.arraycopy(array, firstIndex, array, newFirst, size);
+				int length = firstIndex + size > newFirst ? newFirst
+						: firstIndex + size;
+				Arrays.fill(array, firstIndex, length, null);
+			}
+			firstIndex = newFirst;
+			lastIndex = array.length;
+		} else {
+			int increment = size / 2;
+			if (required > increment)
+				increment = required;
+			if (increment < 12)
+				increment = 12;
+			Object[] newArray = new Object[size + increment];
+			if (size > 0)
+				System.arraycopy(array, firstIndex, newArray, newArray.length
+						- lastIndex, size);
+			firstIndex = newArray.length - lastIndex;
+			lastIndex = newArray.length;
+			array = newArray;
+		}
+	}
+
+	private void growForInsert(int location, int required) {
+		int size = size(), increment = size / 2;
+		if (required > increment)
+			increment = required;
+		if (increment < 12)
+			increment = 12;
+		Object[] newArray = new Object[size + increment];
+		if (location < size / 2) {
+			int newFirst = newArray.length - (size + required);
+			System.arraycopy(array, location, newArray, location + increment,
+					size - location);
+			System.arraycopy(array, firstIndex, newArray, newFirst, location);
+			firstIndex = newFirst;
+			lastIndex = newArray.length;
+		} else {
+			System.arraycopy(array, firstIndex, newArray, 0, location);
+			System.arraycopy(array, location, newArray, location + required,
+					size - location);
+			firstIndex = 0;
+			lastIndex += required;
+		}
+		array = newArray;
+	}
+
+	/**
+	 * Searches this ArrayList for the specified object and returns the index of
+	 * the first occurrence.
+	 * 
+	 * @param object
+	 *            the object to search for
+	 * @return the index of the first occurrence of the object
+	 */
+	public int indexOf(Object object) {
+		if (object != null) {
+			for (int i = firstIndex; i < lastIndex; i++)
+				if (object.equals(array[i]))
+					return i - firstIndex;
+		} else {
+			for (int i = firstIndex; i < lastIndex; i++)
+				if (array[i] == null)
+					return i - firstIndex;
+		}
+		return -1;
+	}
+
+	/**
+	 * Answers if this ArrayList has no elements, a size of zero.
+	 * 
+	 * @return true if this ArrayList has no elements, false otherwise
+	 * 
+	 * @see #size
+	 */
+	public boolean isEmpty() {
+		return lastIndex == firstIndex;
+	}
+
+	/**
+	 * Searches this ArrayList for the specified object and returns the index of
+	 * the last occurrence.
+	 * 
+	 * @param object
+	 *            the object to search for
+	 * @return the index of the last occurrence of the object
+	 */
+	public int lastIndexOf(Object object) {
+		if (object != null) {
+			for (int i = lastIndex - 1; i >= firstIndex; i--)
+				if (object.equals(array[i]))
+					return i - firstIndex;
+		} else {
+			for (int i = lastIndex - 1; i >= firstIndex; i--)
+				if (array[i] == null)
+					return i - firstIndex;
+		}
+		return -1;
+	}
+
+	/**
+	 * Removes the object at the specified location from this ArrayList.
+	 * 
+	 * @param location
+	 *            the index of the object to remove
+	 * @return the removed object
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public Object remove(int location) {
+		Object result;
+		int size = size();
+		if (0 <= location && location < size) {
+			if (location == size - 1) {
+				result = array[--lastIndex];
+				array[lastIndex] = null;
+			} else if (location == 0) {
+				result = array[firstIndex];
+				array[firstIndex++] = null;
+			} else {
+				int elementIndex = firstIndex + location;
+				result = array[elementIndex];
+				if (location < size / 2) {
+					System.arraycopy(array, firstIndex, array, firstIndex + 1,
+							location);
+					array[firstIndex++] = null;
+				} else {
+					System.arraycopy(array, elementIndex + 1, array,
+							elementIndex, size - location - 1);
+					array[--lastIndex] = null;
+				}
+			}
+		} else
+			throw new IndexOutOfBoundsException();
+
+		modCount++;
+		return result;
+	}
+
+	/**
+	 * Removes the objects in the specified range from the start to the end, but
+	 * not including the end index.
+	 * 
+	 * @param start
+	 *            the index at which to start removing
+	 * @param end
+	 *            the index one past the end of the range to remove
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>start < 0, start > end</code> or
+	 *                <code>end > size()</code>
+	 */
+	protected void removeRange(int start, int end) {
+		if (start >= 0 && start <= end && end <= size()) {
+			if (start == end)
+				return;
+			int size = size();
+			if (end == size) {
+				Arrays.fill(array, firstIndex + start, lastIndex, null);
+				lastIndex = firstIndex + start;
+			} else if (start == 0) {
+				Arrays.fill(array, firstIndex, firstIndex + end, null);
+				firstIndex += end;
+			} else {
+				System.arraycopy(array, firstIndex + end, array, firstIndex
+						+ start, size - end);
+				int newLast = lastIndex + start - end;
+				Arrays.fill(array, newLast, lastIndex, null);
+				lastIndex = newLast;
+			}
+			modCount++;
+		} else
+			throw new IndexOutOfBoundsException();
+	}
+
+	/**
+	 * Replaces the element at the specified location in this ArrayList with the
+	 * specified object.
+	 * 
+	 * @param location
+	 *            the index at which to put the specified object
+	 * @param object
+	 *            the object to add
+	 * @return the previous element at the index
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>location < 0 || >= size()</code>
+	 */
+	public Object set(int location, Object object) {
+		if (0 <= location && location < size()) {
+			Object result = array[firstIndex + location];
+			array[firstIndex + location] = object;
+			return result;
+		}
+		throw new IndexOutOfBoundsException();
+	}
+
+	/**
+	 * Answers the number of elements in this ArrayList.
+	 * 
+	 * @return the number of elements in this ArrayList
+	 */
+	public int size() {
+		return lastIndex - firstIndex;
+	}
+
+	/**
+	 * Answers a new array containing all elements contained in this ArrayList.
+	 * 
+	 * @return an array of the elements from this ArrayList
+	 */
+	public Object[] toArray() {
+		int size = size();
+		Object[] result = new Object[size];
+		System.arraycopy(array, firstIndex, result, 0, size);
+		return result;
+	}
+
+	/**
+	 * Answers an array containing all elements contained in this ArrayList. If
+	 * the specified array is large enough to hold the elements, the specified
+	 * array is used, otherwise an array of the same type is created. If the
+	 * specified array is used and is larger than this ArrayList, the array
+	 * element following the collection elements is set to null.
+	 * 
+	 * @param contents
+	 *            the array
+	 * @return an array of the elements from this ArrayList
+	 * 
+	 * @exception ArrayStoreException
+	 *                when the type of an element in this ArrayList cannot be
+	 *                stored in the type of the specified array
+	 */
+	public Object[] toArray(Object[] contents) {
+		int size = size();
+		if (size > contents.length)
+			contents = (Object[]) Array.newInstance(contents.getClass()
+					.getComponentType(), size);
+		System.arraycopy(array, firstIndex, contents, 0, size);
+		if (size < contents.length)
+			contents[size] = null;
+		return contents;
+	}
+
+	/**
+	 * Sets the capacity of this ArrayList to be the same as the size.
+	 * 
+	 * @see #size
+	 */
+	public void trimToSize() {
+		int size = size();
+		Object[] newArray = new Object[size];
+		System.arraycopy(array, firstIndex, newArray, 0, size);
+		array = newArray;
+		firstIndex = 0;
+		lastIndex = array.length;
+	}
+
+	private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
+			"size", Integer.TYPE) }; //$NON-NLS-1$
+
+	private void writeObject(ObjectOutputStream stream) throws IOException {
+		ObjectOutputStream.PutField fields = stream.putFields();
+		fields.put("size", size()); //$NON-NLS-1$
+		stream.writeFields();
+		stream.writeInt(array.length);
+		Iterator it = iterator();
+		while (it.hasNext())
+			stream.writeObject(it.next());
+	}
+
+	private void readObject(ObjectInputStream stream) throws IOException,
+			ClassNotFoundException {
+		ObjectInputStream.GetField fields = stream.readFields();
+		lastIndex = fields.get("size", 0); //$NON-NLS-1$
+		array = new Object[stream.readInt()];
+		for (int i = 0; i < lastIndex; i++)
+			array[i] = stream.readObject();
+	}
+}



Mime
View raw message