Class CidrAddressTable<T>

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.
  • Constructor Details

    • CidrAddressTable

      public CidrAddressTable()
      Construct a new instance.
  • Method Details

    • getOrDefault

      public T getOrDefault(InetAddress address, T defVal)
      Returns the value which best matches the given address, or defVal if none match.
      Parameters:
      address - the address to match (must not be null)
      defVal - the default value to return
      Returns:
      the value which best matches the given address, or defVal if none match
    • get

      public T get(InetAddress address)
      Returns the value which best matches the given address, or null if none match.
      Parameters:
      address - the address to match (must not be null)
      Returns:
      the value which best matches the given address, or null if none match
    • put

      public T put(CidrAddress block, T value)
      Add a mapping for the given block.
      Parameters:
      block - the address block (must not be null)
      value - the value for the mapping (must not be null)
      Returns:
      the previous mapping, if any, or else null
    • putIfAbsent

      public T putIfAbsent(CidrAddress block, T value)
      Add a mapping for the given block if one is not already present.
      Parameters:
      block - the address block (must not be null)
      value - the value for the mapping (must not be null)
      Returns:
      the existing mapping, if any, or else null if the addition succeeded
    • replaceExact

      public T replaceExact(CidrAddress block, T value)
      Replace a mapping for the given block if one is already present.
      Parameters:
      block - the address block (must not be null)
      value - the new value for the mapping (must not be null)
      Returns:
      the previous mapping, if any, or else null if the value was not replaced
    • replaceExact

      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 - the address block (must not be null)
      expect - the expected value for the mapping (must not be null)
      update - the new value for the mapping (must not be null)
      Returns:
      true if the mapping was replaced, or false if it was not replaced
    • removeExact

      public T removeExact(CidrAddress block)
      Remove a mapping for a specific address block.
      Parameters:
      block - the address block (must not be null)
      Returns:
      the removed mapping value, if any, or else null if the value was not removed
    • removeExact

      public boolean removeExact(CidrAddress block, T expect)
      Remove a mapping for a specific address block if its value is the expected value.
      Parameters:
      block - the address block (must not be null)
      expect - the expected value
      Returns:
      true if the mapping was removed, or false if 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()
      Returns true if the table is empty, or false otherwise.
      Returns:
      true if the table is empty, or false otherwise
    • clone

      public CidrAddressTable<T> clone()
      Returns an atomic clone of this table.
      Overrides:
      clone in class Object
      Returns:
      an atomic clone of this table
    • iterator

      public Iterator<CidrAddressTable.Mapping<T>> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • spliterator

      public Spliterator<CidrAddressTable.Mapping<T>> spliterator()
      Specified by:
      spliterator in interface Iterable<T>
    • toString

      public String toString()
      Overrides:
      toString in class Object