Class Inet4AddressWithSubnetmask

java.lang.Object
io.openems.edge.core.host.Inet4AddressWithSubnetmask

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

    • Inet4AddressWithSubnetmask

      public Inet4AddressWithSubnetmask(String label, Inet4Address inet4Address, int subnetmask)
  • Method Details

    • fromString

      public static Inet4AddressWithSubnetmask fromString(String value) throws OpenemsException
      Parse a string in the form "192.168.100.100/24" to an IPv4 address. Label is set to an empty string with this factory method.
      Parameters:
      value - the string in the form "192.168.100.100/24"
      Returns:
      the new Inet4AddressWithSubnetmask
      Throws:
      OpenemsException - on error
    • fromString

      public static Inet4AddressWithSubnetmask fromString(String label, String value) throws OpenemsException
      Parse a string in the form "192.168.100.100/24" to an IPv4 address.
      Parameters:
      label - a label string
      value - the string in the form "192.168.100.100/24"
      Returns:
      the new Inet4AddressWithSubnetmask
      Throws:
      OpenemsException - on error
    • getCidrFromSubnetmask

      public static int getCidrFromSubnetmask(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 String getLabel()
    • getInet4Address

      public 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 String getSubnetmaskAsString()
      Gets the Subnetmask in string format, e.g. "255.255.255.0" for "24".
      Returns:
      the subnetmask
    • toString

      public String toString()
      Overrides:
      toString in class 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 Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object