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
-
-
Field Summary
Fields Modifier and Type Field Description static intPERMISSION_UNSET
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Segmentcleared()Return a new segment with no data set.booleanempty()Returntrueif this segment has no set data.intfallbackPermission()Get the fallback permissions value for this segment.default SegmentmergeFrom(Segment other)Add all data from the segmentotherto this one.<I> SegmentminusParent(SubjectRef<I> subject)Remove a single parent subject in this segment.default <I> SegmentminusParent(SubjectType<I> type, I identifier)Update a new segment to remove the passed parent.Map<String,String>options()Get options registered in a single context set.List<? extends SubjectRef<?>>parents()Get parents in this segmentMap<String,Integer>permissions()Get permissions data for a single context in this subject.<I> SegmentplusParent(SubjectRef<I> subject)Update a new segment with an added parent.default <I> SegmentplusParent(SubjectType<I> type, I identifier)Update a segment with an added parent.SegmentwithFallbackPermission(int defaultValue)Update a new segment with a new fallback permission.SegmentwithOption(String key, String value)Return a new segment with updated option information.SegmentwithOptions(Map<String,String> values)Return a new segment with an entirely new set of optionsSegmentwithoutOption(String key)Return a new segment with an option removed, if it is presentdefault SegmentwithoutOptions()Return a new segment with all options unset.SegmentwithoutParents()Remove all parents from this segment.SegmentwithoutPermissions()Return a new segment with all permissions unset.SegmentwithParents(List<SubjectRef<?>> parents)Update a new segment with the providedparents.SegmentwithPermission(String permission, int value)Set a single permission to a specific value.SegmentwithPermissions(Map<String,Integer> values)Set all permissions.
-
-
-
Field Detail
-
PERMISSION_UNSET
static final int PERMISSION_UNSET
- See Also:
- Constant Field Values
-
-
Method Detail
-
options
Map<String,String> options()
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,Integer> permissions()
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 setvalue- 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 addedidentifier- 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 removedidentifier- 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 providedparents.- 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()
Returntrueif this segment has no set data.- Returns:
- if this sement is empty
- Since:
- 2.0.0
-
-