PrivilegeBits implements PrivilegeConstants { @NotNull public PrivilegeBits retain(@NotNull PrivilegeBits other) { if (d instanceof ModifiableData) { ((ModifiableData) d).retain(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 public void testRetain() { PrivilegeBits pb = READ_NODES_PRIVILEGE_BITS; List<PrivilegeBits> pbs = new ArrayList<>(); pbs.add(pb); Random random = new Random(); for (int i = 0; i < 100; i++) { PrivilegeBits nxt = pb.nextBits(); PrivilegeBits mod = PrivilegeBits.getInstance(nxt, pb); mod.retain(nxt); assertEquivalent(nxt, mod); mod = PrivilegeBits.getInstance(nxt); mod.retain(pb); assertTrue(nxt.toString(), mod.isEmpty()); mod = PrivilegeBits.getInstance(nxt); mod.retain(READ_NODES_PRIVILEGE_BITS); assertTrue(nxt.toString(), mod.isEmpty()); mod = PrivilegeBits.getInstance(nxt, READ_NODES_PRIVILEGE_BITS); mod.retain(nxt); assertEquivalent(nxt, mod); mod = PrivilegeBits.getInstance(nxt, pb, READ_NODES_PRIVILEGE_BITS); mod.retain(READ_NODES_PRIVILEGE_BITS); assertEquivalent(READ_NODES_PRIVILEGE_BITS, mod); mod = PrivilegeBits.getInstance(nxt); PrivilegeBits other = PrivilegeBits.getInstance(); for (int j = 0; j < pbs.size()/2; j++) { other.add(pbs.get(random.nextInt(pbs.size()-1))); } mod.add(other); mod.retain(other); assertEquivalent(other, mod); other.retain(nxt); assertTrue(other.isEmpty()); pbs.add(nxt); pb = nxt; } }