Class DimensionalMetricMap<T>

java.lang.Object
com.itrsgroup.collection.instr.DimensionalMetricMap<T>
Type Parameters:
T - value type

public class DimensionalMetricMap<T> extends Object
Map optimized for storing values per metric/dimension combination.

Instances are safe for use by concurrent threads. It employs a ConcurrentHashMap as the underlying storage.

  • Constructor Details

    • DimensionalMetricMap

      public DimensionalMetricMap()
  • Method Details

    • get

      public T get(String metric, Set<Dimension> dimensions)
      Get a value.
      Parameters:
      metric - metric name
      dimensions - dimensions
      Returns:
      the value if it exists, otherwise null
    • get

      public T get(String namespace, String metric, Set<Dimension> dimensions)
      Get a value.
      Parameters:
      namespace - metric namespace
      metric - metric name
      dimensions - dimensions
      Returns:
      the value if it exists, otherwise null
      Since:
      5.4.0
    • put

      public T put(String metric, Set<Dimension> dimensions, T value)
      Put a value, overwriting any existing value.
      Parameters:
      metric - metric name
      dimensions - dimensions
      value - value
      Returns:
      the previous value
    • put

      public T put(String namespace, String metric, Set<Dimension> dimensions, T value)
      Put a value, overwriting any existing value.
      Parameters:
      namespace - metric namespace
      metric - metric name
      dimensions - dimensions
      value - value
      Returns:
      the previous value
      Since:
      5.4.0
    • putIfAbsent

      public T putIfAbsent(String metric, Set<Dimension> dimensions, T value)
      Put a value only if it does not already exist.
      Parameters:
      metric - metric name
      dimensions - dimensions
      value - value to store only if there is not an existing value
      Returns:
      null if a value did not exist, otherwise the existing value
    • putIfAbsent

      public T putIfAbsent(String namespace, String metric, Set<Dimension> dimensions, T value)
      Put a value only if it does not already exist.
      Parameters:
      namespace - metric namespace
      metric - metric name
      dimensions - dimensions
      value - value to store only if there is not an existing value
      Returns:
      null if a value did not exist, otherwise the existing value
      Since:
      5.4.0
    • computeIfAbsent

      public T computeIfAbsent(String metric, Set<Dimension> dimensions, Function<Set<Dimension>,T> mappingFunction)
      Parameters:
      metric - metric name
      dimensions - dimensions
      mappingFunction - the function to compute a value
      Returns:
      the existing value if not null, otherwise the computed value
    • computeIfAbsent

      public T computeIfAbsent(String namespace, String metric, Set<Dimension> dimensions, Function<Set<Dimension>,T> mappingFunction)
      Parameters:
      namespace - metric namespace
      metric - metric name
      dimensions - dimensions
      mappingFunction - the function to compute a value
      Returns:
      the existing value if not null, otherwise the computed value
      Since:
      5.4.0
    • forEach

      public void forEach(DimensionalMetricMap.Consumer<T> consumer)
      Iterate over all entries.

      Iteration will halt if the consumer returns false for an entry.

      Parameters:
      consumer - consumer
    • forEach

      public void forEach(DimensionalMetricMap.NamespacedConsumer<T> consumer)
      Iterate over all entries.

      Iteration will halt if the consumer returns false for an entry.

      Parameters:
      consumer - consumer
      Since:
      5.4.0
    • remove

      public T remove(String metric, Set<Dimension> dimensions)
      Remove an entry from the map.
      Parameters:
      metric - metric
      dimensions - dimensions
      Returns:
      the previous value, or null if it did not exist
    • remove

      public T remove(String namespace, String metric, Set<Dimension> dimensions)
      Remove an entry from the map.
      Parameters:
      namespace - metric namespace
      metric - metric
      dimensions - dimensions
      Returns:
      the previous value, or null if it did not exist
      Since:
      5.4.0
    • clear

      public void clear()
      Clear the map.