Class FieldMapImpl<T>

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

    public final class FieldMapImpl<T>
    extends AbstractField<T>
    Field implementation based on neighbor/value pairs stored in an ImmutableMap.
    See Also:
    Serialized Form
    • Method Detail

      • containsKey

        public boolean containsKey​(DeviceUID id)
        Description copied from interface: Field
        Verifies if some device has an entry in this field. Note to interface implementors: the default version of this method is not optimized for performance and should be overridden.
        Parameters:
        id - a device UID
        Returns:
        true if there is an entry in this field for the device
      • getLocalDevice

        public DeviceUID getLocalDevice()
        Returns:
        the local Device
      • get

        public T get​(@Nonnull
                     DeviceUID id)
        Parameters:
        id - the DeviceUID
        Returns:
        the associated value
      • getIfPresent

        public java.util.Optional<T> getIfPresent​(@Nonnull
                                                  DeviceUID device)
        Parameters:
        device - the DeviceUID
        Returns:
        the associated value wrapped in an Optional, or an Optional.empty() if the device is not aligned.
      • getLocalValue

        public T getLocalValue()
        Returns:
        the value associated with the local device
      • iterable

        public com.google.common.collect.ImmutableSet<? extends java.util.Map.Entry<DeviceUID,​T>> iterable()
        Returns:
        An iterator over the set of neighbor/value pairs
      • keys

        public com.google.common.collect.ImmutableSet<DeviceUID> keys()
        Returns:
        An Iterable for the field keys
      • keyStream

        public java.util.stream.Stream<DeviceUID> keyStream()
        Returns:
        A Stream for the field keys
      • size

        public int size()
        Description copied from interface: Field
        The number of neighbors in this field. Hence, a field that only contains the local value has size 0. Note to Field implementors: the default implementation is inefficient and should be overridden.
        Returns:
        Number of neighbors with values in the field
      • stream

        public java.util.stream.Stream<? extends java.util.Map.Entry<DeviceUID,​T>> stream()
        Returns:
        A Stream over the set of neighbor/value pairs
      • toMap

        public com.google.common.collect.ImmutableMap<DeviceUID,​T> toMap()
        Returns:
        a map version of the field. The map must not return a mutable view, namely, changes to this map must not affect the field.
      • values

        public com.google.common.collect.ImmutableCollection<T> values()
        Returns:
        An Iterable set of values
      • valueStream

        public java.util.stream.Stream<T> valueStream()
        Returns:
        A Stream over the set of values