public AtomContext branch() { return new AtomContext(atoms); }
/** * <p> * Returns the {@link List} that backs this {@link AtomContext} object, so modifications to the list will be * reflected by this context and vice versa. {@link AtomContext} uses reference counting as an optimization, so a * call to this method might result in duplicating atoms if others currently hold a reference to them. * </p> * * @return the atoms of this {@link AtomContext} */ public List<ByteBuffer> getModifiableAtoms() { toExclusive(); return atoms(); }
@Override public AtomContext branch(AtomContext from) { return from == null ? null : from.branch(); }
public AtomContext merge(AtomContext other) { if (other == null || other.atoms == null || other.atoms.object == null) { return this; } if (atoms == null || atoms.object == null) { return this; } if (atoms.exclusive()) { atoms.object = Lexicographic.merge(atoms.object, other.atoms.object); other.discard(); return this; } if (other.atoms.exclusive()) { return other.merge(this); } List<ByteBuffer> merged = Lexicographic.merge(atoms.object, other.atoms.object); discard(); other.discard(); atoms = new RefCount<>(merged); atoms.ref(); return this; }
@Override public void discard(AtomContext baggageContext) { if (baggageContext != null) { baggageContext.discard(); } }
@Override public AtomContext join(AtomContext left, AtomContext right) { return left == null ? right : left.merge(right); }
List<ByteBuffer> atoms(AtomContext baggageContext) { return baggageContext == null ? null : baggageContext.atoms(); }
AtomContext wrap(List<ByteBuffer> atoms) { if (atoms == null || atoms.size() == 0) { return null; } else { return new AtomContext(atoms); } }