Package org.protelis.lang.datatype.impl
Class LazyField<T>
- java.lang.Object
-
- org.protelis.lang.datatype.impl.AbstractField<T>
-
- org.protelis.lang.datatype.impl.LazyField<T>
-
- Type Parameters:
T
- field type
- All Implemented Interfaces:
java.io.Serializable
,Field<T>
public final class LazyField<T> extends AbstractField<T>
Lazy implementation of a Field.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.protelis.lang.datatype.Field
Field.Builder<T>
-
-
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.java.util.Optional<T>
getIfPresent(DeviceUID id)
DeviceUID
getLocalDevice()
java.lang.Iterable<? extends java.util.Map.Entry<DeviceUID,T>>
iterable()
java.lang.Iterable<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()
java.lang.Iterable<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, get, getExpectedType, getLocal, getLocalValue, isEmpty, map, projectOn, reduce, reduce, reduceKeys, reduceValues, toMap
-
-
-
-
Method Detail
-
iterable
public java.lang.Iterable<? extends java.util.Map.Entry<DeviceUID,T>> iterable()
- Returns:
- An iterator over the set of neighbor/value pairs
-
keys
public java.lang.Iterable<DeviceUID> keys()
- Returns:
- An
Iterable
for the field keys
-
keyStream
public java.util.stream.Stream<DeviceUID> keyStream()
- Returns:
- A
Stream
for the field keys
-
valueStream
public java.util.stream.Stream<T> valueStream()
- Returns:
- A
Stream
over the set of values
-
values
public java.lang.Iterable<T> values()
- Returns:
- An
Iterable
set of values
-
stream
public java.util.stream.Stream<? extends java.util.Map.Entry<DeviceUID,T>> stream()
- Returns:
- A
Stream
over the set of neighbor/value pairs
-
getIfPresent
public java.util.Optional<T> getIfPresent(@Nonnull DeviceUID id)
- Parameters:
id
- the DeviceUID- Returns:
- the associated value wrapped in an
Optional
, or anOptional.empty()
if the device is not aligned.
-
getLocalDevice
public DeviceUID getLocalDevice()
- Returns:
- the local Device
-
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
-
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
-
-