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 Detail

      • 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 at
        operation - 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 by mapper.
        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 from
        mapper - 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 at
        segment - 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 from other.

        This will add to existing data, rather than overwriting.

        Parameters:
        other - source to add from
        Returns:
        a modified subject data
        Since:
        2.0.0