Class IPAddressRange

java.lang.Object
org.n52.janmayen.net.IPAddressRange
All Implemented Interfaces:
com.google.common.base.Predicate<IPAddress>, Predicate<IPAddress>

public class IPAddressRange extends Object implements Predicate<IPAddress>, com.google.common.base.Predicate<IPAddress>
Representation of an IPv4 address range based on an address and a subnet mask.
  • Constructor Details

    • IPAddressRange

      public IPAddressRange(String string)
      Creates a new address range from its string representation. This can be either a CIDR or subnet notation.
      Examples:
       192.168.1.1/24
       192.168.1.1/255.255.255.0
       2001:db8:abcd:0012::0/64
       2001:db8:abcd:0012::0/ffff:ffff:ffff:ffff::
       
      Parameters:
      string - the string representation
    • IPAddressRange

      public IPAddressRange(IPAddress address, IPAddress mask)
      Creates a new address range from an address an a subnet mask.
      Parameters:
      address - the address
      mask - the subnet mask
    • IPAddressRange

      public IPAddressRange(IPAddress address, int prefix)
      Creates a new address range from the an address and an prefix.
      Parameters:
      address - the address
      prefix - the prefix
  • Method Details

    • isIPv4

      public boolean isIPv4()
      Checks if this address range is IPv4.
      Returns:
      if it is IPv4
    • isIPv6

      public boolean isIPv6()
      Checks if this address range is IPv6.
      Returns:
      if it is IPv6
    • getAddress

      public IPAddress getAddress()
      Returns:
      the IP address
    • getPrefix

      public int getPrefix()
      Returns:
      the subnet mask
    • getMask

      public IPAddress getMask()
      Get the mask described by this prefix.
      Returns:
      the mask
    • getHigh

      public IPAddress getHigh()
      Returns:
      the highest IP address in this range
    • getLow

      public IPAddress getLow()
      Returns:
      the lowest IP address in this range
    • contains

      public boolean contains(IPAddress ip)
      Checks if a given IP address is in this range.
      Parameters:
      ip - the address
      Returns:
      whether this range contains the address
    • asRange

      public com.google.common.collect.Range<IPAddress> asRange()
      Returns:
      this address range as a Range
    • apply

      @Deprecated public boolean apply(IPAddress input)
      Deprecated.
      Specified by:
      apply in interface com.google.common.base.Predicate<IPAddress>
    • test

      public boolean test(IPAddress input)
      Specified by:
      test in interface com.google.common.base.Predicate<IPAddress>
      Specified by:
      test in interface Predicate<IPAddress>
    • hashCode

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

      public boolean equals(Object obj)
      Specified by:
      equals in interface com.google.common.base.Predicate<IPAddress>
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPrefixForMask

      static int getPrefixForMask(IPAddress mask)
    • getMaskForPrefix

      static IPAddress getMaskForPrefix(int prefix, int numBits)