Class SubnetUtils.SubnetInfo

  • Enclosing class:
    SubnetUtils

    public final class SubnetUtils.SubnetInfo
    extends java.lang.Object
    Contains subnet summary information.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static long UNSIGNED_INT_MASK
      Mask to convert unsigned int to a long (i.e.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SubnetInfo()  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      int asInteger​(java.lang.String address)
      Converts a dotted decimal format address to a packed integer format.
      private long broadcastLong()  
      java.lang.String getAddress()
      Gets this instance's address into a dotted decimal String.
      int getAddressCount()
      Deprecated.
      (3.4) use getAddressCountLong() instead
      long getAddressCountLong()
      Gets the count of available addresses.
      java.lang.String[] getAllAddresses()
      Gets all addresses in this subnet, the return array could be huge.
      java.lang.String getBroadcastAddress()
      Gets the broadcast address for this subnet.
      java.lang.String getCidrSignature()
      Gets the CIDR signature for this subnet.
      java.lang.String getHighAddress()
      Gets the high address as a dotted IP address.
      java.lang.String getLowAddress()
      Gets the low address as a dotted IP address.
      java.lang.String getNetmask()
      Gets the network mask for this subnet.
      java.lang.String getNetworkAddress()
      Gets the network address for this subnet.
      java.lang.String getNextAddress()
      Gets the next address for this subnet.
      java.lang.String getPreviousAddress()
      Gets the previous address for this subnet.
      private int high()  
      boolean isInRange​(int address)
      Tests if the parameter address is in the range of usable endpoint addresses for this subnet.
      boolean isInRange​(java.lang.String address)
      Tests if the parameter address is in the range of usable endpoint addresses for this subnet.
      java.lang.Iterable<java.lang.String> iterableAddressStrings()
      Creates a new Iterable of address Strings.
      private int low()  
      private long networkLong()
      Long versions of the values (as unsigned int) which are more suitable for range checking.
      java.util.stream.Stream<java.lang.String> streamAddressStrings()
      Creates a new Stream of address Strings.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • UNSIGNED_INT_MASK

        private static final long UNSIGNED_INT_MASK
        Mask to convert unsigned int to a long (i.e. keep 32 bits).
        See Also:
        Constant Field Values
    • Constructor Detail

      • SubnetInfo

        private SubnetInfo()
    • Method Detail

      • asInteger

        public int asInteger​(java.lang.String address)
        Converts a dotted decimal format address to a packed integer format.
        Parameters:
        address - a dotted decimal format address.
        Returns:
        packed integer formatted int.
      • broadcastLong

        private long broadcastLong()
      • getAddress

        public java.lang.String getAddress()
        Gets this instance's address into a dotted decimal String.
        Returns:
        a dotted decimal String.
      • getAddressCount

        @Deprecated
        public int getAddressCount()
        Deprecated.
        (3.4) use getAddressCountLong() instead
        Gets the count of available addresses. Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
        Returns:
        the count of addresses, may be zero.
        Throws:
        java.lang.RuntimeException - if the correct count is greater than Integer.MAX_VALUE
      • getAddressCountLong

        public long getAddressCountLong()
        Gets the count of available addresses. Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
        Returns:
        the count of addresses, may be zero.
        Since:
        3.4
      • getBroadcastAddress

        public java.lang.String getBroadcastAddress()
        Gets the broadcast address for this subnet.
        Returns:
        the broadcast address for this subnet.
      • getCidrSignature

        public java.lang.String getCidrSignature()
        Gets the CIDR signature for this subnet.
        Returns:
        the CIDR signature for this subnet.
      • getHighAddress

        public java.lang.String getHighAddress()
        Gets the high address as a dotted IP address. Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
        Returns:
        the IP address in dotted format, may be "0.0.0.0" if there is no valid address
      • getLowAddress

        public java.lang.String getLowAddress()
        Gets the low address as a dotted IP address. Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
        Returns:
        the IP address in dotted format, may be "0.0.0.0" if there is no valid address
      • getNetmask

        public java.lang.String getNetmask()
        Gets the network mask for this subnet.
        Returns:
        the network mask for this subnet.
      • getNetworkAddress

        public java.lang.String getNetworkAddress()
        Gets the network address for this subnet.
        Returns:
        the network address for this subnet.
      • getNextAddress

        public java.lang.String getNextAddress()
        Gets the next address for this subnet.
        Returns:
        the next address for this subnet.
      • getPreviousAddress

        public java.lang.String getPreviousAddress()
        Gets the previous address for this subnet.
        Returns:
        the previous address for this subnet.
      • high

        private int high()
      • isInRange

        public boolean isInRange​(int address)
        Tests if the parameter address is in the range of usable endpoint addresses for this subnet. This excludes the network and broadcast addresses by default. Use SubnetUtils.setInclusiveHostCount(boolean) to change this.
        Parameters:
        address - the address to check
        Returns:
        true if it is in range
        Since:
        3.4 (made public)
      • isInRange

        public boolean isInRange​(java.lang.String address)
        Tests if the parameter address is in the range of usable endpoint addresses for this subnet. This excludes the network and broadcast addresses. Use SubnetUtils.setInclusiveHostCount(boolean) to change this.
        Parameters:
        address - A dot-delimited IPv4 address, e.g. "192.168.0.1"
        Returns:
        True if in range, false otherwise
      • iterableAddressStrings

        public java.lang.Iterable<java.lang.String> iterableAddressStrings()
        Creates a new Iterable of address Strings.
        Returns:
        a new Iterable of address Strings
        Since:
        3.12.0
        See Also:
        getAllAddresses(), streamAddressStrings()
      • low

        private int low()
      • networkLong

        private long networkLong()
        Long versions of the values (as unsigned int) which are more suitable for range checking.
      • streamAddressStrings

        public java.util.stream.Stream<java.lang.String> streamAddressStrings()
        Creates a new Stream of address Strings.
        Returns:
        a new Stream of address Strings.
        Since:
        3.12.0
        See Also:
        getAllAddresses(), iterableAddressStrings()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Since:
        2.2