public class FlagValueCalculator extends Object
Since there may be multiple overlapping regions, regions with differing priorities, regions with inheritance, flags with region groups assigned to them, and much more, the task of calculating the "effective" value of a flag is far from trivial. This class abstracts away the difficult with a number of methods for performing these calculations.
| Modifier and Type | Class and Description |
|---|---|
static class |
FlagValueCalculator.Result
Describes the membership result from
getMembership(RegionAssociable). |
| Constructor and Description |
|---|
FlagValueCalculator(List<ProtectedRegion> regions,
ProtectedRegion globalRegion)
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
<V> V |
getEffectiveFlag(ProtectedRegion region,
Flag<V> flag,
RegionAssociable subject)
Get a region's state flag, checking parent regions until a value for the
flag can be found (if one even exists).
|
FlagValueCalculator.Result |
getMembership(RegionAssociable subject)
Return the membership status of the given subject, indicating
whether there are no (counted) regions in the list of regions,
whether the subject is a member of all regions, or whether
the region is not a member of all regions.
|
int |
getPriority(ProtectedRegion region)
Get the effective priority of a region, overriding a region's priority
when appropriate (i.e.
|
<V> Collection<V> |
queryAllValues(RegionAssociable subject,
Flag<V> flag)
Get the effective values for a flag, returning a collection of all
values.
|
StateFlag.State |
queryState(RegionAssociable subject,
StateFlag... flags)
Get the effective value for a list of state flags.
|
StateFlag.State |
queryState(RegionAssociable subject,
StateFlag flag)
Get the effective value for a list of state flags.
|
<V> V |
queryValue(RegionAssociable subject,
Flag<V> flag)
Get the effective value for a flag.
|
public FlagValueCalculator(List<ProtectedRegion> regions, @Nullable ProtectedRegion globalRegion)
regions - a list of applicable regions that must be sorted according to NormativeOrdersglobalRegion - an optional global region (null to not use one)public FlagValueCalculator.Result getMembership(RegionAssociable subject)
A region is "counted" if it doesn't have the
DefaultFlag.PASSTHROUGH flag set to ALLOW. (The
explicit purpose of the PASSTHROUGH flag is to have the region
be skipped over in this check.)
This method is mostly for internal use. It's not particularly useful.
subject - the subject@Nullable public StateFlag.State queryState(@Nullable RegionAssociable subject, StateFlag... flags)
DENY overrides ALLOW,
and ALLOW overrides NONE.
A subject can be provided that is used to determine whether the value
of a flag on a particular region should be used. For example, if a
flag's region group is set to RegionGroup.MEMBERS and the given
subject is not a member, then the region would be skipped when
querying that flag. If null is provided for the subject, then
only flags that use RegionGroup.ALL,
RegionGroup.NON_MEMBERS, etc. will apply.
subject - an optional subject, which would be used to determine the region group to applyflags - a list of flags to check@Nullable public StateFlag.State queryState(@Nullable RegionAssociable subject, StateFlag flag)
DENY overrides ALLOW,
and ALLOW overrides NONE.
This method is the same as
queryState(RegionAssociable, StateFlag...).
subject - an optional subject, which would be used to determine the region group to applyflag - a flag to check@Nullable public <V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag)
Only some flag types actually have a strategy for picking the
"best value." For most types, the actual value that is chosen to be
returned is undefined (it could be any value). As of writing, the only
type of flag that can consistently return the same 'best' value is
StateFlag.
A subject can be provided that is used to determine whether the value
of a flag on a particular region should be used. For example, if a
flag's region group is set to RegionGroup.MEMBERS and the given
subject is not a member, then the region would be skipped when
querying that flag. If null is provided for the subject, then
only flags that use RegionGroup.ALL,
RegionGroup.NON_MEMBERS, etc. will apply.
subject - an optional subject, which would be used to determine the region group to applyflag - the flagnullpublic <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag<V> flag)
A subject can be provided that is used to determine whether the value
of a flag on a particular region should be used. For example, if a
flag's region group is set to RegionGroup.MEMBERS and the given
subject is not a member, then the region would be skipped when
querying that flag. If null is provided for the subject, then
only flags that use RegionGroup.ALL,
RegionGroup.NON_MEMBERS, etc. will apply.
subject - an optional subject, which would be used to determine the region group to applyflag - the flagpublic int getPriority(ProtectedRegion region)
region - the regionpublic <V> V getEffectiveFlag(ProtectedRegion region, Flag<V> flag, @Nullable RegionAssociable subject)
region - the regionflag - the flagsubject - an subject objectCopyright © 2015. All Rights Reserved.