/*
 * Copyright 2019, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.server.delivery;

import io.spine.server.type.ActorMessageEnvelope;

import java.util.EnumMap;
import java.util.Map;
import java.util.Optional;

/**
 * The {@linkplain LazyEndpoint endpoints} configured as destinations for
 * a certain {@linkplain io.spine.server.delivery.InboxLabel label}.
 */
class Endpoints<I, M extends ActorMessageEnvelope<?, ?, ?>> {

    private final Map<InboxLabel, LazyEndpoint<I, M>> endpoints =
            new EnumMap<>(InboxLabel.class);

    void add(InboxLabel label, LazyEndpoint<I, M> lazyEndpoint) {
        endpoints.put(label, lazyEndpoint);
    }

    Optional<MessageEndpoint<I, M>> get(InboxLabel label, M envelope) {
        if (!endpoints.containsKey(label)) {
            return Optional.empty();
        }
        return Optional.of(endpoints.get(label)
                                    .apply(envelope));
    }

    boolean isEmpty() {
        return endpoints.isEmpty();
    }
}

@@ -1494,16 +1494,99 @@
 lass);%0A%0A
+    /**%0A     * Adds a lazy-initializable endpoint with a respective label.%0A     */%0A
     void
@@ -1690,24 +1690,199 @@
 nt);%0A    %7D%0A%0A
+    /**%0A     * Obtains the message endpoint for the given label and the envelope.%0A     *%0A     * Returns %7B@code Optional.empty()%7D if there is no such label configured.%0A     */%0A
     Optional
@@ -2139,24 +2139,92 @@
 e));%0A    %7D%0A%0A
+    /**%0A     * Tells if there are any endpoints configured.%0A     */%0A
     boolean 

Add more Javadocs.