src/java.base/share/classes/java/net/InterfaceAddress.java
changeset 57895 82a71d82e326
parent 47216 71c04702a3d5
equal deleted inserted replaced
57894:01b9c26e2651 57895:82a71d82e326
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package java.net;
    26 package java.net;
       
    27 
       
    28 import java.util.Objects;
    27 
    29 
    28 /**
    30 /**
    29  * This class represents a Network Interface address. In short it's an
    31  * This class represents a Network Interface address. In short it's an
    30  * IP address, a subnet mask and a broadcast address when the address is
    32  * IP address, a subnet mask and a broadcast address when the address is
    31  * an IPv4 one. An IP address and a network prefix length in the case
    33  * an IPv4 one. An IP address and a network prefix length in the case
    97      * @return  {@code true} if the objects are the same;
    99      * @return  {@code true} if the objects are the same;
    98      *          {@code false} otherwise.
   100      *          {@code false} otherwise.
    99      * @see     java.net.InterfaceAddress#hashCode()
   101      * @see     java.net.InterfaceAddress#hashCode()
   100      */
   102      */
   101     public boolean equals(Object obj) {
   103     public boolean equals(Object obj) {
   102         if (!(obj instanceof InterfaceAddress)) {
   104         if (obj instanceof InterfaceAddress) {
   103             return false;
   105             InterfaceAddress cmp = (InterfaceAddress) obj;
       
   106 
       
   107             if (Objects.equals(address, cmp.address) &&
       
   108                 Objects.equals(broadcast, cmp.broadcast) &&
       
   109                 maskLength == cmp.maskLength)
       
   110             {
       
   111                 return true;
       
   112             }
   104         }
   113         }
   105         InterfaceAddress cmp = (InterfaceAddress) obj;
   114         return false;
   106         if ( !(address == null ? cmp.address == null : address.equals(cmp.address)) )
       
   107             return false;
       
   108         if ( !(broadcast  == null ? cmp.broadcast == null : broadcast.equals(cmp.broadcast)) )
       
   109             return false;
       
   110         if (maskLength != cmp.maskLength)
       
   111             return false;
       
   112         return true;
       
   113     }
   115     }
   114 
   116 
   115     /**
   117     /**
   116      * Returns a hashcode for this Interface address.
   118      * Returns a hashcode for this Interface address.
   117      *
   119      *