PrivilegeBits implements PrivilegeConstants { @NotNull public PrivilegeBits addDifference(@NotNull PrivilegeBits a, @NotNull PrivilegeBits b) { if (d instanceof ModifiableData) { ((ModifiableData) d).addDifference(a.d, b.d); return this; } else { throw unsupported(); } } private  PrivilegeBits(Data d); static PrivilegeBits getInstance(); @NotNull static PrivilegeBits getInstance(@NotNull PrivilegeBits... base); @NotNull static PrivilegeBits getInstance(@Nullable PropertyState property); @NotNull static PrivilegeBits getInstance(@Nullable Tree tree); static long calculatePermissions(@NotNull PrivilegeBits bits,
                                            @NotNull PrivilegeBits parentBits,
                                            boolean isAllow); boolean isEmpty(); @NotNull PrivilegeBits unmodifiable(); @NotNull PrivilegeBits modifiable(); boolean includes(@NotNull PrivilegeBits otherBits); boolean isBuiltin(); @NotNull PrivilegeBits add(@NotNull PrivilegeBits other); @NotNull PrivilegeBits diff(@NotNull PrivilegeBits other); @NotNull PrivilegeBits addDifference(@NotNull PrivilegeBits a, @NotNull PrivilegeBits b); @NotNull PrivilegeBits retain(@NotNull PrivilegeBits other); @NotNull PropertyState asPropertyState(@NotNull String name); @NotNull PrivilegeBits nextBits(); void writeTo(@NotNull Tree tree); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); static final PrivilegeBits EMPTY; static final Map<String, PrivilegeBits> BUILT_IN; static final PrivilegeBits NEXT_AFTER_BUILT_INS; }
@Test(expected = UnsupportedOperationException.class) public void testEmptyAddDifference() { PrivilegeBits.EMPTY.addDifference(PrivilegeBits.EMPTY, PrivilegeBits.EMPTY); }
@Test public void testAddDifference() { PrivilegeBits pb = READ_NODES_PRIVILEGE_BITS; PrivilegeBits mod = PrivilegeBits.getInstance(pb); for (int i = 0; i < 100; i++) { PrivilegeBits nxt = pb.nextBits(); try { pb.addDifference(nxt, mod); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { } try { pb.addDifference(nxt, READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { } PrivilegeBits tmp = PrivilegeBits.getInstance(mod); tmp.addDifference(nxt, READ_NODES_PRIVILEGE_BITS); mod.add(nxt); assertEquivalent(mod, tmp); if (!pb.equals(READ_NODES_PRIVILEGE_BITS)) { tmp = PrivilegeBits.getInstance(nxt); PrivilegeBits mod2 = PrivilegeBits.getInstance(mod); tmp.addDifference(mod2, READ_NODES_PRIVILEGE_BITS); assertNotEquals(nxt, tmp); assertEquivalent(mod2, mod); assertTrue(tmp.includes(pb)); assertFalse(tmp.includes(READ_NODES_PRIVILEGE_BITS)); assertFalse(tmp.includes(mod)); } tmp = PrivilegeBits.getInstance(nxt); PrivilegeBits mod2 = PrivilegeBits.getInstance(mod); tmp.addDifference(READ_NODES_PRIVILEGE_BITS, mod2); assertEquivalent(nxt, tmp); assertEquivalent(mod2, mod); assertFalse(tmp.includes(pb)); assertFalse(tmp.includes(READ_NODES_PRIVILEGE_BITS)); assertFalse(tmp.includes(mod)); tmp = PrivilegeBits.getInstance(nxt); tmp.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); assertEquivalent(nxt, tmp); assertFalse(tmp.includes(READ_NODES_PRIVILEGE_BITS)); tmp = PrivilegeBits.getInstance(mod); tmp.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); assertEquivalent(mod, tmp); assertTrue(tmp.includes(READ_NODES_PRIVILEGE_BITS)); pb = nxt; } }