*/
package org.opendaylight.mdsal.binding.model.util.generated.type.builder;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import java.util.stream.Collectors;
import org.opendaylight.mdsal.binding.model.api.AnnotationType;
import org.opendaylight.mdsal.binding.model.api.Constant;
import org.opendaylight.mdsal.binding.model.api.Enumeration;
@Override
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
- if ((packageName != null) && (name != null)) {
+ if (packageName != null && name != null) {
final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name);
if (!this.annotationBuilders.contains(builder)) {
this.annotationBuilders = LazyCollections.lazyAdd(this.annotationBuilders, builder);
return null;
}
- @Override
- public void addValue(final String name, final int value, final String description) {
- final EnumPairImpl p = new EnumPairImpl(name, value, description);
+ @VisibleForTesting
+ void addValue(final String name, final String mappedName, final int value, final String description) {
+ final EnumPairImpl p = new EnumPairImpl(name, mappedName, value, description);
this.values = LazyCollections.lazyAdd(this.values, p);
this.unmodifiableValues = Collections.unmodifiableList(this.values);
}
@Override
public Enumeration toInstance(final Type definingType) {
- return new EnumerationImpl(definingType, this.annotationBuilders, this.packageName, this.name, this.unmodifiableValues,
- this.description, this.reference, this.moduleName, this.schemaPath);
+ return new EnumerationImpl(definingType, this.annotationBuilders, this.packageName, this.name,
+ this.unmodifiableValues, this.description, this.reference, this.moduleName, this.schemaPath);
}
/*
@Override
public void updateEnumPairsFromEnumTypeDef(final EnumTypeDefinition enumTypeDef) {
final List<EnumPair> enums = enumTypeDef.getValues();
- if (enums != null) {
- for (final EnumPair enumPair : enums) {
- if (enumPair != null) {
- this.addValue(enumPair.getName(), enumPair.getValue(), enumPair.getDescription());
- }
- }
- }
+ final Map<String, String> valueIds = BindingMapping.mapEnumAssignedNames(enums.stream().map(EnumPair::getName)
+ .collect(Collectors.toList()));
+ for (EnumPair enumPair : enums) {
+ addValue(enumPair.getName(), valueIds.get(enumPair.getName()), enumPair.getValue(),
+ enumPair.getDescription());
+ }
}
private static final class EnumPairImpl implements Enumeration.Pair {
private final int value;
private final String description;
- public EnumPairImpl(final String name, final int value, final String description) {
- super();
- this.name = name;
- this.mappedName = BindingMapping.getClassName(name);
+ EnumPairImpl(final String name, final String mappedName, final int value, final String description) {
+ this.name = requireNonNull(name);
+ this.mappedName = requireNonNull(mappedName);
this.value = value;
this.description = description;
}
public int hashCode() {
final int prime = 31;
int result = 1;
- result = (prime * result) + Objects.hashCode(this.name);
- result = (prime * result) + Objects.hashCode(this.value);
+ result = prime * result + Objects.hashCode(this.name);
+ result = prime * result + Objects.hashCode(this.value);
return result;
}
builder.append(" (");
builder.append(valPair.getValue());
- if (i == (this.values.size() - 1)) {
+ if (i == this.values.size() - 1) {
builder.append(" );");
} else {
builder.append(" ),");