Skip to content

Commit

Permalink
Add accessibility state isMoreRestrictiveThan
Browse files Browse the repository at this point in the history
Added a SubtreeAccessibilityState.isMoreRestrictiveThan method that
can be used to determine whether one state is more restrictive than
another.
  • Loading branch information
dirmgr committed Oct 18, 2024
1 parent 7e722bf commit 0c84638
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ <h3>Version 7.0.2</h3>
<br><br>
</li>

<li>
Added a SubtreeAccessibilityState.isMoreRestrictiveThan method that can be used
to determine whether one state is more restrictive than another.
<br><br>
</li>

<li>
Updated the documentation to include the latest revisions of
draft-coretta-ldap-subnf-01, draft-coretta-oiddir-radit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,56 @@ public boolean isToBeDeleted()



/**
* Indicates whether this subtree accessibility state is considered more
* restrictive than the provided state. States will be considered in the
* following descending order of restrictiveness:
* <OL>
* <LI>{@code TO_BE_DELETED}</LI>
* <LI>{@code HIDDEN}</LI>
* <LI>{@code READ_ONLY_BIND_DENIED}</LI>
* <LI>{@code READ_ONLY_BIND_ALLOWED}</LI>
* <LI>{@code ACCESSIBLE}</LI>
* </OL>
*
* @param state The accessibility state to compare against this one. It
* must not be {@code null}.
*
* @return {@code true} if this state is more restrictive than the provided
* state, or {@code false} if this state is the same as or less
* restrictive than the provided state.
*/
public boolean isMoreRestrictiveThan(
@NotNull final SubtreeAccessibilityState state)
{
switch (this)
{
case TO_BE_DELETED:
return (state != SubtreeAccessibilityState.TO_BE_DELETED);

case HIDDEN:
return ((state != SubtreeAccessibilityState.TO_BE_DELETED) &&
(state != SubtreeAccessibilityState.HIDDEN));

case READ_ONLY_BIND_DENIED:
return ((state != SubtreeAccessibilityState.TO_BE_DELETED) &&
(state != SubtreeAccessibilityState.HIDDEN) &&
(state != SubtreeAccessibilityState.READ_ONLY_BIND_DENIED));

case READ_ONLY_BIND_ALLOWED:
return ((state != SubtreeAccessibilityState.TO_BE_DELETED) &&
(state != SubtreeAccessibilityState.HIDDEN) &&
(state != SubtreeAccessibilityState.READ_ONLY_BIND_DENIED) &&
(state != SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED));

case ACCESSIBLE:
default:
return false;
}
}



/**
* Retrieves the subtree accessibility state with the specified integer value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,83 @@ public void testIsStateMethods()



/**
* Tests the behavior of the {@code isMoreRestrictiveThan} method.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testIsMoreRestrictiveThan()
throws Exception
{
assertFalse(SubtreeAccessibilityState.TO_BE_DELETED.isMoreRestrictiveThan(
SubtreeAccessibilityState.TO_BE_DELETED));
assertTrue(SubtreeAccessibilityState.TO_BE_DELETED.isMoreRestrictiveThan(
SubtreeAccessibilityState.HIDDEN));
assertTrue(SubtreeAccessibilityState.TO_BE_DELETED.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED));
assertTrue(SubtreeAccessibilityState.TO_BE_DELETED.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED));
assertTrue(SubtreeAccessibilityState.TO_BE_DELETED.isMoreRestrictiveThan(
SubtreeAccessibilityState.ACCESSIBLE));

assertFalse(SubtreeAccessibilityState.HIDDEN.isMoreRestrictiveThan(
SubtreeAccessibilityState.TO_BE_DELETED));
assertFalse(SubtreeAccessibilityState.HIDDEN.isMoreRestrictiveThan(
SubtreeAccessibilityState.HIDDEN));
assertTrue(SubtreeAccessibilityState.HIDDEN.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED));
assertTrue(SubtreeAccessibilityState.HIDDEN.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED));
assertTrue(SubtreeAccessibilityState.HIDDEN.isMoreRestrictiveThan(
SubtreeAccessibilityState.ACCESSIBLE));

assertFalse(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED.isMoreRestrictiveThan(
SubtreeAccessibilityState.TO_BE_DELETED));
assertFalse(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED.isMoreRestrictiveThan(
SubtreeAccessibilityState.HIDDEN));
assertFalse(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED));
assertTrue(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED));
assertTrue(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED.isMoreRestrictiveThan(
SubtreeAccessibilityState.ACCESSIBLE));

assertFalse(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED.isMoreRestrictiveThan(
SubtreeAccessibilityState.TO_BE_DELETED));
assertFalse(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED.isMoreRestrictiveThan(
SubtreeAccessibilityState.HIDDEN));
assertFalse(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED));
assertFalse(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED));
assertTrue(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED.isMoreRestrictiveThan(
SubtreeAccessibilityState.ACCESSIBLE));

assertFalse(SubtreeAccessibilityState.ACCESSIBLE.isMoreRestrictiveThan(
SubtreeAccessibilityState.TO_BE_DELETED));
assertFalse(SubtreeAccessibilityState.ACCESSIBLE.isMoreRestrictiveThan(
SubtreeAccessibilityState.HIDDEN));
assertFalse(SubtreeAccessibilityState.ACCESSIBLE.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_DENIED));
assertFalse(SubtreeAccessibilityState.ACCESSIBLE.isMoreRestrictiveThan(
SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED));
assertFalse(SubtreeAccessibilityState.ACCESSIBLE.isMoreRestrictiveThan(
SubtreeAccessibilityState.ACCESSIBLE));
}



/**
* Tests the {@code forName} method with automated tests based on the actual
* name of the enum values.
Expand Down

0 comments on commit 0c84638

Please sign in to comment.