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

org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveStatementInference Maven / Gradle / Ivy

/*
 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.model.spi;

import static java.util.Objects.requireNonNull;

import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;

/**
 * A {@link EffectiveStatementInference}s with its attached {@link EffectiveModelContext}.
 *
 * @param  constituent {@link EffectiveStatement} type
 */
@Beta
public abstract class AbstractEffectiveStatementInference>
        implements EffectiveStatementInference {
    private final @NonNull EffectiveModelContext modelContext;

    protected AbstractEffectiveStatementInference(final @NonNull EffectiveModelContext modelContext) {
        this.modelContext = requireNonNull(modelContext);
    }

    @Override
    public final EffectiveModelContext modelContext() {
        return modelContext;
    }

    @Override
    public abstract List statementPath();

    @Override
    public final String toString() {
        return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
    }

    protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
        return helper.add("modelContext", modelContext);
    }

    /**
     * A simple capture of an {@link AbstractEffectiveStatementInference} and a list of {@link EffectiveStatement}s. No
     * further guarantees are made.
     *
     * @param  constituent {@link EffectiveStatement} type
     */
    @Beta
    public abstract static class WithPath>
            extends AbstractEffectiveStatementInference {
        private final @NonNull List path;

        protected WithPath(final @NonNull EffectiveModelContext modelContext, final @NonNull ImmutableList path) {
            super(modelContext);
            this.path = requireNonNull(path);
        }

        protected WithPath(final @NonNull EffectiveModelContext modelContext, final @NonNull List path) {
            super(modelContext);
            this.path = ImmutableList.copyOf(path);
        }

        @Override
        public final List statementPath() {
            return path;
        }

        @Override
        protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
            return super.addToStringAttributes(helper).add("path", path);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy