Populate data/ hierarchy
[yangtools.git] / yang / yang-model-spi / src / main / java / org / opendaylight / yangtools / yang / model / spi / AbstractEffectiveModelContextProvider.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.model.spi;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects;
14 import com.google.common.base.MoreObjects.ToStringHelper;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
18
19 /**
20  * Utility superclass for classes returning a constant {@link EffectiveModelContext}.
21  */
22 @Beta
23 @NonNullByDefault
24 public abstract class AbstractEffectiveModelContextProvider implements EffectiveModelContextProvider {
25     private final EffectiveModelContext modelContext;
26
27     protected AbstractEffectiveModelContextProvider(final EffectiveModelContext modelContext) {
28         this.modelContext = requireNonNull(modelContext);
29     }
30
31     @Override
32     public final EffectiveModelContext getEffectiveModelContext() {
33         return modelContext;
34     }
35
36     @Override
37     public final String toString() {
38         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
39     }
40
41     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
42         return helper.add("modelContext", modelContext);
43     }
44 }