Class Inet4AddressWithSubnetmask


  • public class Inet4AddressWithSubnetmask
    extends java.lang.Object
    Helper class for wrapping an IPv4 address together with its subnetmask in CIDR format.
    • Constructor Detail

      • Inet4AddressWithSubnetmask

        public Inet4AddressWithSubnetmask​(java.lang.String label,
                                          java.net.Inet4Address inet4Address,
                                          int subnetmask)
    • Method Detail

      • getCidrFromSubnetmask

        public static int getCidrFromSubnetmask​(java.net.Inet4Address subnetmask)
                                         throws OpenemsException
        Converts the Subnetmask to a CIDR number.

        e. g. Converts "255.255.255.0" to "24".

        Parameters:
        subnetmask - the subnetmask.
        Returns:
        the CIDR number.
        Throws:
        OpenemsException
      • getLabel

        public java.lang.String getLabel()
      • getInet4Address

        public java.net.Inet4Address getInet4Address()
      • getSubnetmaskAsCidr

        public int getSubnetmaskAsCidr()
        Gets the Subnetmask in CIDR format, e.g. "24" for "255.255.255.0".
        Returns:
        the subnetmask
      • getSubnetmaskAsString

        public final java.lang.String getSubnetmaskAsString()
        Gets the Subnetmask in string format, e.g. "255.255.255.0" for "24".
        Returns:
        the subnetmask
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isInSameNetwork

        public boolean isInSameNetwork​(Inet4AddressWithSubnetmask other)
        Determines if this address and the given address are in the same network.
        Parameters:
        other - the other Inet4AddressWithSubnetmask
        Returns:
        true if they are in the same network
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object