NetMaskSet (Apache Tomcat 10.1.55 API Documentation)
Description: declaration: package: org.apache.catalina.util, class: NetMaskSet

# Class NetMaskSet

java.lang.Object
org.apache.catalina.util.NetMaskSet

public class NetMaskSet extends Object
This class maintains a Set of NetMask objects and allows to check if a given IP address is matched by any of the NetMasks, making it easy to create Allow and Deny lists of CIDR networks and hosts.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NetMaskSet()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `add(String input)`
  Creates a NetMask object from the input string and adds it to the set.
  `boolean`
  `add(NetMask netmask)`
  Adds a NetMask object to the set if the set does not contain it
  `List<String>`
  `addAll(String input)`
  Adds a `NetMask` list from a string input containing a comma-separated list of (hopefully valid) `NetMask`s.
  `void`
  `clear()`
  removes all entries from the set
  `boolean`
  `contains(String ipAddress)`
  Tests if the provided IP address matches any of the `NetMask`s in the set.
  `boolean`
  `contains(InetAddress inetAddress)`
  Tests if the provided InetAddress matches any of the `NetMask`s in the set.
  `boolean`
  `isEmpty()`
  Tests if the set is empty.
  `String`
  `toString()`
  Provides a string representation of this NetMaskSet.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### NetMaskSet

    public NetMaskSet()

- ## Method Details

  - ### contains

    public boolean contains(InetAddress inetAddress)
    Tests if the provided InetAddress matches any of the `NetMask`s in the set.
    Parameters:
      `inetAddress` - An InetAddress to check
    Returns:
      `true` if the passed inetAddress is matched by any of the `NetMask`s in the set

  - ### contains

    public boolean contains(String ipAddress) throws UnknownHostException
    Tests if the provided IP address matches any of the `NetMask`s in the set.
    Parameters:
      `ipAddress` - an IP address to check
    Returns:
      `true` if the passed IP address is matched by any of the `NetMask`s in the set
    Throws:
      `UnknownHostException` - if the passed input is not a valid IP address

  - ### add

    public boolean add(NetMask netmask)
    Adds a NetMask object to the set if the set does not contain it
    Parameters:
      `netmask` - The NetMask to add
    Returns:
      true if the object was added

  - ### add

    public boolean add(String input)
    Creates a NetMask object from the input string and adds it to the set.
    Parameters:
      `input` - The string from which to construct the NetMask
    Returns:
      true if the object was added
    Throws:
      `IllegalArgumentException` - if the input is not a valid CIDR format.

  - ### clear

    public void clear()
    removes all entries from the set

  - ### isEmpty

    public boolean isEmpty()
    Tests if the set is empty.
    Returns:
      `true` if the set is empty, otherwise `false`

  - ### addAll

    public List<String> addAll(String input)
    Adds a `NetMask` list from a string input containing a comma-separated list of (hopefully valid) `NetMask`s.
    Parameters:
      `input` - The input string
    Returns:
      a list of processing error messages (empty when no errors)

  - ### toString

    public String toString()
    Provides a string representation of this NetMaskSet. The format of the String is not guaranteed to remain fixed.
    Overrides:
      `toString` in class `Object`
    Returns:
      a comma separated list of the `NetMask`s in this set