import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
{ // create GeneralInterfaceFtlFile for runtime MXBean. Attributes will
// be transformed to getter methods
String mxBeanTypeName = entry.getJavaNameOfRuntimeMXBean();
- List<String> extendedInterfaces = Arrays.asList(RuntimeBean.class
+ List<String> extendedInterfaces = Collections.singletonList(RuntimeBean.class
.getCanonicalName());
List<MethodDeclaration> methods = new ArrayList<>();
// convert JavaAttribute parameters into fields
List<Field> fields = new ArrayList<>();
for (JavaAttribute ja : rpc.getParameters()) {
- Field field = new Field(Collections.<String> emptyList(),
+ Field field = new Field(Collections.emptyList(),
ja.getType().getFullyQualifiedName(),
ja.getLowerCaseCammelCase(), ja.getNullableDefaultWrappedForCode());
fields.add(field);
public static AbstractFactoryTemplate abstractFactoryTemplateFromMbe(
final ModuleMXBeanEntry mbe) {
AbstractFactoryAttributesProcessor attrProcessor = new AbstractFactoryAttributesProcessor();
- attrProcessor.processAttributes(mbe.getAttributes(),
- mbe.getPackageName());
+ attrProcessor.processAttributes(mbe.getAttributes());
boolean generateRuntime = false;
String registratorFullyQualifiedName = null;
if (mbe.getRuntimeBeans() != null
- && mbe.getRuntimeBeans().isEmpty() == false) {
+ && !mbe.getRuntimeBeans().isEmpty()) {
generateRuntime = true;
RuntimeBeanEntry rootEntry = RuntimeRegistratorFtlTemplate
.findRoot(mbe.getRuntimeBeans());
continue;
}
- Preconditions.checkState(yangPropertiesToTypesMap.containsKey(returnType.getAttributeYangName()) == false,
+ Preconditions.checkState(!yangPropertiesToTypesMap.containsKey(returnType.getAttributeYangName()),
"Duplicate TO %s for %s", returnType.getAttributeYangName(), rbe);
yangPropertiesToTypesMap.put(returnType.getAttributeYangName(), returnType);
}
private MethodDefinition getEquals(final Map<String, AttributeIfc> attrs) {
final StringBuilder equalsBodyBuilder = new StringBuilder(
- " if (this == o) return true;\n" +
- " if (o == null || getClass() != o.getClass()) return false;\n");
+ " if (this == o) { return true; }\n" +
+ " if (o == null || getClass() != o.getClass()) { return false; }\n");
equalsBodyBuilder.append(String.format(
" final %s that = (%s) o;\n", name, name));
for (AttributeIfc s : attrs.values()) {
equalsBodyBuilder.append(String.format(
- " if(java.util.Objects.equals(%1$s, that.%1$s) == false) {\n" +
+ " if (!java.util.Objects.equals(%1$s, that.%1$s)) {\n" +
" return false;\n" +
" }\n\n", s.getLowerCaseCammelCase()));
}
Collections.singletonList(new Annotation("Override", Collections.<Parameter>emptyList())), equalsBodyBuilder.toString());
}
- private MethodDefinition getHash(final Map<String, AttributeIfc> attrs) {
+ private static MethodDefinition getHash(final Map<String, AttributeIfc> attrs) {
final StringBuilder hashBodyBuilder = new StringBuilder(
" return java.util.Objects.hash(");
for (AttributeIfc s : attrs.values()) {
private final List<Field> fields = Lists.newArrayList();
- void processAttributes(final Map<String, AttributeIfc> attributes,
- final String packageName) {
- for (Entry<String, AttributeIfc> attrEntry : attributes.entrySet()) {
- String type;
- String nullableDefaultWrapped = null;
- AttributeIfc attributeIfc = attrEntry.getValue();
-
+ void processAttributes(final Map<String, AttributeIfc> attributes) {
+ for (AttributeIfc attributeIfc : attributes.values()) {
if (attributeIfc instanceof TypedAttribute) {
TypedAttribute typedAttribute = (TypedAttribute) attributeIfc;
- type = serializeType(typedAttribute.getType());
+ String type = serializeType(typedAttribute.getType());
+
+ fields.add(new Field(type, attributeIfc
+ .getUpperCaseCammelCase(), null));
} else {
throw new UnsupportedOperationException(
"Attribute not supported: "
+ attributeIfc.getClass());
}
-
- fields.add(new Field(type, attributeIfc
- .getUpperCaseCammelCase(), nullableDefaultWrapped));
}
}
String setterBody = "this." + varName + " = " + varName + ";";
if (isListOfDependencies) {
- String nullCheck = String.format("if (%s == null) throw new IllegalArgumentException(\"Null not supported\");%n",
- varName);
+ String nullCheck = String.format("if (%s == null) {\n%s = new java.util.ArrayList<>(); \n}%n",
+ varName, varName);
setterBody = nullCheck + setterBody;
}
MethodDefinition setter = new MethodDefinition("void",