From: Robert Varga Date: Mon, 17 Jan 2022 17:10:34 +0000 (+0100) Subject: Disconnect StatementSupportBundle.Builder from concepts X-Git-Tag: v8.0.0~78 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=yangtools.git;a=commitdiff_plain;h=0ba2da0ea0214fb246b14dfe7b48bf3234a9e57a Disconnect StatementSupportBundle.Builder from concepts concepts.Builder is going away, disconnect it from StatementSupportBundle. JIRA: YANGTOOLS-1327 Change-Id: I465b1b39b43281dbf4f1ab479036c4cb04a7c2f5 Signed-off-by: Robert Varga --- diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java index a78dd72795..8e74f508e5 100644 --- a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java +++ b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java @@ -11,7 +11,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; -import com.google.common.base.Preconditions; import com.google.common.collect.HashBasedTable; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -20,7 +19,9 @@ import com.google.common.collect.Table; import java.util.HashMap; import java.util.Map; import java.util.Set; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.Immutable; +import org.opendaylight.yangtools.concepts.Mutable; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.YangVersion; import org.slf4j.Logger; @@ -44,9 +45,9 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio final ImmutableTable> versionSpecificStatements) { this.parent = parent; this.supportedVersions = supportedVersions; - this.commonDefinitions = commonStatements; - this.namespaceDefinitions = namespaces; - this.versionSpecificDefinitions = versionSpecificStatements; + commonDefinitions = commonStatements; + namespaceDefinitions = namespaces; + versionSpecificDefinitions = versionSpecificStatements; } /** @@ -158,12 +159,12 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio return null; } - public static class Builder implements org.opendaylight.yangtools.concepts.Builder { + public static final class Builder implements Mutable { private static final Logger LOG = LoggerFactory.getLogger(Builder.class); private final Map> commonStatements = new HashMap<>(); - private final Table> versionSpecificStatements = HashBasedTable - .create(); + private final Table> versionSpecificStatements = + HashBasedTable.create(); private final Map, NamespaceBehaviour> namespaces = new HashMap<>(); private final ImmutableSet supportedVersions; @@ -174,7 +175,7 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio this.supportedVersions = ImmutableSet.copyOf(supportedVersions); } - public Builder addSupport(final StatementSupport support) { + public @NonNull Builder addSupport(final StatementSupport support) { final QName identifier = support.getStatementName(); checkNoParentDefinition(identifier); @@ -184,7 +185,7 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio return this; } - public > Builder addSupport( + public > @NonNull Builder addSupport( final NamespaceBehaviour namespaceSupport) { final Class identifier = namespaceSupport.getIdentifier(); checkState(!namespaces.containsKey(identifier)); @@ -193,7 +194,7 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio return this; } - public Builder addVersionSpecificSupport(final YangVersion version, + public @NonNull Builder addVersionSpecificSupport(final YangVersion version, final StatementSupport definition) { checkArgument(supportedVersions.contains(requireNonNull(version))); @@ -213,12 +214,12 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio return supportedVersions; } - public Builder setParent(final StatementSupportBundle parent) { + public @NonNull Builder setParent(final StatementSupportBundle parent) { this.parent = parent; return this; } - public Builder overrideSupport(final StatementSupport support) { + public @NonNull Builder overrideSupport(final StatementSupport support) { final QName identifier = support.getStatementName(); checkNoParentDefinition(identifier); @@ -228,9 +229,14 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio return this; } - @Override - public StatementSupportBundle build() { - Preconditions.checkState(parent != null, "Parent must not be null"); + /** + * Create a {@link StatementSupportBundle} from the contents of this builder. + * + * @return A StatementSupportBundle + * @throws IllegalStateException if parent has not been set + */ + public @NonNull StatementSupportBundle build() { + checkState(parent != null, "Parent must not be null"); return new StatementSupportBundle(parent, supportedVersions, ImmutableMap.copyOf(commonStatements), ImmutableMap.copyOf(namespaces), ImmutableTable.copyOf(versionSpecificStatements)); }