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;
}
*/
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();
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);
}
}
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));
}
-
}
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;
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());
}
}
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
*
* @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>
* @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>
*
* @return <code>new</code> <i>immutable</i> instance of Annotation Type.
*/
- @Override
- AnnotationType build();
+ @NonNull AnnotationType build();
}
*/
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;
/**
*
* @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>
*
* @return generated transfer object instance
*/
- @Override
- GeneratedTransferObject build();
+ @NonNull GeneratedTransferObject build();
void setTypedef(boolean isTypedef);
*/
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
*
* @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();
}
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;
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);
return parameterizedTypeFor(LISTENABLE_FUTURE, valueType);
}
- /**
- * Returns an instance of {@link ParameterizedType} describing the typed
- * {@link Builder}<V> 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}.
*
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;
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;
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<>();
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;
}
}
- 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
*
* @return Resulting instance identifier.
*/
- @Override
- InstanceIdentifier<T> build();
+ @NonNull InstanceIdentifier<T> build();
}
private Object writeReplace() throws ObjectStreamException {
* @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() {
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);
}