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 class
FieldMapImpl.Builder<T>
Builder for an immutable field.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(DeviceUID id)
Verifies if some device has an entry in this field.T
get(DeviceUID id)
java.util.Optional<T>
getIfPresent(DeviceUID device)
DeviceUID
getLocalDevice()
T
getLocalValue()
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()
int
size()
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: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 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
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
-
-