/*
 * Copyright 2016-2018 Talsma ICT
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.talsmasoftware.context.futures;

import nl.talsmasoftware.context.ContextManagers;
import nl.talsmasoftware.context.ContextSnapshot;

import java.util.function.Consumer;
import java.util.function.Supplier;

import static java.util.Objects.requireNonNull;

final class ContextSnapshotHolder implements Consumer<ContextSnapshot>, Supplier<ContextSnapshot> {
    private volatile ContextSnapshot snapshot;

    ContextSnapshotHolder(ContextSnapshot snapshot) {
        this.accept(snapshot == null ? ContextManagers.createContextSnapshot() : snapshot);
    }

    @Override
    public void accept(ContextSnapshot snapshot) {
        this.snapshot = requireNonNull(snapshot, "Context snapshot is <null>.");
    }

    @Override
    public ContextSnapshot get() {
        return snapshot;
    }

}

@@ -867,461 +867,1370 @@
 l;%0A%0A
-final class ContextSnapshotHolder implements Consumer%3CContextSnapshot%3E, Supplier%3CContextSnapshot%3E %7B%0A    private volatile ContextSnapshot snapshot;%0A%0A    ContextSnapshotHolder(ContextSnapshot snapshot) %7B%0A        this.accept(snapshot == null ? ContextManagers.createContextSnapshot() : snapshot);%0A    %7D%0A%0A    @Override%0A    public void accept(ContextSnapshot snapshot) %7B%0A        this.snapshot = requireNonNull(snapshot, %22Context snapshot is %3Cnull%3E.%22);%0A    %7D%0A
+/**%0A * Snapshot holder that is used internally to temporarily 'hold' a context snapshot%0A * to be propagated from one %7B@code CompletionStage%7D to another.%0A *%0A * @author Sjoerd Talsma%0A */%0Afinal class ContextSnapshotHolder implements Consumer%3CContextSnapshot%3E, Supplier%3CContextSnapshot%3E %7B%0A    private volatile ContextSnapshot snapshot;%0A%0A    /**%0A     * Create a new snapshot holder initially containing either the provided snapshot,%0A     * or takes a new snapshot as initial value.%0A     *%0A     * @param snapshot The snapshot to hold initially.%0A     *                 Optional, if %7B@code null%7D the holder will initialize with a new snapshot.%0A     */%0A    ContextSnapshotHolder(ContextSnapshot snapshot) %7B%0A        this.accept(snapshot == null ? ContextManagers.createContextSnapshot() : snapshot);%0A    %7D%0A%0A    /**%0A     * Accept a new snapshot (i.e. after a single stage is completed) to be propagated%0A     * into another completion stage.%0A     *%0A     * @param snapshot The snapshot to hold (required, must not be %7B@code null%7D)%0A     */%0A    @Override%0A    public void accept(ContextSnapshot snapshot) %7B%0A        this.snapshot = requireNonNull(snapshot, %22Context snapshot is %3Cnull%3E.%22);%0A    %7D%0A%0A    /**%0A     * Returns the current snapshot, normally to activate when beginning a new completion stage.%0A     *%0A     * @return The held snapshot (should never be %7B@code null%7D)%0A     */
 %0A   

Add ContextSnapshotHolder JavaDoc