Interface ImmutableSubjectData
-
public interface ImmutableSubjectData
The core subject data interface.This class is an immutable holder for all of a single subject's data. No inherited data is included, and no context calculations are performed when querying objects of this class.
The global context is represented by an empty set (
ContextDefinitionProvider.GLOBAL_CONTEXT), not a null value.- Since:
- 2.0.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Set<? extends Set<ContextValue<?>>>activeContexts()Gets the contexts with data set in this subject.<V> @Nullable VmapSegment(Set<ContextValue<?>> contexts, Function<Segment,V> mapper)Get a value derived from a single segment.<V> Map<Set<ContextValue<?>>,V>mapSegmentValues(Function<Segment,V> mapper)Return a map derived from all segments in this data, transformed bymapper.default ImmutableSubjectDatamergeFrom(ImmutableSubjectData other)Create a new subject data instance, applying all data fromother.Segmentsegment(Set<ContextValue<?>> contexts)Get a segment at the specified coordinates.Map<? extends Set<ContextValue<?>>,Segment>segments()Get all non-empty segments associated with this subject.ImmutableSubjectDatawithSegment(Set<ContextValue<?>> contexts, Segment segment)Make an updated subject data with the segment applied at the specified context set.ImmutableSubjectDatawithSegment(Set<ContextValue<?>> contexts, UnaryOperator<Segment> operation)Apply a transformation to the segment at the provided contexts.ImmutableSubjectDatawithSegments(BiFunction<Set<ContextValue<?>>,Segment,Segment> transformer)Apply a transformation to every segment contained in this subject.
-
-
-
Method Detail
-
segments
Map<? extends Set<ContextValue<?>>,Segment> segments()
Get all non-empty segments associated with this subject.- Returns:
- all segments
- Since:
- 2.0.0
-
withSegments
ImmutableSubjectData withSegments(BiFunction<Set<ContextValue<?>>,Segment,Segment> transformer)
Apply a transformation to every segment contained in this subject.- Parameters:
transformer- action to apply- Returns:
- the modified subject data
- Since:
- 2.0.0
-
withSegment
ImmutableSubjectData withSegment(Set<ContextValue<?>> contexts, UnaryOperator<Segment> operation)
Apply a transformation to the segment at the provided contexts.If no segment is present at
contexts, an empty segment will be used as the input value.- Parameters:
contexts- the contexts to modify atoperation- the operation to perform- Returns:
- an updated subject data
- Since:
- 2.0.0
-
mapSegmentValues
<V> Map<Set<ContextValue<?>>,V> mapSegmentValues(Function<Segment,V> mapper)
Return a map derived from all segments in this data, transformed bymapper.- Type Parameters:
V- the output value type- Parameters:
mapper- the mapper- Returns:
- the map
- Since:
- 2.0.0
-
mapSegment
<V> @Nullable V mapSegment(Set<ContextValue<?>> contexts, Function<Segment,V> mapper)
Get a value derived from a single segment.- Type Parameters:
V- the output value type- Parameters:
contexts- the contexts to query the segment frommapper- the transformation- Returns:
- the transformed value, or null if no segment was present at the context
- Since:
- 2.0.0
-
segment
Segment segment(Set<ContextValue<?>> contexts)
Get a segment at the specified coordinates.- Parameters:
contexts- the context coordinates for the segment- Returns:
- the segment at the coordinates, or an empty segment if none is present
- Since:
- 2.0.0
-
withSegment
ImmutableSubjectData withSegment(Set<ContextValue<?>> contexts, Segment segment)
Make an updated subject data with the segment applied at the specified context set.- Parameters:
contexts- contexts to set atsegment- the segment to set- Returns:
- an updated subject data
- Since:
- 2.0.0
-
activeContexts
Set<? extends Set<ContextValue<?>>> activeContexts()
Gets the contexts with data set in this subject.- Returns:
- An immutable set of all sets of contexts with data stored
- Since:
- 2.0.0
-
mergeFrom
default ImmutableSubjectData mergeFrom(ImmutableSubjectData other)
Create a new subject data instance, applying all data fromother.This will add to existing data, rather than overwriting.
- Parameters:
other- source to add from- Returns:
- a modified subject data
- Since:
- 2.0.0
-
-