Top Description Inners Fields Constructors Methods
io.smallrye.common.net

public final Class CidrAddressTable<T>

extends Object
implements Iterable<CidrAddressTable.Mapping<T>>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Type Parameters
<T>
the value type
Imports
java.net.Inet4Address, .InetAddress, java.util.Arrays, .Iterator, .NoSuchElementException, .Objects, .Spliterator, .Spliterators, java.util.concurrent.atomic.AtomicReference, io.smallrye.common.constraint.Assert

A table for mapping IP addresses to objects using CidrAddress instances for matching.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
CidrAddressTable.Mapping<
the value type
T
>

A single mapping in the table.

Field Summary

Modifier and TypeField and Description
private final AtomicReference<CidrAddressTable.Mapping<T>[]>
private static final CidrAddressTable.Mapping<T>[]

Constructor Summary

AccessConstructor and Description
public
CidrAddressTable()

Construct a new instance.

private

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Remove all mappings from this table.

public CidrAddressTable<T>

Returns:

an atomic clone of this table
clone
()

Overrides java.lang.Object.clone.

Returns an atomic clone of this table.

private int
doFind(CidrAddressTable.Mapping<T>[] table, byte[] bytes, int maskBits, final int scopeId)

private CidrAddressTable.Mapping<T>
doGet(CidrAddressTable.Mapping<T>[] table, byte[] bytes, final int netmaskBits, final int scopeId)

private T
doPut(final CidrAddress block, final T expect, final T update, final boolean putIfAbsent, final boolean putIfPresent)

private static <T> CidrAddressTable.Mapping<T>[]
public T

Returns:

the value which best matches the given address, or null if none match
get
(InetAddress
the address to match (must not be null)
address
)

Returns the value which best matches the given address, or null if none match.

public T

Returns:

the value which best matches the given address, or defVal if none match
getOrDefault
(InetAddress
the address to match (must not be null)
address
,
T
the default value to return
defVal
)

Returns the value which best matches the given address, or defVal if none match.

public boolean

Returns:

true if the table is empty, or false otherwise
isEmpty
()

Returns true if the table is empty, or false otherwise.

public Iterator<CidrAddressTable.Mapping<T>>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public T

Returns:

the previous mapping, if any, or else null
put
(CidrAddress
the address block (must not be null)
block
,
T
the value for the mapping (must not be null)
value
)

Add a mapping for the given block.

public T

Returns:

the existing mapping, if any, or else null if the addition succeeded
putIfAbsent
(CidrAddress
the address block (must not be null)
block
,
T
the value for the mapping (must not be null)
value
)

Add a mapping for the given block if one is not already present.

public T

Returns:

the removed mapping value, if any, or else null if the value was not removed
removeExact
(CidrAddress
the address block (must not be null)
block
)

Remove a mapping for a specific address block.

public boolean

Returns:

true if the mapping was removed, or false if it was not removed
removeExact
(CidrAddress
the address block (must not be null)
block
,
T
the expected value
expect
)

Remove a mapping for a specific address block if its value is the expected value.

public T

Returns:

the previous mapping, if any, or else null if the value was not replaced
replaceExact
(CidrAddress
the address block (must not be null)
block
,
T
the new value for the mapping (must not be null)
value
)

Replace a mapping for the given block if one is already present.

public boolean

Returns:

true if the mapping was replaced, or false if it was not replaced
replaceExact
(CidrAddress
the address block (must not be null)
block
,
T
the expected value for the mapping (must not be null)
expect
,
T
the new value for the mapping (must not be null)
update
)

Replace a mapping for the given block if one is already present with the given expected value.

public int

Returns:

the number of mappings in this table
size
()

Returns the number of mappings in this table.

public Spliterator<CidrAddressTable.Mapping<T>>
spliterator()

Overrides default java.lang.Iterable.spliterator.

Creates a Spliterator over the elements described by this Iterable.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

mappingsRefback to summary
private final AtomicReference<CidrAddressTable.Mapping<T>[]> mappingsRef
NO_MAPPINGSback to summary
private static final CidrAddressTable.Mapping<T>[] NO_MAPPINGS
Annotations
@SuppressWarnings:rawtypes

Constructor Detail

CidrAddressTableback to summary
public CidrAddressTable()

Construct a new instance.

CidrAddressTableback to summary
private CidrAddressTable(CidrAddressTable.Mapping<T>[] mappings)

Method Detail

clearback to summary
public void clear()

Remove all mappings from this table.

cloneback to summary
public CidrAddressTable<T> clone()

Overrides java.lang.Object.clone.

Returns an atomic clone of this table.

Returns:CidrAddressTable<T>

an atomic clone of this table

doFindback to summary
private int doFind(CidrAddressTable.Mapping<T>[] table, byte[] bytes, int maskBits, final int scopeId)
doGetback to summary
private CidrAddressTable.Mapping<T> doGet(CidrAddressTable.Mapping<T>[] table, byte[] bytes, final int netmaskBits, final int scopeId)
doPutback to summary
private T doPut(final CidrAddress block, final T expect, final T update, final boolean putIfAbsent, final boolean putIfPresent)
emptyback to summary
private static <T> CidrAddressTable.Mapping<T>[] empty()
Annotations
@SuppressWarnings:unchecked
getback to summary
public T get(InetAddress address)

