java.lang.Object
io.smallrye.common.net.CidrAddressTable<T>
- Type Parameters:
T- the value type
- All Implemented Interfaces:
Iterable<CidrAddressTable.Mapping<T>>
public final class CidrAddressTable<T>
extends Object
implements Iterable<CidrAddressTable.Mapping<T>>
A table for mapping IP addresses to objects using
CidrAddress instances for matching.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA single mapping in the table. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Remove all mappings from this table.clone()Returns an atomic clone of this table.get(InetAddress address) Returns the value which best matches the given address, ornullif none match.getOrDefault(InetAddress address, T defVal) Returns the value which best matches the given address, ordefValif none match.booleanisEmpty()Returnstrueif the table is empty, orfalseotherwise.iterator()put(CidrAddress block, T value) Add a mapping for the given block.putIfAbsent(CidrAddress block, T value) Add a mapping for the given block if one is not already present.removeExact(CidrAddress block) Remove a mapping for a specific address block.booleanremoveExact(CidrAddress block, T expect) Remove a mapping for a specific address block if its value is the expected value.replaceExact(CidrAddress block, T value) Replace a mapping for the given block if one is already present.booleanreplaceExact(CidrAddress block, T expect, T update) Replace a mapping for the given block if one is already present with the given expected value.intsize()Returns the number of mappings in this table.toString()
-
Constructor Details
-
CidrAddressTable
public CidrAddressTable()Construct a new instance.
-
-
Method Details
-
getOrDefault
Returns the value which best matches the given address, ordefValif none match.- Parameters:
address- the address to match (must not benull)defVal- the default value to return- Returns:
- the value which best matches the given address, or
defValif none match
-
get
Returns the value which best matches the given address, ornullif none match.- Parameters:
address- the address to match (must not benull)- Returns:
- the value which best matches the given address, or
nullif none match
-
put
Add a mapping for the given block.- Parameters:
block- the address block (must not benull)value- the value for the mapping (must not benull)- Returns:
- the previous mapping, if any, or else
null
-
putIfAbsent
Add a mapping for the given block if one is not already present.- Parameters:
block- the address block (must not benull)value- the value for the mapping (must not benull)- Returns:
- the existing mapping, if any, or else
nullif the addition succeeded
-
replaceExact
Replace a mapping for the given block if one is already present.- Parameters:
block- the address block (must not benull)value- the new value for the mapping (must not benull)- Returns:
- the previous mapping, if any, or else
nullif the value was not replaced
-
replaceExact
Replace a mapping for the given block if one is already present with the given expected value.- Parameters:
block- the address block (must not benull)expect- the expected value for the mapping (must not benull)update- the new value for the mapping (must not benull)- Returns:
trueif the mapping was replaced, orfalseif it was not replaced
-
removeExact
Remove a mapping for a specific address block.- Parameters:
block- the address block (must not benull)- Returns:
- the removed mapping value, if any, or else
nullif the value was not removed
-
removeExact
Remove a mapping for a specific address block if its value is the expected value.- Parameters:
block- the address block (must not benull)expect- the expected value- Returns:
trueif the mapping was removed, orfalseif it was not removed
-
clear
public void clear()Remove all mappings from this table. -
size
public int size()Returns the number of mappings in this table.- Returns:
- the number of mappings in this table
-
isEmpty
public boolean isEmpty()Returnstrueif the table is empty, orfalseotherwise.- Returns:
trueif the table is empty, orfalseotherwise
-
clone
Returns an atomic clone of this table. -
iterator
-
spliterator
- Specified by:
spliteratorin interfaceIterable<T>
-
toString
-