Package io.openems.edge.core.host
Class Inet4AddressWithSubnetmask
- java.lang.Object
-
- io.openems.edge.core.host.Inet4AddressWithSubnetmask
-
public class Inet4AddressWithSubnetmask extends java.lang.Object
Helper class for wrapping an IPv4 address together with its subnetmask in CIDR format.
-
-
Constructor Summary
Constructors Constructor Description Inet4AddressWithSubnetmask(java.lang.String label, java.net.Inet4Address inet4Address, int subnetmask)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
static Inet4AddressWithSubnetmask
fromString(java.lang.String value)
Parse a string in the form "192.168.100.100/24" to an IPv4 address.static Inet4AddressWithSubnetmask
fromString(java.lang.String label, java.lang.String value)
Parse a string in the form "192.168.100.100/24" to an IPv4 address.static int
getCidrFromSubnetmask(java.net.Inet4Address subnetmask)
Converts the Subnetmask to a CIDR number.java.net.Inet4Address
getInet4Address()
java.lang.String
getLabel()
int
getSubnetmaskAsCidr()
Gets the Subnetmask in CIDR format, e.g.java.lang.String
getSubnetmaskAsString()
Gets the Subnetmask in string format, e.g.int
hashCode()
boolean
isInSameNetwork(Inet4AddressWithSubnetmask other)
Determines if this address and the given address are in the same network.java.lang.String
toString()
-
-
-
Method Detail
-
fromString
public static Inet4AddressWithSubnetmask fromString(java.lang.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(java.lang.String label, java.lang.String value) throws OpenemsException
Parse a string in the form "192.168.100.100/24" to an IPv4 address.- Parameters:
label
- a label stringvalue
- the string in the form "192.168.100.100/24"- Returns:
- the new
Inet4AddressWithSubnetmask
- Throws:
OpenemsException
- on error
-
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 classjava.lang.Object
-
isInSameNetwork
public boolean isInSameNetwork(Inet4AddressWithSubnetmask other)
Determines if this address and the given address are in the same network.- Parameters:
other
- the otherInet4AddressWithSubnetmask
- Returns:
- true if they are in the same network
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-