Imported GNU Classpath 0.90

Imported GNU Classpath 0.90
       * scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
       * gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
       * java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
       * java/lang/Math.java: New override file.
       * java/lang/Character.java: Merged from Classpath.
       (start, end): Now 'int's.
       (canonicalName): New field.
       (CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
       (UnicodeBlock): Added argument.
       (of): New overload.
       (forName): New method.
       Updated unicode blocks.
       (sets): Updated.
       * sources.am: Regenerated.
       * Makefile.in: Likewise.

From-SVN: r111942
This commit is contained in:
Mark Wielaard 2006-03-10 21:46:48 +00:00
parent 27079765d0
commit 8aa540d2f7
1367 changed files with 188789 additions and 22762 deletions

View file

@ -1,5 +1,5 @@
/* Headers.java --
Copyright (C) 2004 Free Software Foundation, Inc.
Copyright (C) 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -44,125 +44,75 @@ import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
/**
* A collection of HTTP header names and associated values.
* Retrieval of values is case insensitive. An iteration over the keys
* A collection of HTTP header names and associated values. The
* values are {@link ArrayList ArrayLists} of Strings. Retrieval of
* values is case insensitive. An iteration over the collection
* returns the header names in the order they were received.
*
* @author Chris Burdess (dog@gnu.org)
* @author David Daney (ddaney@avtrex.com)
*/
public class Headers
extends LinkedHashMap
class Headers
{
/**
* A list of HeaderElements
*
*/
private final ArrayList headers = new ArrayList();
static final DateFormat dateFormat = new HTTPDateFormat();
static class Header
static class HeaderElement
{
String name;
String value;
final String name;
Header(String name)
HeaderElement(String name, String value)
{
if (name == null || name.length() == 0)
{
throw new IllegalArgumentException(name);
}
this.name = name;
this.value = value;
}
public int hashCode()
{
return name.toLowerCase().hashCode();
}
public boolean equals(Object other)
{
if (other instanceof Header)
{
return ((Header) other).name.equalsIgnoreCase(name);
}
return false;
}
public String toString()
{
return name;
}
}
static class HeaderEntry
implements Map.Entry
{
final Map.Entry entry;
HeaderEntry(Map.Entry entry)
{
this.entry = entry;
}
public Object getKey()
{
return ((Header) entry.getKey()).name;
}
public Object getValue()
{
return entry.getValue();
}
public Object setValue(Object value)
{
return entry.setValue(value);
}
public int hashCode()
{
return entry.hashCode();
}
public boolean equals(Object other)
{
return entry.equals(other);
}
public String toString()
{
return getKey().toString() + "=" + getValue();
}
}
public Headers()
{
}
public boolean containsKey(Object key)
{
return super.containsKey(new Header((String) key));
}
public Object get(Object key)
{
return super.get(new Header((String) key));
}
/**
* Returns the value of the specified header as a string.
* Return an Iterator over this collection of headers.
* Iterator.getNext() returns objects of type {@link HeaderElement}.
*
* @return the Iterator.
*/
Iterator iterator()
{
return headers.iterator();
}
/**
* Returns the value of the specified header as a string. If
* multiple values are present, the last one is returned.
*/
public String getValue(String header)
{
return (String) super.get(new Header(header));
for (int i = headers.size() - 1; i >= 0; i--)
{
HeaderElement e = (HeaderElement)headers.get(i);
if (e.name.equalsIgnoreCase(header))
{
return e.value;
}
}
return null;
}
/**
@ -228,51 +178,62 @@ public class Headers
}
}
public Object put(Object key, Object value)
/**
* Add a header to this set of headers. If there is an existing
* header with the same name, it is discarded.
*
* @param name the header name
* @param value the header value
*
* @see #addValue
*/
public void put(String name, String value)
{
return super.put(new Header((String) key), value);
}
public Object remove(Object key)
{
return super.remove(new Header((String) key));
}
public void putAll(Map t)
{
for (Iterator i = t.keySet().iterator(); i.hasNext(); )
{
String key = (String) i.next();
String value = (String) t.get(key);
put(key, value);
}
}
public Set keySet()
{
Set keys = super.keySet();
Set ret = new LinkedHashSet();
for (Iterator i = keys.iterator(); i.hasNext(); )
{
ret.add(((Header) i.next()).name);
}
return ret;
}
public Set entrySet()
{
Set entries = super.entrySet();
Set ret = new LinkedHashSet();
for (Iterator i = entries.iterator(); i.hasNext(); )
{
Map.Entry entry = (Map.Entry) i.next();
ret.add(new HeaderEntry(entry));
}
return ret;
remove(name);
headers.add(headers.size(), new HeaderElement(name, value));
}
/**
* Parse the specified input stream, adding headers to this collection.
* Add all headers from a set of headers to this set. If any of the
* headers to be added have the same name as existing headers, the
* existing headers will be discarded.
*
* @param o the headers to be added
*/
public void putAll(Headers o)
{
for (Iterator it = o.iterator(); it.hasNext(); )
{
HeaderElement e = (HeaderElement)it.next();
remove(e.name);
}
for (Iterator it = o.iterator(); it.hasNext(); )
{
HeaderElement e = (HeaderElement)it.next();
addValue(e.name, e.value);
}
}
/**
* Remove a header from this set of headers. If there is more than
* one instance of a header of the given name, they are all removed.
*
* @param name the header name
*/
public void remove(String name)
{
for (Iterator it = headers.iterator(); it.hasNext(); )
{
HeaderElement e = (HeaderElement)it.next();
if (e.name.equalsIgnoreCase(name))
it.remove();
}
}
/**
* Parse the specified InputStream, adding headers to this collection.
*
* @param in the InputStream.
*/
public void parse(InputStream in)
throws IOException
@ -334,18 +295,90 @@ public class Headers
}
}
private void addValue(String name, String value)
/**
* Add a header to this set of headers. If there is an existing
* header with the same name, it is not effected.
*
* @param name the header name
* @param value the header value
*
* @see #put
*/
public void addValue(String name, String value)
{
Header key = new Header(name);
String old = (String) super.get(key);
if (old == null)
headers.add(headers.size(), new HeaderElement(name, value));
}
/**
* Get a new Map containing all the headers. The keys of the Map
* are Strings (the header names). The values of the Map are
* unmodifiable Lists containing Strings (the header values).
*
* <p>
*
* The returned map is modifiable. Changing it will not effect this
* collection of Headers in any way.
*
* @return a Map containing all the headers.
*/
public Map getAsMap()
{
LinkedHashMap m = new LinkedHashMap();
for (Iterator it = headers.iterator(); it.hasNext(); )
{
super.put(key, value);
HeaderElement e = (HeaderElement)it.next();
ArrayList l = (ArrayList)m.get(e.name);
if (l == null)
{
l = new ArrayList(1);
l.add(e.value);
m.put(e.name, l);
}
else
l.add(0, e.value);
}
else
for (Iterator it = m.entrySet().iterator(); it.hasNext(); )
{
super.put(key, old + ", " + value);
Map.Entry me = (Map.Entry)it.next();
ArrayList l = (ArrayList)me.getValue();
me.setValue(Collections.unmodifiableList(l));
}
return m;
}
/**
* Get the name of the Nth header.
*
* @param i the header index.
*
* @return the header name.
*
* @see #getHeaderValue
*/
public String getHeaderName(int i)
{
if (i >= headers.size() || i < 0)
return null;
return ((HeaderElement)headers.get(i)).name;
}
/**
* Get the value of the Nth header.
*
* @param i the header index.
*
* @return the header value.
*
* @see #getHeaderName
*/
public String getHeaderValue(int i)
{
if (i >= headers.size() || i < 0)
return null;
return ((HeaderElement)headers.get(i)).value;
}
}