All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.ditto.edge.service.placeholders.AbstractEntityIdPlaceholder Maven / Gradle / Ivy

There is a newer version: 3.6.3
Show newest version
/*
 * Copyright (c) 2020 Contributors to the Eclipse Foundation
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.eclipse.ditto.edge.service.placeholders;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.eclipse.ditto.base.model.entity.id.NamespacedEntityId;

/**
 * Abstract base class for entity id placeholders.
 */
abstract class AbstractEntityIdPlaceholder implements EntityIdPlaceholder {

    private static final String ID_PLACEHOLDER = "id";
    private static final String NAMESPACE_PLACEHOLDER = "namespace";
    private static final String NAME_PLACEHOLDER = "name";

    private static final List SUPPORTED = Collections.unmodifiableList(
            Arrays.asList(ID_PLACEHOLDER, NAMESPACE_PLACEHOLDER, NAME_PLACEHOLDER));

    protected AbstractEntityIdPlaceholder() {
    }

    @Override
    public List getSupportedNames() {
        return SUPPORTED;
    }

    @Override
    public boolean supports(final String name) {
        return SUPPORTED.contains(name);
    }

    protected List doResolve(final T entityId, final String placeholder) {
        switch (placeholder) {
            case NAMESPACE_PLACEHOLDER:
                return Collections.singletonList(entityId.getNamespace());
            case NAME_PLACEHOLDER:
                return Collections.singletonList(entityId.getName());
            case ID_PLACEHOLDER:
                return Collections.singletonList(entityId.toString());
            default:
                return Collections.emptyList();
        }
    }

    @Override
    public String toString() {
        return getClass().getSimpleName() + "[]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy