PrivilegeBits implements PrivilegeConstants { @NotNull public PrivilegeBits add(@NotNull PrivilegeBits other) { if (d instanceof ModifiableData) { ((ModifiableData) d).add(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 testEmptyAdd() { PrivilegeBits.EMPTY.add(PrivilegeBits.EMPTY); }
@Test public void testAdd() { PrivilegeBits pb = READ_NODES_PRIVILEGE_BITS; PrivilegeBits mod = PrivilegeBits.getInstance(pb); for (int i = 0; i < 100; i++) { PrivilegeBits nxt = pb.nextBits(); long before = getLongValue(mod); long nxtLong = getLongValue(nxt); mod.add(nxt); if (getLongValue(nxt) != 0) { assertEquals(before | nxtLong, getLongValue(mod)); } assertTrue(mod.includes(nxt)); PrivilegeBits tmp = PrivilegeBits.getInstance(pb); assertTrue(tmp.includes(pb)); assertFalse(tmp.includes(nxt)); if (READ_NODES_PRIVILEGE_BITS.equals(pb)) { assertTrue(tmp.includes(BUILT_IN.get(PrivilegeConstants.REP_READ_NODES))); } else { assertFalse(tmp.includes(BUILT_IN.get(PrivilegeConstants.REP_READ_NODES))); } tmp.add(nxt); assertTrue(tmp.includes(pb) && tmp.includes(nxt)); if (READ_NODES_PRIVILEGE_BITS.equals(pb)) { assertTrue(tmp.includes(READ_NODES_PRIVILEGE_BITS)); } else { assertFalse(tmp.includes(READ_NODES_PRIVILEGE_BITS)); } tmp.add(READ_NODES_PRIVILEGE_BITS); assertTrue(tmp.includes(READ_NODES_PRIVILEGE_BITS)); pb = nxt; } }
@Test(expected = UnsupportedOperationException.class) public void testAddSameToUnmodifiable() { READ_NODES_PRIVILEGE_BITS.add(READ_NODES_PRIVILEGE_BITS); }