2002-10-11 Michael Koch <konqueror@gmx.de>

* java/net/URL.java
	(URL): Activate SecurityManager checks.
	(equals): Use URLStreamHandler implementation instead of doing it
	alone. This allows special protocol stream handlers to change default
	behaviour.
	(hashCode): Use URLStreamHandler implementation instead of doing it
	alone. This allows special protocol stream handlers to change default
	behaviour.
	* java/net/URLStreamHandler.java
	(equals): Implemented default URL equality check.
	(hostsEqual): Implemented default URL equality check.
	(hashCode): Implemented default URL hashCode algorithm.
	* java/net/natPlainDatagramSocketImpl.cc:
	No lines longer then 80 characters.

From-SVN: r58345
This commit is contained in:
Michael Koch 2002-10-21 04:53:50 +00:00 committed by Michael Koch
parent e2a450f6e8
commit e1caed8988
4 changed files with 65 additions and 48 deletions

View file

@ -234,8 +234,30 @@ public abstract class URLStreamHandler
*/
protected boolean equals (URL url1, URL url2)
{
// FIXME: implement this
return false;
// This comparison is very conservative. It assumes that any
// field can be null.
return (url1.getPort () == url2.getPort ()
&& ((url1.getProtocol () == null && url2.getProtocol () == null)
|| (url1.getProtocol () != null
&& url1.getProtocol ().equals (url2.getProtocol ())))
&& ((url1.getUserInfo () == null && url2.getUserInfo () == null)
|| (url1.getUserInfo () != null
&& url1.getUserInfo ().equals(url2.getUserInfo ())))
&& ((url1.getAuthority () == null && url2.getAuthority () == null)
|| (url1.getAuthority () != null
&& url1.getAuthority ().equals(url2.getAuthority ())))
&& ((url1.getHost () == null && url2.getHost () == null)
|| (url1.getHost () != null
&& url1.getHost ().equals(url2.getHost ())))
&& ((url1.getPath () == null && url2.getPath () == null)
|| (url1.getPath () != null
&& url1.getPath ().equals (url2.getPath ())))
&& ((url1.getQuery () == null && url2.getQuery () == null)
|| (url1.getQuery () != null
&& url1.getQuery ().equals(url2.getQuery ())))
&& ((url1.getRef () == null && url2.getRef () == null)
|| (url1.getRef () != null
&& url1.getRef ().equals(url2.getRef ()))));
}
/**
@ -244,9 +266,12 @@ public abstract class URLStreamHandler
* @exception UnknownHostException If an unknown host is found
*/
protected boolean hostsEqual (URL url1, URL url2)
throws UnknownHostException
{
// FIXME: implement this
return false;
InetAddress addr1 = InetAddress.getByName (url1.getHost ());
InetAddress addr2 = InetAddress.getByName (url2.getHost ());
return addr1.equals (addr2);
}
/**
@ -285,8 +310,10 @@ public abstract class URLStreamHandler
*/
protected int hashCode (URL url)
{
// FIXME: implement this
return 0;
return url.getProtocol ().hashCode () +
((url.getHost () == null) ? 0 : url.getHost ().hashCode ()) +
url.getFile ().hashCode() +
url.getPort ();
}
/**