URL comparison patch
Anthony Green
green@cygnus.com
Mon Jul 5 13:39:00 GMT 1999
I'm committing the following fix to the trunk. It fixes a small
number of mauve tests.
Mon Jul 5 12:01:35 1999 Anthony Green <green@cygnus.com>
* java/net/URL.java (equals): Compare strings using String.equals.
* java/net/URL.java (sameFile): Ditto.
Index: libjava/java/net/URL.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/URL.java,v
retrieving revision 1.2
diff -u -p -u -r1.2 URL.java
--- URL.java 1999/06/03 22:29:11 1.2
+++ URL.java 1999/07/05 20:29:20
@@ -189,11 +189,18 @@ public final class URL implements Serial
return false;
URL uObj = (URL) obj;
- if (protocol != uObj.protocol || host != uObj.host || port != uObj.port ||
- file != uObj.file || ref != uObj.ref)
- return false;
-
- return true;
+
+ // This comparison is very conservative. It assumes that any
+ // field can be null.
+ return (port == uObj.port
+ && ((protocol == null && uObj.protocol == null)
+ || (protocol != null && protocol.equals(uObj.protocol)))
+ && ((host == null && uObj.host == null)
+ || (host != null && host.equals(uObj.host)))
+ && ((file == null && uObj.file == null)
+ || (file != null && file.equals(uObj.file)))
+ && ((ref == null && uObj.ref == null)
+ || (ref != null && ref.equals(uObj.ref))));
}
public final Object getContent() throws IOException
@@ -258,11 +265,16 @@ public final class URL implements Serial
public boolean sameFile(URL other)
{
- if (other == null || protocol != other.protocol || host != other.host ||
- port != other.port || file != other.file)
- return false;
-
- return true;
+ // This comparison is very conservative. It assumes that any
+ // field can be null.
+ return (other != null
+ && port == other.port
+ && ((protocol == null && other.protocol == null)
+ || (protocol != null && protocol.equals(other.protocol)))
+ && ((host == null && other.host == null)
+ || (host != null && host.equals(other.host)))
+ && ((file == null && other.file == null)
+ || (file != null && file.equals(other.file))));
}
protected void set(String protocol, String host, int port, String file,
--
Anthony Green Cygnus Solutions
Sunnyvale, California
More information about the Java-patches
mailing list