Hi again,

InetAddress contains a bunch of IPv4-specific methods to which their
equivalents in Inet4Address defer.  This is decidedly non-OO, so this
commit moves the implementations to Inet4Address and makes the methods
in InetAddress throw UnsupportedOperationExceptions.

Cheers,
Gary
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.8514
diff -u -r1.8514 ChangeLog
--- ChangeLog   8 Sep 2006 09:13:27 -0000       1.8514
+++ ChangeLog   8 Sep 2006 11:00:43 -0000
@@ -1,3 +1,16 @@
+2006-09-08  Gary Benson  <[EMAIL PROTECTED]>
+
+       * java/net/Inet4Address.java (isMulticastAddress,
+       isLoopbackAddress, isAnyLocalAddress, isLinkLocalAddress,
+       isSiteLocalAddress, isMCGlobal, isMCNodeLocal, isMCLinkLocal,
+       isMCSiteLocal, isMCOrgLocal, getHostAddress): Moved
+       implementations from InetAddress.
+       * java/net/InetAddress.java (isMulticastAddress,
+       isLoopbackAddress, isAnyLocalAddress, isLinkLocalAddress,
+       isSiteLocalAddress, isMCGlobal, isMCNodeLocal, isMCLinkLocal,
+       isMCSiteLocal, isMCOrgLocal, getHostAddress): Replace
+       implementations with UnsupportedOperationExceptions.
+       
 2006-09-08  Gary Benson  <[EMAIL PROTECTED]>
 
        * java/net/InetAddress.java
Index: java/net/Inet4Address.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/Inet4Address.java,v
retrieving revision 1.19
diff -u -r1.19 Inet4Address.java
--- java/net/Inet4Address.java  8 Sep 2006 08:59:56 -0000       1.19
+++ java/net/Inet4Address.java  8 Sep 2006 11:00:43 -0000
@@ -84,7 +84,7 @@
    */
   public boolean isMulticastAddress()
   {
-    return super.isMulticastAddress();
+    return (addr[0] & 0xf0) == 0xe0;
   }
 
   /**
@@ -92,7 +92,7 @@
    */
   public boolean isLoopbackAddress()
   {
-    return super.isLoopbackAddress();
+    return (addr[0] & 0xff) == 0x7f;
   }
 
   /**
@@ -102,7 +102,7 @@
    */
   public boolean isAnyLocalAddress()
   {
-    return super.isAnyLocalAddress();
+    return equals(InetAddress.ANY_IF);
   }
 
   /**
@@ -112,7 +112,7 @@
    */
   public boolean isLinkLocalAddress()
   {
-    return super.isLinkLocalAddress();
+    return false;
   }
 
   /**
@@ -122,7 +122,19 @@
    */
   public boolean isSiteLocalAddress()
   {
-    return super.isSiteLocalAddress();
+    // 10.0.0.0/8
+    if ((addr[0] & 0xff) == 0x0a)
+      return true;
+
+    // 172.16.0.0/12
+    if ((addr[0] & 0xff) == 0xac && (addr[1] & 0xf0) == 0x10)
+      return true;
+
+    // 192.168.0.0/16
+    if ((addr[0] & 0xff) == 0xc0 && (addr[1] & 0xff) == 0xa8)
+      return true;
+
+    return false;
   }
 
   /**
@@ -132,7 +144,7 @@
    */
   public boolean isMCGlobal()
   {
-    return super.isMCGlobal();
+    return false;
   }
 
   /**
@@ -142,7 +154,7 @@
    */
   public boolean isMCNodeLocal()
   {
-    return super.isMCNodeLocal();
+    return false;
   }
 
   /**
@@ -152,7 +164,12 @@
    */
   public boolean isMCLinkLocal()
   {
-    return super.isMCLinkLocal();
+    if (! isMulticastAddress())
+      return false;
+
+    return ((addr[0] & 0xff) == 0xe0
+           && (addr[1] & 0xff)  == 0x00
+           && (addr[2] & 0xff)  == 0x00);
   }
 
   /**
@@ -162,7 +179,7 @@
    */
   public boolean isMCSiteLocal()
   {
-    return super.isMCSiteLocal();
+    return false;
   }
 
   /**
@@ -172,7 +189,7 @@
    */
   public boolean isMCOrgLocal()
   {
-    return super.isMCOrgLocal();
+    return false;
   }
 
   /**
@@ -190,7 +207,23 @@
    */
   public String getHostAddress()
   {
-    return super.getHostAddress();
+    StringBuffer sb = new StringBuffer(40);
+
+    int len = addr.length;
+    int i = 0;
+    
+    for ( ; ; )
+      {
+        sb.append(addr[i] & 0xff);
+        i++;
+       
+        if (i == len)
+          break;
+       
+        sb.append('.');
+      }
+
+    return sb.toString();
   }
 
   /**
Index: java/net/InetAddress.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/InetAddress.java,v
retrieving revision 1.47
diff -u -r1.47 InetAddress.java
--- java/net/InetAddress.java   8 Sep 2006 08:59:56 -0000       1.47
+++ java/net/InetAddress.java   8 Sep 2006 11:00:43 -0000
@@ -159,150 +159,144 @@
    * An address is multicast if the high four bits are "1110".  These are
    * also known as "Class D" addresses.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @return true if mulitcast, false if not
    *
    * @since 1.1
    */
   public boolean isMulticastAddress()
   {
-    // Mask against high order bits of 1110
-    if (addr.length == 4)
-      return (addr[0] & 0xf0) == 0xe0;
-
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if the InetAddress in a wildcard address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isAnyLocalAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    return equals(ANY_IF);
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if the InetAddress is a loopback address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isLoopbackAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    return (addr[0] & 0xff) == 0x7f;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a link local address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isLinkLocalAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a site local address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isSiteLocalAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-
-    // 10.0.0.0/8
-    if ((addr[0] & 0xff) == 0x0a)
-      return true;
-
-    // 172.16.0.0/12
-    if ((addr[0] & 0xff) == 0xac && (addr[1] & 0xf0) == 0x10)
-      return true;
-
-    // 192.168.0.0/16
-    if ((addr[0] & 0xff) == 0xc0 && (addr[1] & 0xff) == 0xa8)
-      return true;
-
-    // XXX: Do we need to check more addresses here ?
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a global multicast address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCGlobal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a node local multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCNodeLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a link local multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCLinkLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    if (! isMulticastAddress())
-      return false;
-
-    return ((addr[0] & 0xff) == 0xe0
-           && (addr[1] & 0xff)  == 0x00
-           && (addr[2] & 0xff)  == 0x00);
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a site local multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCSiteLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a organization local
    * multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCOrgLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
@@ -373,32 +367,19 @@
   }
 
   /**
-   * Returns the IP address of this object as a String.  The address is in
-   * the dotted octet notation, for example, "127.0.0.1".
+   * Returns the IP address of this object as a String.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws [EMAIL PROTECTED] UnsupportedOperationException} 
unless
+   * overridden.</p>
+   * 
    * @return The IP address of this object in String form
    *
    * @since 1.0.2
    */
   public String getHostAddress()
   {
-    StringBuffer sb = new StringBuffer(40);
-
-    int len = addr.length;
-    int i = 0;
-    
-    for ( ; ; )
-      {
-        sb.append(addr[i] & 0xff);
-        i++;
-       
-        if (i == len)
-          break;
-       
-        sb.append('.');
-      }
-
-    return sb.toString();
+    throw new UnsupportedOperationException();
   }
 
   /**

Reply via email to