Returns the value which best matches the given address, or null if none match.

Parameters
address:InetAddress

the address to match (must not be null)

Returns:T

the value which best matches the given address, or null if none match

getOrDefaultback to summary
public T getOrDefault(InetAddress address, T defVal)

Returns the value which best matches the given address, or defVal if none match.

Parameters
address:InetAddress

the address to match (must not be null)

defVal:T

the default value to return

Returns:T

the value which best matches the given address, or defVal if none match

isEmptyback to summary
public boolean isEmpty()

Returns true if the table is empty, or false otherwise.

Returns:boolean

true if the table is empty, or false otherwise

iteratorback to summary
public Iterator<CidrAddressTable.Mapping<T>> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<CidrAddressTable.Mapping<T>>

an Iterator.

putback to summary
public T put(CidrAddress block, T value)

Add a mapping for the given block.

Parameters
block:CidrAddress

the address block (must not be null)

value:T

the value for the mapping (must not be null)

Returns:T

the previous mapping, if any, or else null

putIfAbsentback to summary
public T putIfAbsent(CidrAddress block, T value)

Add a mapping for the given block if one is not already present.

Parameters
block:CidrAddress

the address block (must not be null)

value:T

the value for the mapping (must not be null)

Returns:T

the existing mapping, if any, or else null if the addition succeeded

removeExactback to summary
public T removeExact(CidrAddress block)

Remove a mapping for a specific address block.

Parameters
block:CidrAddress

the address block (must not be null)

Returns:T

the removed mapping value, if any, or else null if the value was not removed

removeExactback to summary
public boolean removeExact(CidrAddress block, T expect)

Remove a mapping for a specific address block if its value is the expected value.

Parameters
block:CidrAddress

the address block (must not be null)

expect:T

the expected value

Returns:boolean

true if the mapping was removed, or false if it was not removed

replaceExactback to summary
public T replaceExact(CidrAddress block, T value)

Replace a mapping for the given block if one is already present.

Parameters
block:CidrAddress

the address block (must not be null)

value:T

the new value for the mapping (must not be null)

Returns:T

the previous mapping, if any, or else null if the value was not replaced

replaceExactback to summary
public boolean replaceExact(CidrAddress block, T expect, T update)

Replace a mapping for the given block if one is already present with the given expected value.

Parameters
block:CidrAddress

the address block (must not be null)

expect:T

the expected value for the mapping (must not be null)

update:T

the new value for the mapping (must not be null)

Returns:boolean

true if the mapping was replaced, or false if it was not replaced

sizeback to summary
public int size()

Returns the number of mappings in this table.

Returns:int

the number of mappings in this table

spliteratorback to summary
public Spliterator<CidrAddressTable.Mapping<T>> spliterator()

Overrides default java.lang.Iterable.spliterator.

Doc from java.lang.Iterable.spliterator.

Creates a Spliterator over the elements described by this Iterable.

Returns:Spliterator<CidrAddressTable.Mapping<T>>

a Spliterator over the elements described by this Iterable.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

io.smallrye.common.net back to summary

public final Class CidrAddressTable.Mapping<T>

extends Object
Class Inheritance
Type Parameters
<T>
the value type

A single mapping in the table.

Field Summary

Modifier and TypeField and Description
pack-priv final CidrAddressTable.Mapping<T>
pack-priv final CidrAddress
pack-priv final T

Constructor Summary

AccessConstructor and Description
pack-priv
Mapping(final CidrAddress range, final T value, final CidrAddressTable.Mapping<T> parent)

Method Summary

Modifier and TypeMethod and Description
public CidrAddressTable.Mapping<T>

Returns:

the parent of this entry, or null if there is no parent
getParent
()

Get the parent of this entry, if any.

public CidrAddress

Returns:

the address range of this entry (not null)
getRange
()

Get the address range of this entry.

public T

Returns:

the stored value of this entry
getValue
()

Get the stored value of this entry.

pack-priv CidrAddressTable.Mapping<T>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

parentback to summary
pack-priv final CidrAddressTable.Mapping<T> parent
rangeback to summary
pack-priv final CidrAddress range
valueback to summary
pack-priv final T value

Constructor Detail

Mappingback to summary
pack-priv Mapping(final CidrAddress range, final T value, final CidrAddressTable.Mapping<T> parent)

Method Detail

getParentback to summary
public CidrAddressTable.Mapping<T> getParent()

Get the parent of this entry, if any.

Returns:CidrAddressTable.Mapping<T>

the parent of this entry, or null if there is no parent

getRangeback to summary
public CidrAddress getRange()

Get the address range of this entry.

Returns:CidrAddress

the address range of this entry (not null)

getValueback to summary
public T getValue()

Get the stored value of this entry.

Returns:T

the stored value of this entry

withNewParentback to summary
pack-priv CidrAddressTable.Mapping<T> withNewParent(CidrAddressTable.Mapping<T> newParent)