@Test public void testGetEffectiveFlagGlobalRegionBuildAllow() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion global = mock.global(); global.setFlag(Flags.BUILD, State.ALLOW); FlagValueCalculator result = mock.getFlagCalculator(); assertThat(result.getEffectiveFlag(global, Flags.BUILD, null), equalTo(null)); }
@SuppressWarnings("unchecked") public <V> V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nullable RegionAssociable subject) { if (region == globalRegion) { if (flag == Flags.PASSTHROUGH) { State passthrough = region.getFlag(Flags.PASSTHROUGH); if (passthrough == State.DENY || passthrough != State.ALLOW && region.hasMembersOrOwners()) { return null; } else { return (V) State.ALLOW; } } else if (flag instanceof StateFlag && ((StateFlag) flag).preventsAllowOnGlobal()) { State value = region.getFlag((StateFlag) flag); return value != State.ALLOW ? (V) value : null; } } ProtectedRegion current = region; List<ProtectedRegion> seen = new ArrayList<>(); while (current != null) { seen.add(current); V value = current.getFlag(flag); if (value != null) { boolean use = true; if (flag.getRegionGroupFlag() != null) { RegionGroup group = current.getFlag(flag.getRegionGroupFlag()); if (group == null) { group = flag.getRegionGroupFlag().getDefault(); } if (group == null) { use = false; } else if (subject == null) { use = group.contains(Association.NON_MEMBER); } else if (!group.contains(subject.getAssociation(seen))) { use = false; } } if (use) { return value; } } current = current.getParent(); } return null; }
FlagValueCalculator { @SuppressWarnings("unchecked") public <V> V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nullable RegionAssociable subject) { if (region == globalRegion) { if (flag == Flags.PASSTHROUGH) { State passthrough = region.getFlag(Flags.PASSTHROUGH); if (passthrough == State.DENY || passthrough != State.ALLOW && region.hasMembersOrOwners()) { return null; } else { return (V) State.ALLOW; } } else if (flag instanceof StateFlag && ((StateFlag) flag).preventsAllowOnGlobal()) { State value = region.getFlag((StateFlag) flag); return value != State.ALLOW ? (V) value : null; } } ProtectedRegion current = region; List<ProtectedRegion> seen = new ArrayList<>(); while (current != null) { seen.add(current); V value = current.getFlag(flag); if (value != null) { boolean use = true; if (flag.getRegionGroupFlag() != null) { RegionGroup group = current.getFlag(flag.getRegionGroupFlag()); if (group == null) { group = flag.getRegionGroupFlag().getDefault(); } if (group == null) { use = false; } else if (subject == null) { use = group.contains(Association.NON_MEMBER); } else if (!group.contains(subject.getAssociation(seen))) { use = false; } } if (use) { return value; } } current = current.getParent(); } return null; } }
FlagValueCalculator { @SuppressWarnings("unchecked") public <V> V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nullable RegionAssociable subject) { if (region == globalRegion) { if (flag == Flags.PASSTHROUGH) { State passthrough = region.getFlag(Flags.PASSTHROUGH); if (passthrough == State.DENY || passthrough != State.ALLOW && region.hasMembersOrOwners()) { return null; } else { return (V) State.ALLOW; } } else if (flag instanceof StateFlag && ((StateFlag) flag).preventsAllowOnGlobal()) { State value = region.getFlag((StateFlag) flag); return value != State.ALLOW ? (V) value : null; } } ProtectedRegion current = region; List<ProtectedRegion> seen = new ArrayList<>(); while (current != null) { seen.add(current); V value = current.getFlag(flag); if (value != null) { boolean use = true; if (flag.getRegionGroupFlag() != null) { RegionGroup group = current.getFlag(flag.getRegionGroupFlag()); if (group == null) { group = flag.getRegionGroupFlag().getDefault(); } if (group == null) { use = false; } else if (subject == null) { use = group.contains(Association.NON_MEMBER); } else if (!group.contains(subject.getAssociation(seen))) { use = false; } } if (use) { return value; } } current = current.getParent(); } return null; } FlagValueCalculator(List<ProtectedRegion> regions, @Nullable ProtectedRegion globalRegion); }
FlagValueCalculator { @SuppressWarnings("unchecked") public <V> V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nullable RegionAssociable subject) { if (region == globalRegion) { if (flag == Flags.PASSTHROUGH) { State passthrough = region.getFlag(Flags.PASSTHROUGH); if (passthrough == State.DENY || passthrough != State.ALLOW && region.hasMembersOrOwners()) { return null; } else { return (V) State.ALLOW; } } else if (flag instanceof StateFlag && ((StateFlag) flag).preventsAllowOnGlobal()) { State value = region.getFlag((StateFlag) flag); return value != State.ALLOW ? (V) value : null; } } ProtectedRegion current = region; List<ProtectedRegion> seen = new ArrayList<>(); while (current != null) { seen.add(current); V value = current.getFlag(flag); if (value != null) { boolean use = true; if (flag.getRegionGroupFlag() != null) { RegionGroup group = current.getFlag(flag.getRegionGroupFlag()); if (group == null) { group = flag.getRegionGroupFlag().getDefault(); } if (group == null) { use = false; } else if (subject == null) { use = group.contains(Association.NON_MEMBER); } else if (!group.contains(subject.getAssociation(seen))) { use = false; } } if (use) { return value; } } current = current.getParent(); } return null; } FlagValueCalculator(List<ProtectedRegion> regions, @Nullable ProtectedRegion globalRegion); Result getMembership(RegionAssociable subject); @Nullable State queryState(@Nullable RegionAssociable subject, StateFlag... flags); @Nullable State queryState(@Nullable RegionAssociable subject, StateFlag flag); @Nullable V queryValue(@Nullable RegionAssociable subject, Flag<V> flag); Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag<V> flag); int getPriority(final ProtectedRegion region); @SuppressWarnings("unchecked") V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nullable RegionAssociable subject); }
FlagValueCalculator { @SuppressWarnings("unchecked") public <V> V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nullable RegionAssociable subject) { if (region == globalRegion) { if (flag == Flags.PASSTHROUGH) { State passthrough = region.getFlag(Flags.PASSTHROUGH); if (passthrough == State.DENY || passthrough != State.ALLOW && region.hasMembersOrOwners()) { return null; } else { return (V) State.ALLOW; } } else if (flag instanceof StateFlag && ((StateFlag) flag).preventsAllowOnGlobal()) { State value = region.getFlag((StateFlag) flag); return value != State.ALLOW ? (V) value : null; } } ProtectedRegion current = region; List<ProtectedRegion> seen = new ArrayList<>(); while (current != null) { seen.add(current); V value = current.getFlag(flag); if (value != null) { boolean use = true; if (flag.getRegionGroupFlag() != null) { RegionGroup group = current.getFlag(flag.getRegionGroupFlag()); if (group == null) { group = flag.getRegionGroupFlag().getDefault(); } if (group == null) { use = false; } else if (subject == null) { use = group.contains(Association.NON_MEMBER); } else if (!group.contains(subject.getAssociation(seen))) { use = false; } } if (use) { return value; } } current = current.getParent(); } return null; } FlagValueCalculator(List<ProtectedRegion> regions, @Nullable ProtectedRegion globalRegion); Result getMembership(RegionAssociable subject); @Nullable State queryState(@Nullable RegionAssociable subject, StateFlag... flags); @Nullable State queryState(@Nullable RegionAssociable subject, StateFlag flag); @Nullable V queryValue(@Nullable RegionAssociable subject, Flag<V> flag); Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag<V> flag); int getPriority(final ProtectedRegion region); @SuppressWarnings("unchecked") V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nullable RegionAssociable subject);  }