Package org.protelis.lang.datatype.impl
Class FieldMapImpl<T>
- java.lang.Object
-
- org.protelis.lang.datatype.impl.AbstractField<T>
-
- org.protelis.lang.datatype.impl.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 anImmutableMap.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFieldMapImpl.Builder<T>Builder for an immutable field.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(DeviceUID id)Verifies if some device has an entry in this field.Tget(DeviceUID id)java.util.Optional<T>getIfPresent(DeviceUID device)DeviceUIDgetLocalDevice()TgetLocalValue()com.google.common.collect.ImmutableSet<? extends java.util.Map.Entry<DeviceUID,T>>iterable()com.google.common.collect.ImmutableSet<DeviceUID>keys()java.util.stream.Stream<DeviceUID>keyStream()intsize()The number of neighbors in this field.java.util.stream.Stream<? extends java.util.Map.Entry<DeviceUID,T>>stream()com.google.common.collect.ImmutableMap<DeviceUID,T>toMap()com.google.common.collect.ImmutableCollection<T>values()java.util.stream.Stream<T>valueStream()-
Methods inherited from class org.protelis.lang.datatype.impl.AbstractField
equals, hashCode, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.protelis.lang.datatype.Field
foldExcludingLocal, foldExcludingLocal, foldIncludingLocal, foldIncludingLocal, foldKeysExcludingLocal, foldKeysIncludingLocal, foldValuesExcludingLocal, foldValuesIncludingLocal, getExpectedType, getLocal, isEmpty, map, projectOn, reduce, reduce, reduceKeys, reduceValues
-
-
-
-
Method Detail
-
containsKey
public boolean containsKey(DeviceUID id)
Description copied from interface:FieldVerifies 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 anOptional.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
Iterablefor the field keys
-
keyStream
public java.util.stream.Stream<DeviceUID> keyStream()
- Returns:
- A
Streamfor the field keys
-
size
public int size()
Description copied from interface:FieldThe 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
Streamover 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
Iterableset of values
-
valueStream
public java.util.stream.Stream<T> valueStream()
- Returns:
- A
Streamover the set of values
-
-