Class MultiClusterContainer<T>

  • Type Parameters:
    T - value type
    All Implemented Interfaces:
    java.io.Serializable, MultiClusterSupport<T>

    public class MultiClusterContainer<T>
    extends java.lang.Object
    implements java.io.Serializable, MultiClusterSupport<T>
    A container to hold values per cluster. Each value is identified by its belonging cluster id. It is compatible with single cluster, i.e. no cluster id is defined for the value. Pass null clusterId to get the value. However, the container does not permit holding values for both multi-cluster case and single cluster case; otherwise, IllegalStateException is thrown.
    See Also:
    Serialized Form
    • Constructor Detail

      • MultiClusterContainer

        public MultiClusterContainer()
    • Method Detail

      • getValueOrNull

        @Nullable
        public T getValueOrNull​(@Nullable
                                java.lang.String clusterId)
        Description copied from interface: MultiClusterSupport
        Look up a value based on clusterId
        Specified by:
        getValueOrNull in interface MultiClusterSupport<T>
        Parameters:
        clusterId - cluster id
        Returns:
        the value of type T associated with the clusterId, or null if not found
      • getAnyValue

        @Nullable
        public T getAnyValue()
        Returns:
        any value in the container. Null is returned if the container is empty.
      • getAnyValueOrThrow

        @NotNull
        public T getAnyValueOrThrow()
                             throws java.util.NoSuchElementException
        Returns:
        any value in the container
        Throws:
        java.util.NoSuchElementException - when no value can be found
      • size

        public int size()
        Specified by:
        size in interface MultiClusterSupport<T>
        Returns:
        the total number of clusters
      • forEach

        public void forEach​(java.util.function.BiConsumer<java.lang.String,​T> action)
        Description copied from interface: MultiClusterSupport
        Iterate through all values
        Specified by:
        forEach in interface MultiClusterSupport<T>
        Parameters:
        action - function to consume the values
      • setValue

        public void setValue​(@Nullable
                             java.lang.String clusterId,
                             @NotNull
                             T value)
        Set the value for a cluster
        Parameters:
        clusterId - nullable cluster id. When the value is null, it reads from the single value
      • updateValue

        public void updateValue​(@Nullable
                                java.lang.String clusterId,
                                java.util.function.UnaryOperator<T> valueUpdater)
        Update the value associated with the clusterId
        Parameters:
        clusterId - nullable cluster id. When the value is null, it updates the single value
        valueUpdater - function to update the value; if not prior value exist, the updater receives null as input, If the updater returns null, the value associated with the cluster is removed
      • addAll

        public void addAll​(java.util.Map<java.lang.String,​T> clusters)
        Add all values from the map
        Parameters:
        clusters - map of value per cluster
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object