Remove remaining concepts.(Checked)Builder references 56/98756/11
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Tue, 30 Nov 2021 10:53:40 +0000 (11:53 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 17 Jan 2022 12:56:13 +0000 (13:56 +0100)
To complete elimination of concepts.(Checked)Builder usage
we have to remove references from manually created Builder
classes and Types.java as well.

JIRA: MDSAL-690
Change-Id: I4a4129bf006d99cf430af6c4d08234208b6620d4
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/query/StructuralBuilder.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AdapterBuilder.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/query/SimpleQueryExecutor.java
binding/mdsal-binding-model-api/src/main/java/org/opendaylight/mdsal/binding/model/api/type/builder/AnnotationTypeBuilder.java
binding/mdsal-binding-model-api/src/main/java/org/opendaylight/mdsal/binding/model/api/type/builder/GeneratedTOBuilder.java
binding/mdsal-binding-model-api/src/main/java/org/opendaylight/mdsal/binding/model/api/type/builder/GeneratedTypeBuilder.java
binding/mdsal-binding-model-ri/src/main/java/org/opendaylight/mdsal/binding/model/ri/Types.java
binding/mdsal-binding-runtime-spi/src/main/java/org/opendaylight/mdsal/binding/runtime/spi/ModuleInfoSnapshotBuilder.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifier.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/BindingMap.java

index eb62b2329dc0437924b5bdc4ac3ab46595710b9b..be677bb7a688f6ff3f4c4bd82ec22752b8b499a7 100644 (file)
@@ -8,14 +8,21 @@
 package org.opendaylight.mdsal.binding.api.query;
 
 import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.concepts.CheckedBuilder;
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
- * A specialization of {@link CheckedBuilder}, whose {@code build()} method throws a {@link QueryStructureException}.
+ * Builder object which {@code build()} method produces a product or throws {@link QueryStructureException}.
  *
  * @param <P> Product of builder
  */
 @Beta
-public interface StructuralBuilder<P> extends CheckedBuilder<P, QueryStructureException> {
-
+public interface StructuralBuilder<P> {
+    /**
+     * Returns instance of the product. Multiple calls to this method are not required to return same instance if
+     * the state of the builder has changed.
+     *
+     * @return A newly-built instance
+     * @throws QueryStructureException if the builder's state is not sufficiently initialized
+     */
+    @NonNull P build() throws QueryStructureException;
 }
index ef6f035994d8a2042ecb98e3d1ebc94653652b61..47e27f0198376e20ee8f2d159721db14a520fdfc 100644 (file)
@@ -7,15 +7,15 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.collect.MutableClassToInstanceMap;
 import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Builder;
 
-public abstract class AdapterBuilder<T,D> implements Builder<T> {
+public abstract class AdapterBuilder<T, D> {
 
     private final ClassToInstanceMap<D> delegates = MutableClassToInstanceMap.create();
 
@@ -25,7 +25,7 @@ public abstract class AdapterBuilder<T,D> implements Builder<T> {
 
     private void checkAllRequiredServices() {
         for (final Class<? extends D> type : getRequiredDelegates()) {
-            Preconditions.checkState(delegates.get(type) != null, "Requires service %s is not defined.",type);
+            checkState(delegates.get(type) != null, "Requires service %s is not defined.", type);
         }
     }
 
@@ -33,10 +33,14 @@ public abstract class AdapterBuilder<T,D> implements Builder<T> {
         delegates.put(type,impl);
     }
 
-    @Override
-    public final  T build() {
+    /**
+     * Check that all required {@code delegates} are present and return an instance of type {@code T}.
+     *
+     * @return Instance of {@code T}
+     * @throws IllegalStateException if a required delegate instance is missing
+     */
+    public final @NonNull T build() {
         checkAllRequiredServices();
         return createInstance(ImmutableClassToInstanceMap.copyOf(delegates));
     }
-
 }
index c19d493b56af10b718589ffff3b2540a2788d80e..5f85ed9b00ccc7eb5401a7d6e8f9400ba8ad605d 100644 (file)
@@ -50,7 +50,7 @@ public final class SimpleQueryExecutor implements QueryExecutor {
         return new Builder(codec);
     }
 
-    public static final class Builder implements org.opendaylight.yangtools.concepts.Builder<SimpleQueryExecutor> {
+    public static final class Builder {
         private final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> rootBuilder = Builders.containerBuilder()
             .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME));
         private final BindingCodecTree codec;
@@ -67,8 +67,12 @@ public final class SimpleQueryExecutor implements QueryExecutor {
             return this;
         }
 
-        @Override
-        public SimpleQueryExecutor build() {
+        /**
+         * Build an instance of {@link SimpleQueryExecutor}.
+         *
+         * @return An {@link SimpleQueryExecutor} instance
+         */
+        public @NonNull SimpleQueryExecutor build() {
             return new SimpleQueryExecutor(rootBuilder.build());
         }
     }
index 3a5e4b6cd4cf7a1c98ceba766d3691e89c8a1839..a8c7205db8f9331b7fec3765ea3b1a2c962b65c2 100644 (file)
@@ -8,9 +8,9 @@
 package org.opendaylight.mdsal.binding.model.api.type.builder;
 
 import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.model.api.AnnotationType;
 import org.opendaylight.mdsal.binding.model.api.Type;
-import org.opendaylight.yangtools.concepts.Builder;
 
 /**
  * Annotation Type Builder Interface serves for creation and instantiation of
@@ -21,7 +21,7 @@ import org.opendaylight.yangtools.concepts.Builder;
  *
  * @see AnnotationType
  */
-public interface AnnotationTypeBuilder extends Type, Builder<AnnotationType> {
+public interface AnnotationTypeBuilder extends Type {
     /**
      * The method creates new AnnotationTypeBuilder containing specified package
      * name an annotation name. <br>
@@ -33,7 +33,7 @@ public interface AnnotationTypeBuilder extends Type, Builder<AnnotationType> {
      * @param name Name of Annotation Type
      * @return <code>new</code> instance of Annotation Type Builder.
      */
-    AnnotationTypeBuilder addAnnotation(String packageName, String name);
+    @NonNull AnnotationTypeBuilder addAnnotation(String packageName, String name);
 
     /**
      * Adds the parameter into List of parameters for Annotation Type. <br>
@@ -76,6 +76,5 @@ public interface AnnotationTypeBuilder extends Type, Builder<AnnotationType> {
      *
      * @return <code>new</code> <i>immutable</i> instance of Annotation Type.
      */
-    @Override
-    AnnotationType build();
+    @NonNull AnnotationType build();
 }
index b032d16f1fa1bb04b697641022b2cde8821bf351..38097e1f303344489a932cd317825b95db80d8c2 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.mdsal.binding.model.api.type.builder;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
 import org.opendaylight.mdsal.binding.model.api.Restrictions;
-import org.opendaylight.yangtools.concepts.Builder;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
 /**
@@ -18,8 +18,7 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
  *
  * @see GeneratedTransferObject
  */
-public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase<GeneratedTOBuilder>,
-        Builder<GeneratedTransferObject> {
+public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase<GeneratedTOBuilder> {
 
     /**
      * Add Generated Transfer Object from which will be extended current Generated Transfer Object.<br>
@@ -70,8 +69,7 @@ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase<GeneratedTO
      *
      * @return generated transfer object instance
      */
-    @Override
-    GeneratedTransferObject build();
+    @NonNull GeneratedTransferObject build();
 
     void setTypedef(boolean isTypedef);
 
index 2b993069f573d4c9f4bb279080ad3c24b3295cec..43511292789154a2c94b3ad6cfa60bed1d84431b 100644 (file)
@@ -7,8 +7,8 @@
  */
 package org.opendaylight.mdsal.binding.model.api.type.builder;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.yangtools.concepts.Builder;
 
 /**
  * Generated Type Builder interface is helper interface for building and
@@ -16,14 +16,11 @@ import org.opendaylight.yangtools.concepts.Builder;
  *
  * @see GeneratedType
  */
-public interface GeneratedTypeBuilder extends GeneratedTypeBuilderBase<GeneratedTypeBuilder>, Builder<GeneratedType> {
-
+public interface GeneratedTypeBuilder extends GeneratedTypeBuilderBase<GeneratedTypeBuilder> {
     /**
      * Returns the <code>new</code> <i>immutable</i> instance of Generated Type.
      *
      * @return the <code>new</code> <i>immutable</i> instance of Generated Type.
      */
-    @Override
-    GeneratedType build();
-
+    @NonNull GeneratedType build();
 }
index 186582d60b8fbd4707ef93302783acccc53c95ad..132de64d03f1ea56f1e9488b436befc5d7bd47ef 100644 (file)
@@ -35,7 +35,6 @@ import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
 import org.opendaylight.mdsal.binding.model.api.Restrictions;
 import org.opendaylight.mdsal.binding.model.api.Type;
 import org.opendaylight.mdsal.binding.model.api.WildcardType;
-import org.opendaylight.yangtools.concepts.Builder;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
@@ -56,7 +55,6 @@ public final class Types {
     public static final @NonNull ConcreteType STRING = typeForClass(String.class);
     public static final @NonNull ConcreteType VOID = typeForClass(Void.class);
 
-    private static final @NonNull ConcreteType BUILDER = typeForClass(Builder.class);
     private static final @NonNull ConcreteType LIST_TYPE = typeForClass(List.class);
     private static final @NonNull ConcreteType LISTENABLE_FUTURE = typeForClass(ListenableFuture.class);
     private static final @NonNull ConcreteType MAP_TYPE = typeForClass(Map.class);
@@ -235,17 +233,6 @@ public final class Types {
         return parameterizedTypeFor(LISTENABLE_FUTURE, valueType);
     }
 
-    /**
-     * Returns an instance of {@link ParameterizedType} describing the typed
-     * {@link Builder}&lt;V&gt; with concrete type of value.
-     *
-     * @param valueType Value Type
-     * @return Description of type instance of Builder
-     */
-    public static @NonNull ParameterizedType builderTypeFor(final Type valueType) {
-        return parameterizedTypeFor(BUILDER, valueType);
-    }
-
     /**
      * Creates instance of type {@link org.opendaylight.mdsal.binding.model.api.ParameterizedType ParameterizedType}.
      *
index 2c5ffd7cb44879d6a1b2879d388bcf7b701d45ae..b4c12b0b1e2d0799b6c6ba3296e96d83b0556f46 100644 (file)
@@ -19,7 +19,6 @@ import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
-import org.opendaylight.yangtools.concepts.CheckedBuilder;
 import org.opendaylight.yangtools.yang.binding.BindingObject;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
@@ -30,7 +29,7 @@ import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 
 @Beta
-public final class ModuleInfoSnapshotBuilder implements CheckedBuilder<ModuleInfoSnapshot, YangParserException> {
+public final class ModuleInfoSnapshotBuilder {
     private final Set<YangModuleInfo> moduleInfos = new HashSet<>();
     private final YangParserFactory parserFactory;
 
@@ -78,8 +77,13 @@ public final class ModuleInfoSnapshotBuilder implements CheckedBuilder<ModuleInf
         return this;
     }
 
-    @Override
-    public ModuleInfoSnapshot build() throws YangParserException {
+    /**
+     * Build {@link ModuleInfoSnapshot} from all {@code moduleInfos} in this builder.
+     *
+     * @return Resulting {@link ModuleInfoSnapshot}
+     * @throws YangParserException if parsing any of the {@link YangModuleInfo} instances fails
+     */
+    public @NonNull ModuleInfoSnapshot build() throws YangParserException {
         final YangParser parser = parserFactory.createParser();
         final Map<SourceIdentifier, YangModuleInfo> mappedInfos = new HashMap<>();
         final Map<String, ClassLoader> classLoaders = new HashMap<>();
index 2b5a5e4cf0cb0a37a63806112fee4283d3831f18..c2840c4b231eebf35bd40df238d993b3e8dbf83e 100644 (file)
@@ -25,7 +25,6 @@ import java.util.Objects;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.concepts.Builder;
 import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
 import org.opendaylight.yangtools.util.HashCodeBuilder;
 
@@ -827,7 +826,7 @@ public class InstanceIdentifier<T extends DataObject>
         }
     }
 
-    public interface InstanceIdentifierBuilder<T extends DataObject> extends Builder<InstanceIdentifier<T>> {
+    public interface InstanceIdentifierBuilder<T extends DataObject> {
         /**
          * Append the specified container as a child of the current InstanceIdentifier referenced by the builder. This
          * method should be used when you want to build an instance identifier by appending top-level elements, for
@@ -912,8 +911,7 @@ public class InstanceIdentifier<T extends DataObject>
          *
          * @return Resulting instance identifier.
          */
-        @Override
-        InstanceIdentifier<T> build();
+        @NonNull InstanceIdentifier<T> build();
     }
 
     private Object writeReplace() throws ObjectStreamException {
index d74159c8b3eb51fc5fda48ec4a3a8600180ea0cc..db16dcfd841a893bddb7f4cade0c7ef52ec168a8 100644 (file)
@@ -492,8 +492,7 @@ public final class BindingMap {
      * @param <K> the {@code Map}'s key type
      * @param <V> the {@code Map}'s value type
      */
-    public abstract static class Builder<K extends Identifier<V>, V extends Identifiable<K>>
-            implements org.opendaylight.yangtools.concepts.Builder<Map<K, V>> {
+    public abstract static class Builder<K extends Identifier<V>, V extends Identifiable<K>> {
         static final int DEFAULT_INITIAL_CAPACITY = 4;
 
         Builder() {
@@ -536,8 +535,27 @@ public final class BindingMap {
             return this;
         }
 
+        /**
+         * Build map from existing map entries in this builder.
+         *
+         * @return Resulting map
+         * @throws IllegalArgumentException if duplicate keys were added
+         */
+        public abstract @NonNull Map<K, V> build();
+
+        /**
+         * Add map entry identified by its {@code key} and containing {@code value} to this builder.
+         *
+         * @param key Key of the map entry
+         * @param value Value of the map entry
+         */
         abstract void addEntry(K key, V value);
 
+        /**
+         * Add collection of map entries to this builder.
+         *
+         * @param entries Map entries to add
+         */
         abstract void addEntries(Collection<Entry<K, V>> entries);
     }