PrivilegeBits implements PrivilegeConstants { @NotNull public PrivilegeBits diff(@NotNull PrivilegeBits other) { if (d instanceof ModifiableData) { ((ModifiableData) d).diff(other.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 testEmptyDiff() { PrivilegeBits.EMPTY.diff(PrivilegeBits.EMPTY); }
@Test public void testDiff() { PrivilegeBits pb = READ_NODES_PRIVILEGE_BITS; PrivilegeBits mod = PrivilegeBits.getInstance(pb); for (int i = 0; i < 100; i++) { PrivilegeBits nxt = pb.nextBits(); try { pb.diff(nxt); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { } try { pb.diff(mod); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { } PrivilegeBits before = PrivilegeBits.getInstance(mod); mod.diff(nxt); assertEquivalent(before, mod); mod.add(nxt); assertNotEquals(before, mod); mod.diff(nxt); assertEquivalent(before, mod); mod.add(nxt); PrivilegeBits tmp = PrivilegeBits.getInstance(pb); tmp.add(nxt); tmp.add(READ_NODES_PRIVILEGE_BITS); tmp.diff(tmp); assertEquivalent(PrivilegeBits.EMPTY, tmp); tmp = PrivilegeBits.getInstance(pb); tmp.add(nxt); tmp.add(READ_NODES_PRIVILEGE_BITS); tmp.diff(PrivilegeBits.getInstance(tmp)); assertEquivalent(PrivilegeBits.EMPTY, tmp); tmp = PrivilegeBits.getInstance(pb); tmp.diff(nxt); assertEquivalent(PrivilegeBits.getInstance(pb), tmp); tmp = PrivilegeBits.getInstance(nxt); tmp.add(READ_NODES_PRIVILEGE_BITS); assertTrue(tmp.includes(READ_NODES_PRIVILEGE_BITS)); assertTrue(tmp.includes(nxt)); tmp.diff(nxt); assertEquivalent(READ_NODES_PRIVILEGE_BITS, tmp); assertTrue(tmp.includes(READ_NODES_PRIVILEGE_BITS)); assertFalse(tmp.includes(nxt)); tmp = PrivilegeBits.getInstance(pb); tmp.add(READ_NODES_PRIVILEGE_BITS); PrivilegeBits tmp2 = PrivilegeBits.getInstance(pb); tmp2.add(nxt); PrivilegeBits tmp3 = PrivilegeBits.getInstance(tmp2); assertEquivalent(tmp2, tmp3); tmp.diff(tmp2); if (READ_NODES_PRIVILEGE_BITS.equals(pb)) { assertEquivalent(PrivilegeBits.EMPTY, tmp); } else { assertEquivalent(READ_NODES_PRIVILEGE_BITS, tmp); } assertEquivalent(tmp3, tmp2); pb = nxt; } }