Interface Segment


  • public interface Segment
    Subject data set for a specific configuration of properties.

    Segments are immutable, so any changes will produce a new object.

    Since:
    2.0.0
    • Method Detail

      • options

        Map<String,​Stringoptions()
        Get options registered in a single context set.
        Returns:
        the options, as an immutable map
        Since:
        2.0.0
      • withOption

        Segment withOption​(String key,
                           String value)
        Return a new segment with updated option information.
        Parameters:
        key - the key of the option to set. Must be unique.
        value - the value to set attached to the key
        Returns:
        an updated segment
        Since:
        2.0.0
      • withoutOption

        Segment withoutOption​(String key)
        Return a new segment with an option removed, if it is present
        Parameters:
        key - the key of the option to remove
        Returns:
        an updated segment, or the same segment if no such option was present
        Since:
        2.0.0
      • withOptions

        Segment withOptions​(Map<String,​String> values)
        Return a new segment with an entirely new set of options
        Parameters:
        values - the options to set
        Returns:
        an updated segment
        Since:
        2.0.0
      • withoutOptions

        default Segment withoutOptions()
        Return a new segment with all options unset.
        Returns:
        a new segment with no options information.
        Since:
        2.0.0
      • permissions

        Map<String,​Integerpermissions()
        Get permissions data for a single context in this subject.
        Returns:
        an immutable map from permission to value
        Since:
        2.0.0
      • withPermission

        Segment withPermission​(String permission,
                               int value)
        Set a single permission to a specific value.

        Values greater than zero evaluate to true, values less than zero evaluate to false, and equal to zero will unset the permission. Higher absolute values carry more weight.

        Parameters:
        permission - the permission to set
        value - the value. Zero to unset.
        Returns:
        an updated segment
        Since:
        2.0.0
      • withPermissions

        Segment withPermissions​(Map<String,​Integer> values)
        Set all permissions.
        Parameters:
        values - a map from permissions to their values
        Returns:
        an updated segment object
        Since:
        2.0.0
      • withoutPermissions

        Segment withoutPermissions()
        Return a new segment with all permissions unset.
        Returns:
        the updated segment
        Since:
        2.0.0
      • parents

        List<? extends SubjectRef<?>> parents()
        Get parents in this segment
        Returns:
        an immutable list of parents
        Since:
        2.0.0
      • plusParent

        default <I> Segment plusParent​(SubjectType<I> type,
                                       I identifier)
        Update a segment with an added parent.

        This parent will be added at the beginning of the list of parents, meaning it will have higher priority than any existing parents.

        Parameters:
        type - the type of the parent subject being added
        identifier - the identifier of the parent subject being added
        Returns:
        an updated segment
        Since:
        2.0.0
      • plusParent

        <I> Segment plusParent​(SubjectRef<I> subject)
        Update a new segment with an added parent.

        This parent will be added at the end of the list of parents, meaning it will have lower priority than any existing parents.

        Type Parameters:
        I - identifier type
        Parameters:
        subject - a reference to the subject that should be added as parent.
        Returns:
        an updated segment
        Since:
        2.0.0
      • minusParent

        default <I> Segment minusParent​(SubjectType<I> type,
                                        I identifier)
        Update a new segment to remove the passed parent.
        Parameters:
        type - the type of the parent subject being removed
        identifier - the identifier of the parent subject being removed
        Returns:
        an updated segment
        Since:
        2.0.0
      • minusParent

        <I> Segment minusParent​(SubjectRef<I> subject)
        Remove a single parent subject in this segment.
        Type Parameters:
        I - identifier type
        Parameters:
        subject - a reference to the subject that should be added as parent.
        Returns:
        an updated segment
        Since:
        2.0.0
      • withParents

        Segment withParents​(List<SubjectRef<?>> parents)
        Update a new segment with the provided parents.
        Parameters:
        parents - the parents that will be written
        Returns:
        an updated segment
        Since:
        2.0.0
      • withoutParents

        Segment withoutParents()
        Remove all parents from this segment.
        Returns:
        an updated segment
        Since:
        2.0.0
      • fallbackPermission

        int fallbackPermission()
        Get the fallback permissions value for this segment. This is the value that will be returned for permissions that do not match anything more specific.
        Returns:
        the default value in the given context set, or 0 if none is set.
        Since:
        2.0.0
      • withFallbackPermission

        Segment withFallbackPermission​(int defaultValue)
        Update a new segment with a new fallback permission.
        Parameters:
        defaultValue - the default value to apply. A default value of 0 is equivalent to unset
        Returns:
        an updated segment
        Since:
        2.0.0
      • cleared

        Segment cleared()
        Return a new segment with no data set.
        Returns:
        the cleared segment
        Since:
        2.0.0
      • empty

        boolean empty()
        Return true if this segment has no set data.
        Returns:
        if this sement is empty
        Since:
        2.0.0
      • mergeFrom

        default Segment mergeFrom​(Segment other)
        Add all data from the segment other to this one.
        Parameters:
        other - the source segment
        Returns:
        an updated segment
        Since:
        2.0.0