import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.ModuleRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
+import org.opendaylight.mdsal.binding.runtime.api.YangDataRuntimeType;
import org.opendaylight.yangtools.yang.binding.contract.Naming;
import org.opendaylight.yangtools.yang.common.AbstractQName;
import org.opendaylight.yangtools.yang.common.QNameModule;
ModuleRuntimeType build(final GeneratedType type, final ModuleEffectiveStatement statement,
final List<RuntimeType> children, final List<AugmentRuntimeType> augments) {
verify(augments.isEmpty(), "Unexpected augments %s", augments);
- return new DefaultModuleRuntimeType(type, statement, children);
+
+ final var yangDataChildren = new ArrayList<YangDataRuntimeType>();
+ for (var child : ModuleGenerator.this) {
+ if (child instanceof YangDataGenerator yangDataGen) {
+ yangDataGen.runtimeType().ifPresent(yangDataChildren::add);
+ }
+ }
+
+ return new DefaultModuleRuntimeType(type, statement, children, yangDataChildren);
}
};
}
*/
package org.opendaylight.mdsal.binding.generator.impl.rt;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.annotations.Beta;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
import java.util.List;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.runtime.api.ModuleRuntimeType;
@Beta
public final class DefaultModuleRuntimeType extends AbstractCompositeRuntimeType<ModuleEffectiveStatement>
implements ModuleRuntimeType {
- private final ImmutableList<YangDataRuntimeType> yangDataChildren;
+ private final ImmutableMap<YangDataName, YangDataRuntimeType> yangDataChildren;
public DefaultModuleRuntimeType(final GeneratedType bindingType, final ModuleEffectiveStatement statement,
- final List<RuntimeType> children) {
+ final List<RuntimeType> children, final List<YangDataRuntimeType> yangDataChildren) {
super(bindingType, statement, children);
- yangDataChildren = children.stream()
- .filter(YangDataRuntimeType.class::isInstance)
- .map(YangDataRuntimeType.class::cast)
- .collect(ImmutableList.toImmutableList());
+ this.yangDataChildren = Maps.uniqueIndex(yangDataChildren, type -> type.statement().argument());
}
@Override
public YangDataRuntimeType yangDataChild(final YangDataName templateName) {
- if (statement().localQNameModule().equals(templateName.module())) {
- final var name = templateName.name();
- for (var child : yangDataChildren) {
- if (name.equals(child.statement().argument())) {
- return child;
- }
- }
- }
- return null;
+ return yangDataChildren.get(requireNonNull(templateName));
}
}