Top Description Fields Constructors Methods
org.apache.catalina.util

public Class NetMaskSet

extends Object
Class Inheritance
Imports
java.net.InetAddress, .UnknownHostException, java.util.ArrayList, .Collections, .HashSet, .List, .Set

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.

Field Summary

Modifier and TypeField and Description
private final Set<NetMask>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the object was added
add
(NetMask
The NetMask to add
netmask
)

Adds a NetMask object to the set if the set does not contain it

public boolean

Returns:

true if the object was added
add
(String
The string from which to construct the NetMask
input
)

Creates a NetMask object from the input string and adds it to the set.

public List<String>

Returns:

a list of processing error messages (empty when no errors)
addAll
(String
The input string
input
)

Adds a NetMask list from a string input containing a comma-separated list of (hopefully valid) NetMasks.

public void
clear()

removes all entries from the set

public boolean

Returns:

true if the passed inetAddress is matched by any of the NetMasks in the set
contains
(InetAddress
An InetAddress to check
inetAddress
)

Tests if the provided InetAddress matches any of the NetMasks in the set.

public boolean

Returns:

true if the passed IP address is matched by any of the NetMasks in the set
contains
(String
an IP address to check
ipAddress
)

Tests if the provided IP address matches any of the NetMasks in the set.

public boolean

Returns:

true if the set is empty, otherwise false
isEmpty
()

Tests if the set is empty.

public String

Returns:

a comma separated list of the NetMasks in this set
toString
()

Overrides java.lang.Object.toString.

Provides a string representation of this NetMaskSet.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

netmasksback to summary
private final Set<NetMask> netmasks

Constructor Detail

NetMaskSetback to summary
public NetMaskSet()

Method Detail

addback to summary
public boolean add(NetMask netmask)

Adds a NetMask object to the set if the set does not contain it

Parameters
netmask:NetMask

The NetMask to add

Returns:boolean

true if the object was added

addback to summary
public boolean add(String input)

Creates a NetMask object from the input string and adds it to the set.

Parameters
input:String

The string from which to construct the NetMask

Returns:boolean

true if the object was added

Exceptions
IllegalArgumentException:
if the input is not a valid CIDR format.
addAllback to summary
public List<String> addAll(String input)

Adds a NetMask list from a string input containing a comma-separated list of (hopefully valid) NetMasks.

Parameters
input:String

The input string

Returns:List<String>

a list of processing error messages (empty when no errors)

clearback to summary
public void clear()

removes all entries from the set

containsback to summary
public boolean contains(InetAddress inetAddress)

Tests if the provided InetAddress matches any of the NetMasks in the set.

Parameters
inetAddress:InetAddress

An InetAddress to check

Returns:boolean

true if the passed inetAddress is matched by any of the NetMasks in the set

containsback to summary
public boolean contains(String ipAddress) throws UnknownHostException

Tests if the provided IP address matches any of the NetMasks in the set.

Parameters
ipAddress:String

an IP address to check

Returns:boolean

true if the passed IP address is matched by any of the NetMasks in the set

Exceptions
UnknownHostException:
if the passed input is not a valid IP address
isEmptyback to summary
public boolean isEmpty()

Tests if the set is empty.

Returns:boolean

true if the set is empty, otherwise false

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Provides a string representation of this NetMaskSet. The format of the String is not guaranteed to remain fixed.

Returns:String

a comma separated list of the NetMasks in this set

Annotations
@Override