String performance and maintenability 54/57354/8
authorStephen Kitt <skitt@redhat.com>
Thu, 18 May 2017 13:28:46 +0000 (15:28 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 16 Sep 2017 01:39:20 +0000 (01:39 +0000)
Use StringBuilder for strings built in loops. Use plain concatenation
for string construction not involving loops.

Change-Id: I8299eb54a347d132f0d19dfb39c8fb52366049f2
Signed-off-by: Stephen Kitt <skitt@redhat.com>
30 files changed:
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/IdentityAttributeRef.java
opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/ObjectNameAttributeMappingStrategy.java
opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/EditStrategyType.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/ConfigSnapshot.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/RuntimeRegistratorFtlTemplate.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/AbsFactoryGeneratedObjectFactory.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/AbsModuleGeneratedObjectFactory.java
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/MbeASTVisitor.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/NotLeaderExceptionTest.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/base/messages/CaptureSnapshot.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/messages/AppendEntries.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/messages/InstallSnapshotReply.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/messages/RequestVote.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/AbstractRaftActorIntegrationTest.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/CommonConfig.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/MeteringBehavior.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/LeaderStateChanged.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypesTest.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/clustering/Entity.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ShardManagerIdentifier.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/BatchedModifications.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/BatchedModificationsReply.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CreateTransactionReply.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/FindPrimary.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/LocalPrimaryShardFound.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/RemotePrimaryShardFound.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/SwitchShardBehavior.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImpl.java

index a578ac5..735a6e1 100644 (file)
@@ -40,10 +40,7 @@ public final class IdentityAttributeRef {
 
     @Override
     public String toString() {
-        final StringBuilder sb = new StringBuilder("IdentityAttributeRef{");
-        sb.append("qNameOfIdentity='").append(qualifiedNameOfIdentity).append('\'');
-        sb.append('}');
-        return sb.toString();
+        return "IdentityAttributeRef{" + "qualifiedNameOfIdentity='" + qualifiedNameOfIdentity + "'}";
     }
 
     @Override
index 4cad460..9d6c59c 100644 (file)
@@ -73,12 +73,11 @@ public class ObjectNameAttributeMappingStrategy
 
         @Override
         public String toString() {
-            final StringBuilder sb = new StringBuilder("MappedDependency{");
-            sb.append("namespace='").append(namespace).append('\'');
-            sb.append(", serviceName='").append(serviceName).append('\'');
-            sb.append(", refName='").append(refName).append('\'');
-            sb.append('}');
-            return sb.toString();
+            return "MappedDependency{"
+                    + "namespace='" + namespace + '\''
+                    + ", serviceName='" + serviceName + '\''
+                    + ", refName='" + refName + '\''
+                    + '}';
         }
     }
 }
index bf11f2a..5061592 100644 (file)
@@ -46,10 +46,11 @@ public enum EditStrategyType {
             EditStrategyType defaultStrategy) throws OperationNotPermittedException {
         if (defaultStrategy.isEnforcing()) {
             if (parsedStrategy != defaultStrategy) {
-                throw new OperationNotPermittedException(String.format("With " + defaultStrategy
-                        + " as default-operation operations on module elements are not permitted"
-                        + "since the default option is restrictive"),
-                        DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED,
+                throw new OperationNotPermittedException("With " + defaultStrategy
+                        + " as default-operation operations on module elements are not permitted since the default "
+                        + "option is restrictive",
+                        DocumentedException.ErrorType.APPLICATION,
+                        DocumentedException.ErrorTag.OPERATION_FAILED,
                         DocumentedException.ErrorSeverity.ERROR);
             }
         }
index 25b691f..d5d82dd 100644 (file)
@@ -541,10 +541,7 @@ public class ConfigTransactionControllerImpl implements ConfigTransactionControl
 
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("transactionName=");
-        sb.append(getTransactionName());
-        return sb.toString();
+        return "transactionName=" + getTransactionName();
     }
 
     // @VisibleForTesting
index e84e75a..05372dd 100644 (file)
@@ -82,12 +82,11 @@ public class ConfigSnapshot {
 
     @Override
     public String toString() {
-        final StringBuilder sb = new StringBuilder("ConfigSnapshot{");
-        sb.append("configSnapshot='").append(configXml).append('\'');
-        sb.append(", capabilities=").append(capabilities);
-        sb.append(", features=").append(features);
-        sb.append('}');
-        return sb.toString();
+        return "ConfigSnapshot{"
+                + "configSnapshot='" + configXml + '\''
+                + ", capabilities=" + capabilities
+                + ", features=" + features +
+                '}';
     }
 }
 
index dd2cd8c..47a1dfc 100644 (file)
@@ -106,19 +106,17 @@ public class RuntimeRegistratorFtlTemplate extends GeneralClassTemplate {
                     .getFullyQualifiedName(rootRB.getPackageName(), rootRB.getJavaNameOfRuntimeMXBean());
             String childRegistratorFQN = rootFtlFile.getFullyQualifiedName();
             Field rbParameter = new Field(fullyQualifiedNameOfMXBean, "rb");
-            StringBuilder registerBody = new StringBuilder();
-            registerBody.append(format("%s %s = this.%s.registerRoot(%s);\n",
-                    HierarchicalRuntimeBeanRegistration.class
-                            .getCanonicalName(), hierachicalRegistration
-                            .getName(), rootRuntimeBeanRegistratorField
-                            .getName(), rbParameter.getName()));
-            registerBody.append(format("return new %s(%s);\n",
-                    rootFtlFile.getFullyQualifiedName(),
-                    hierachicalRegistration.getName()));
+            String registerBody = format("%s %s = this.%s.registerRoot(%s);\n"
+                            + "return new %s(%2$s);\n",
+                    HierarchicalRuntimeBeanRegistration.class.getCanonicalName(),
+                    hierachicalRegistration.getName(),
+                    rootRuntimeBeanRegistratorField.getName(),
+                    rbParameter.getName(),
+                    rootFtlFile.getFullyQualifiedName());
 
             MethodDefinition registerMethod = new MethodDefinition(
                     childRegistratorFQN, "register",
-                    Collections.singletonList(rbParameter), registerBody.toString());
+                    Collections.singletonList(rbParameter), registerBody);
             methods.add(registerMethod);
         }
 
index e7a7d21..dad6222 100644 (file)
@@ -148,65 +148,70 @@ public class AbsFactoryGeneratedObjectFactory {
     }
 
     private static String getCreateModule(FullyQualifiedName moduleFQN, List<Field> moduleFields) {
-        String result = "\n"+
-            "@Override\n"+
-            format("public %s createModule(String instanceName, %s dependencyResolver, %s old, %s bundleContext) throws Exception {\n",
-                                Module.class.getCanonicalName(), DependencyResolver.class.getCanonicalName(),
-                                DynamicMBeanWithInstance.class.getCanonicalName(), BUNDLE_CONTEXT)+
-                format("%s oldModule;\n",moduleFQN)+
-                "try {\n"+
-                    format("oldModule = (%s) old.getModule();\n", moduleFQN)+
-                "} catch(Exception e) {\n"+
-                    "return handleChangedClass(dependencyResolver, old, bundleContext);\n"+
-                "}\n"+
-            format("%s module = instantiateModule(instanceName, dependencyResolver, oldModule, old.getInstance(), bundleContext);\n", moduleFQN);
-
-        for(Field field: moduleFields) {
-            result += format("module.set%s(oldModule.get%1$s());\n", field.getName());
+        StringBuilder result = new StringBuilder("\n" +
+                "@Override\n");
+        result.append(
+                format("public %s createModule(String instanceName, %s dependencyResolver, %s old, %s bundleContext) "
+                                + "throws Exception {\n",
+                        Module.class.getCanonicalName(), DependencyResolver.class.getCanonicalName(),
+                        DynamicMBeanWithInstance.class.getCanonicalName(), BUNDLE_CONTEXT))
+                .append(format("%s oldModule;\n", moduleFQN))
+                .append("try {\n")
+                .append(format("oldModule = (%s) old.getModule();\n", moduleFQN))
+                .append("} catch(Exception e) {\n"
+                        + "return handleChangedClass(dependencyResolver, old, bundleContext);\n"
+                        + "}\n")
+                .append(format("%s module = instantiateModule(instanceName, dependencyResolver, oldModule, old"
+                                + ".getInstance(), bundleContext);\n",
+                        moduleFQN));
+
+        for (Field field : moduleFields) {
+            result.append(format("module.set%s(oldModule.get%1$s());\n", field.getName()));
         }
 
-        result += "\n"+
-                "return module;\n"+
-            "}\n";
-        return result;
+        result.append("\n"
+                + "return module;\n"
+                + "}\n");
+        return result.toString();
     }
 
     private static String getServiceIfcsInitialization(List<FullyQualifiedName> providedServices) {
         String generic = format("Class<? extends %s>", AbstractServiceInterface.class.getCanonicalName());
 
-        String result = "static {\n";
+        StringBuilder result = new StringBuilder("static {\n");
         if (!providedServices.isEmpty()) {
-            result += format("java.util.Set<%1$s> serviceIfcs2 = new java.util.HashSet<>();\n", generic);
+            result.append(format("java.util.Set<%1$s> serviceIfcs2 = new java.util.HashSet<>();\n", generic));
 
-            for(FullyQualifiedName fqn: providedServices) {
-                result += format("serviceIfcs2.add(%s.class);\n", fqn);
+            for (FullyQualifiedName fqn : providedServices) {
+                result.append(format("serviceIfcs2.add(%s.class);\n", fqn));
             }
 
-            result += "serviceIfcs = java.util.Collections.unmodifiableSet(serviceIfcs2);\n";
+            result.append("serviceIfcs = java.util.Collections.unmodifiableSet(serviceIfcs2);\n");
         } else {
-            result += "serviceIfcs = java.util.Collections.emptySet();\n";
+            result.append("serviceIfcs = java.util.Collections.emptySet();\n");
         }
-        result += "}\n";
+        result.append("}\n");
 
         // add isModuleImplementingServiceInterface and getImplementedServiceIntefaces methods
 
-        result += format("\n"+
-            "@Override\n"+
-            "public final boolean isModuleImplementingServiceInterface(Class<? extends %1$s> serviceInterface) {\n"+
-                "for (Class<?> ifc: serviceIfcs) {\n"+
-                    "if (serviceInterface.isAssignableFrom(ifc)){\n"+
-                        "return true;\n"+
-                    "}\n"+
-                "}\n"+
-                "return false;\n"+
-            "}\n"+
-            "\n"+
-            "@Override\n"+
-            "public java.util.Set<Class<? extends %1$s>> getImplementedServiceIntefaces() {\n"+
-                "return serviceIfcs;\n"+
-            "}\n", AbstractServiceInterface.class.getCanonicalName());
-
-        return result;
+        result.append(format("\n"
+                + "@Override\n"
+                + "public final boolean isModuleImplementingServiceInterface(Class<? extends %1$s> serviceInterface) "
+                + "{\n"
+                + "for (Class<?> ifc: serviceIfcs) {\n"
+                + "if (serviceInterface.isAssignableFrom(ifc)){\n"
+                + "return true;\n"
+                + "}\n"
+                + "}\n"
+                + "return false;\n"
+                + "}\n"
+                + "\n"
+                + "@Override\n"
+                + "public java.util.Set<Class<? extends %1$s>> getImplementedServiceIntefaces() {\n"
+                + "return serviceIfcs;\n"
+                + "}\n", AbstractServiceInterface.class.getCanonicalName()));
+
+        return result.toString();
     }
 
 }
index cfc2ea5..0444318 100644 (file)
@@ -133,11 +133,11 @@ public class AbsModuleGeneratedObjectFactory {
     }
 
     private static String getMethods(List<? extends Method>  methods) {
-        String result = "\n// getters and setters\n";
-        for(Method method: methods) {
-            result += method.toString()+"\n";
+        StringBuilder result = new StringBuilder("\n// getters and setters\n");
+        for (Method method : methods) {
+            result.append(method).append("\n");
         }
-        return result;
+        return result.toString();
     }
 
     private static String getEqualsAndHashCode(FullyQualifiedName abstractFQN) {
@@ -157,55 +157,59 @@ public class AbsModuleGeneratedObjectFactory {
     }
 
     private static String getReuseLogic(List<ModuleField> moduleFields, FullyQualifiedName abstractFQN) {
-        String result = "\n"+
-            format("public boolean canReuseInstance(%s oldModule){\n", abstractFQN.getTypeName())+
-                "// allow reusing of old instance if no parameters was changed\n"+
-                "return isSame(oldModule);\n"+
-            "}\n"+
-            "\n"+
-            format("public %s reuseInstance(%1$s oldInstance){\n", AutoCloseable.class.getCanonicalName())+
-                "// implement if instance reuse should be supported. Override canReuseInstance to change the criteria.\n"+
-                "return oldInstance;\n"+
-            "}\n";
+        StringBuilder result = new StringBuilder("\n" +
+                format("public boolean canReuseInstance(%s oldModule){\n", abstractFQN.getTypeName()) +
+                "// allow reusing of old instance if no parameters was changed\n" +
+                "return isSame(oldModule);\n" +
+                "}\n" +
+                "\n" +
+                format("public %s reuseInstance(%1$s oldInstance){\n", AutoCloseable.class.getCanonicalName()) +
+                "// implement if instance reuse should be supported." +
+                "Override canReuseInstance to change the criteria.\n" +
+                "return oldInstance;\n" +
+                "}\n");
         // isSame method that detects changed fields
-        result += "\n"+
-            format("public boolean isSame(%s other) {\n", abstractFQN.getTypeName())+
-                "if (other == null) {\n"+
-                    "throw new IllegalArgumentException(\"Parameter 'other' is null\");\n"+
-                "}\n";
-        // loop through fields, do deep equals on each field
+        result.append("\n")
+                .append(format("public boolean isSame(%s other) {\n", abstractFQN.getTypeName()))
+                .append("if (other == null) {\n")
+                .append("throw new IllegalArgumentException(\"Parameter 'other' is null\");\n")
+                .append("}\n");
 
+        // loop through fields, do deep equals on each field
         for (ModuleField moduleField : moduleFields) {
-            result += format(
-                "if (!java.util.Objects.deepEquals(%s, other.%1$s)) {\n"+
-                    "return false;\n"+
-                "}\n", moduleField.getName());
+            result.append(format(
+                    "if (!java.util.Objects.deepEquals(%s, other.%1$s)) {\n" +
+                            "return false;\n" +
+                            "}\n", moduleField.getName()));
 
             if (moduleField.isListOfDependencies()) {
-                result += format(
-                        "for (int idx = 0; idx < %1$s.size(); idx++) {\n"+
-                            "if (!dependencyResolver.canReuseDependency(%1$s.get(idx), %1$sJmxAttribute)) {\n"+
-                                "return false;\n"+
-                            "}\n"+
-                        "}\n" , moduleField.getName());
+                result.append(format(
+                        "for (int idx = 0; idx < %1$s.size(); idx++) {\n" +
+                                "if (!dependencyResolver.canReuseDependency(%1$s.get(idx), %1$sJmxAttribute)) {\n" +
+                                "return false;\n" +
+                                "}\n" +
+                                "}\n", moduleField.getName()));
             } else if (moduleField.isDependent()) {
-                result += format(
+                result.append(format(
                         // If a reference is null (ie optional reference) it makes no sens to call canReuse on it
-                        // In such case we continue in the isSame method because if we have null here, the previous value was null as well
-                        // If the previous value was not null and current is or vice verse, the deepEquals comparison would return false
+                        // In such case we continue in the isSame method because if we have null here, the previous
+                        // value was null as well
+                        // If the previous value was not null and current is or vice verse, the deepEquals comparison
+                        // would return false
                         "if(%1$s!= null) {\n" +
-                            "if (!dependencyResolver.canReuseDependency(%1$s, %1$sJmxAttribute)) { // reference to dependency must be reusable as well\n" +
+                                "// reference to dependency must be reusable as well\n" +
+                                "if (!dependencyResolver.canReuseDependency(%1$s, %1$sJmxAttribute)) {\n" +
                                 "return false;\n" +
-                            "}\n" +
-                        "}\n", moduleField.getName());
+                                "}\n" +
+                                "}\n", moduleField.getName()));
             }
         }
 
-        result += "\n"+
-                "return true;\n"+
-            "}\n";
+        result.append("\n" +
+                "return true;\n" +
+                "}\n");
 
-        return result;
+        return result.toString();
     }
 
     private static String getResolveDependencies(final List<ModuleField> moduleFields) {
@@ -230,46 +234,46 @@ public class AbsModuleGeneratedObjectFactory {
             }
         }
 
-        String result = "\n"
-                + "protected final void resolveDependencies() {\n";
+        StringBuilder result = new StringBuilder("\n" +
+                "protected final void resolveDependencies() {\n");
         // wrap each field resolvation statement with if !=null when dependency is not mandatory
         for (Map.Entry<ModuleField, String> entry : resolveDependenciesMap.entrySet()) {
-            if (entry.getKey().getDependency().isMandatory() == false) {
+            if (!entry.getKey().getDependency().isMandatory()) {
                 checkState(entry.getValue().endsWith(";\n"));
-                result += format("if (%s!=null) {\n%s}\n", entry.getKey().getName(), entry.getValue());
+                result.append(format("if (%s!=null) {\n%s}\n", entry.getKey().getName(), entry.getValue()));
             } else {
-                result += entry.getValue();
+                result.append(entry.getValue());
             }
         }
 
         // add code to inject dependency resolver to fields that support it
         for(ModuleField moduleField: moduleFields) {
             if (moduleField.isNeedsDepResolver()) {
-                result += format("if (%s!=null){\n", moduleField.getName());
+                result.append(format("if (%s!=null){\n", moduleField.getName()));
                 if (moduleField.isList()) {
-                    result += format(
-                            "for(%s candidate : %s) {\n"+
-                                    "candidate.injectDependencyResolver(dependencyResolver);\n"+
-                                    "}\n", moduleField.getGenericInnerType(), moduleField.getName());
+                    result.append(format(
+                            "for(%s candidate : %s) {\n" +
+                                    "candidate.injectDependencyResolver(dependencyResolver);\n" +
+                                    "}\n", moduleField.getGenericInnerType(), moduleField.getName()));
                 } else {
-                    result += format("%s.injectDependencyResolver(dependencyResolver);\n", moduleField.getName());
+                    result.append(format("%s.injectDependencyResolver(dependencyResolver);\n", moduleField.getName()));
                 }
-                result += "}\n";
+                result.append("}\n");
             }
         }
 
         // identity refs need to be injected with dependencyResolver and base class
         for (ModuleField moduleField : moduleFields) {
             if (moduleField.isIdentityRef()) {
-                result += format("if (%s!=null) {", moduleField.getName());
-                result += format("set%s(%s.resolveIdentity(dependencyResolver, %s.class));",
+                result.append(format("if (%s!=null) {", moduleField.getName()));
+                result.append(format("set%s(%s.resolveIdentity(dependencyResolver, %s.class));",
                         moduleField.getAttributeName(), moduleField.getName(),
-                        ((IdentityRefModuleField)moduleField).getIdentityBaseClass());
-                result += "}\n";
+                        ((IdentityRefModuleField) moduleField).getIdentityBaseClass()));
+                result.append("}\n");
             }
         }
-        result += "}\n";
-        return result;
+        result.append("}\n");
+        return result.toString();
     }
 
     private static String getCachesOfResolvedIdentityRefs(List<ModuleField> moduleFields) {
@@ -328,37 +332,39 @@ public class AbsModuleGeneratedObjectFactory {
     }
 
     private static String getValidationMethods(List<ModuleField> moduleFields) {
-        String result = "\n"+
-            "@Override\n"+
-            "public void validate() {\n";
+        StringBuilder result = new StringBuilder("\n" +
+                "@Override\n" +
+                "public void validate() {\n");
         // validate each mandatory dependency
-        for(ModuleField moduleField: moduleFields) {
+        for (ModuleField moduleField : moduleFields) {
             if (moduleField.isDependent()) {
                 if (moduleField.isList()) {
-                    result += "" +
-                            format("for(javax.management.ObjectName dep : %s) {\n", moduleField.getName()) +
-                            format("    dependencyResolver.validateDependency(%s.class, dep, %sJmxAttribute);\n",
-                                    moduleField.getDependency().getSie().getFullyQualifiedName(), moduleField.getName()) +
-                            "}\n";
+                    result.append(format("for(javax.management.ObjectName dep : %s) {\n", moduleField.getName()))
+                            .append(format("    dependencyResolver.validateDependency(%s.class, dep, %sJmxAttribute);" +
+                                                    "\n",
+                                            moduleField.getDependency().getSie().getFullyQualifiedName(),
+                                            moduleField.getName()))
+                            .append("}\n");
                 } else {
-                    if(moduleField.getDependency().isMandatory() == false) {
-                        result += format("if(%s != null) {\n", moduleField.getName());
+                    if (!moduleField.getDependency().isMandatory()) {
+                        result.append(format("if(%s != null) {\n", moduleField.getName()));
                     }
-                    result += format("dependencyResolver.validateDependency(%s.class, %s, %sJmxAttribute);\n",
-                            moduleField.getDependency().getSie().getFullyQualifiedName(), moduleField.getName(), moduleField.getName());
-                    if(moduleField.getDependency().isMandatory() == false) {
-                        result += "}\n";
+                    result.append(format("dependencyResolver.validateDependency(%s.class, %s, %sJmxAttribute);\n",
+                            moduleField.getDependency().getSie().getFullyQualifiedName(), moduleField.getName(),
+                            moduleField.getName()));
+                    if (!moduleField.getDependency().isMandatory()) {
+                        result.append("}\n");
                     }
                 }
             }
         }
-        result += "\n"+
-                "customValidation();\n"+
-            "}\n"+
-            "\n"+
-            "protected void customValidation() {\n"+
-            "}\n";
-        return result;
+        result.append("\n" +
+                "customValidation();\n" +
+                "}\n" +
+                "\n" +
+                "protected void customValidation() {\n" +
+                "}\n");
+        return result.toString();
     }
 
     private static String getLoggerDefinition(FullyQualifiedName fqn) {
index 3fc32dc..57770c3 100644 (file)
@@ -49,7 +49,7 @@ class MbeASTVisitor extends SieASTVisitor {
             if (parent instanceof MethodDeclaration) {
                 // remember only top level description annotation
                 String reqVal = expr.getPairs().get(0).toString();
-                requireIfc.put(((MethodDeclaration) parent).getName().toString(), reqVal);
+                requireIfc.put(((MethodDeclaration) parent).getName(), reqVal);
             }
         }
     }
index 32cc72f..c018f00 100644 (file)
@@ -30,8 +30,7 @@ public class NotLeaderExceptionTest extends RequestExceptionTest<NotLeaderExcept
     @Override
     protected void checkMessage() {
         final String message = OBJECT.getMessage();
-        final String checkMessage = new StringBuilder("Actor ").append(ACTOR.toString())
-                .append(" is not the current leader").toString();
+        final String checkMessage = "Actor " + ACTOR + " is not the current leader";
         assertTrue(checkMessage.equals(message));
         assertNull(OBJECT.getCause());
     }
index 2a54d7a..b06f8f2 100644 (file)
@@ -65,14 +65,14 @@ public class CaptureSnapshot implements ControlMessage {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("CaptureSnapshot [lastAppliedIndex=").append(lastAppliedIndex).append(", lastAppliedTerm=")
-                .append(lastAppliedTerm).append(", lastIndex=").append(lastIndex).append(", lastTerm=")
-                .append(lastTerm).append(", installSnapshotInitiated=")
-                .append(", replicatedToAllIndex=").append(replicatedToAllIndex).append(", replicatedToAllTerm=")
-                .append(replicatedToAllTerm).append(", unAppliedEntries size=")
-                .append(unAppliedEntries.size()).append("]");
-        return builder.toString();
+        return "CaptureSnapshot [lastAppliedIndex=" + lastAppliedIndex
+                + ", lastAppliedTerm=" + lastAppliedTerm
+                + ", lastIndex=" + lastIndex
+                + ", lastTerm=" + lastTerm
+                + ", installSnapshotInitiated="
+                + ", replicatedToAllIndex=" + replicatedToAllIndex
+                + ", replicatedToAllTerm=" + replicatedToAllTerm
+                + ", unAppliedEntries size=" + unAppliedEntries.size() + "]";
     }
 
 
index d878e2c..4d4b7e4 100644 (file)
@@ -92,12 +92,13 @@ public class AppendEntries extends AbstractRaftRPC {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("AppendEntries [leaderId=").append(leaderId).append(", prevLogIndex=").append(prevLogIndex)
-                .append(", prevLogTerm=").append(prevLogTerm).append(", leaderCommit=").append(leaderCommit)
-                .append(", replicatedToAllIndex=").append(replicatedToAllIndex).append(", payloadVersion=")
-                .append(payloadVersion).append(", entries=").append(entries).append("]");
-        return builder.toString();
+        return "AppendEntries [leaderId=" + leaderId
+                + ", prevLogIndex=" + prevLogIndex
+                + ", prevLogTerm=" + prevLogTerm
+                + ", leaderCommit=" + leaderCommit
+                + ", replicatedToAllIndex=" + replicatedToAllIndex
+                + ", payloadVersion=" + payloadVersion
+                + ", entries=" + entries + "]";
     }
 
     private Object writeReplace() {
index 4f0ca13..bbee5c4 100644 (file)
@@ -43,10 +43,10 @@ public class InstallSnapshotReply extends AbstractRaftRPC {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("InstallSnapshotReply [term=").append(getTerm()).append(", followerId=").append(followerId)
-                .append(", chunkIndex=").append(chunkIndex).append(", success=").append(success).append("]");
-        return builder.toString();
+        return "InstallSnapshotReply [term=" + getTerm()
+                + ", followerId=" + followerId
+                + ", chunkIndex=" + chunkIndex
+                + ", success=" + success + "]";
     }
 
     private Object writeReplace() {
index 5ed18f9..d5a581a 100644 (file)
@@ -49,11 +49,11 @@ public class RequestVote extends AbstractRaftRPC {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("RequestVote [term=").append(getTerm()).append(", candidateId=").append(candidateId)
-                .append(", lastLogIndex=").append(lastLogIndex).append(", lastLogTerm=").append(lastLogTerm)
-                .append("]");
-        return builder.toString();
+        return "RequestVote [term=" + getTerm()
+                + ", candidateId=" + candidateId
+                + ", lastLogIndex=" + lastLogIndex
+                + ", lastLogTerm=" + lastLogTerm
+                + "]";
     }
 
     private Object writeReplace() {
index 05a2df4..9d275e7 100644 (file)
@@ -131,7 +131,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest
             }
 
             if (message instanceof SetPeerAddress) {
-                setPeerAddress(((SetPeerAddress) message).getPeerId().toString(),
+                setPeerAddress(((SetPeerAddress) message).getPeerId(),
                         ((SetPeerAddress) message).getPeerAddress());
                 return;
             }
index 84ac92e..d57134d 100644 (file)
@@ -63,7 +63,7 @@ public class CommonConfig extends AbstractConfig {
             return cachedMailBoxCapacity;
         }
 
-        final String PATH = new StringBuilder(TAG_MAILBOX).append(".").append(TAG_MAILBOX_CAPACITY).toString();
+        final String PATH = TAG_MAILBOX + "." + TAG_MAILBOX_CAPACITY;
         cachedMailBoxCapacity = get().hasPath(PATH)
                 ? get().getInt(PATH)
                 : DEFAULT_MAILBOX_CAPACITY;
@@ -77,7 +77,7 @@ public class CommonConfig extends AbstractConfig {
             return cachedMailBoxPushTimeout;
         }
 
-        final String PATH = new StringBuilder(TAG_MAILBOX).append(".").append(TAG_MAILBOX_PUSH_TIMEOUT).toString();
+        final String PATH = TAG_MAILBOX + "." + TAG_MAILBOX_PUSH_TIMEOUT;
 
         long timeout = get().hasPath(PATH)
                 ? get().getDuration(PATH, TimeUnit.NANOSECONDS)
index 8a8eed1..6395891 100644 (file)
@@ -61,8 +61,8 @@ public class MeteringBehavior implements Procedure<Object> {
     }
 
     private void init(final String actorName) {
-        actorQualifiedName = new StringBuilder(meteredActor.getSelf().path().parent().toStringWithoutAddress())
-                .append("/").append(actorName).toString();
+        actorQualifiedName = meteredActor.getSelf().path().parent().toStringWithoutAddress()
+                + "/" + actorName;
 
         final String msgProcessingTime = MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE);
         msgProcessingTimer = metricRegistry.timer(msgProcessingTime);
index 359e2b2..5de794d 100644 (file)
@@ -42,9 +42,8 @@ public class LeaderStateChanged {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("LeaderStateChanged [memberId=").append(memberId).append(", leaderId=").append(leaderId)
-                .append(", leaderPayloadVersion=").append(leaderPayloadVersion).append("]");
-        return builder.toString();
+        return "LeaderStateChanged [memberId=" + memberId
+                + ", leaderId=" + leaderId
+                + ", leaderPayloadVersion=" + leaderPayloadVersion + "]";
     }
 }
index 083a049..81d9767 100644 (file)
@@ -229,12 +229,10 @@ public class NormalizedNodeStreamReaderWriterTest {
     }
 
     private static String largeString(final int pow) {
-        String str = "X";
+        StringBuilder sb = new StringBuilder("X");
         for (int i = 0; i < pow; i++) {
-            StringBuilder buf = new StringBuilder();
-            buf.append(str).append(str);
-            str = buf.toString();
+            sb.append(sb);
         }
-        return str;
+        return sb.toString();
     }
 }
index 34b5421..0395e94 100644 (file)
@@ -22,12 +22,10 @@ public class ValueTypesTest {
 
     private static String largeString(int minSize) {
         final int pow = (int) (Math.log(minSize * 2) / Math.log(2));
-        String str = "X";
+        StringBuilder sb = new StringBuilder("X");
         for (int i = 0; i < pow; i++) {
-            StringBuilder buf = new StringBuilder();
-            buf.append(str).append(str);
-            str = buf.toString();
+            sb.append(sb);
         }
-        return str;
+        return sb.toString();
     }
 }
index e301130..2c79ff6 100644 (file)
@@ -121,10 +121,6 @@ public final class Entity implements Serializable {
 
     @Override
     public String toString() {
-        final StringBuilder sb = new StringBuilder("Entity{");
-        sb.append("type='").append(type).append('\'');
-        sb.append(", id=").append(id);
-        sb.append('}');
-        return sb.toString();
+        return "Entity{" + "type='" + type + '\'' + ", id=" + id + '}';
     }
 }
index 98dbba3..880ba99 100644 (file)
@@ -39,9 +39,7 @@ public class ShardManagerIdentifier {
     }
 
     @Override public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("shardmanager-").append(type);
-        return builder.toString();
+        return "shardmanager-" + type;
     }
 
     public static Builder builder() {
index da87a08..3773bee 100644 (file)
@@ -84,10 +84,9 @@ public class BatchedModifications extends MutableCompositeModification {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("BatchedModifications [transactionId=").append(transactionId).append(", ready=").append(ready)
-            .append(", totalMessagesSent=").append(totalMessagesSent).append(", modifications size=")
-            .append(getModifications().size()).append("]");
-        return builder.toString();
+        return "BatchedModifications [transactionId=" + transactionId
+                + ", ready=" + ready
+                + ", totalMessagesSent=" + totalMessagesSent
+                + ", modifications size=" + getModifications().size() + "]";
     }
 }
index 070b143..29bb3e9 100644 (file)
@@ -46,8 +46,6 @@ public class BatchedModificationsReply extends VersionedExternalizableMessage {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("BatchedModificationsReply [numBatched=").append(numBatched).append("]");
-        return builder.toString();
+        return "BatchedModificationsReply [numBatched=" + numBatched + "]";
     }
 }
index 5bc0c74..e8d9b19 100644 (file)
@@ -54,10 +54,9 @@ public class CreateTransactionReply extends VersionedExternalizableMessage {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("CreateTransactionReply [transactionPath=").append(transactionPath).append(", transactionId=")
-                .append(transactionId).append(", version=").append(getVersion()).append("]");
-        return builder.toString();
+        return "CreateTransactionReply [transactionPath=" + transactionPath
+                + ", transactionId=" + transactionId
+                + ", version=" + getVersion() + "]";
     }
 
     public static CreateTransactionReply fromSerializable(Object serializable) {
index 507f615..9eba5c6 100644 (file)
@@ -38,9 +38,7 @@ public class FindPrimary implements Serializable {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append(getClass().getName()).append(" [shardName=").append(shardName).append(", waitUntilReady=")
-               .append(waitUntilReady).append("]");
-        return builder.toString();
+        return getClass().getName() + " [shardName=" + shardName
+                + ", waitUntilReady=" + waitUntilReady + "]";
     }
 }
index e19dcd6..707f50b 100644 (file)
@@ -37,9 +37,7 @@ public class LocalPrimaryShardFound {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("LocalPrimaryShardFound [primaryPath=").append(primaryPath).append(", localShardDataTree=")
-                .append(ObjectUtils.identityToString(localShardDataTree)).append("]");
-        return builder.toString();
+        return "LocalPrimaryShardFound [primaryPath=" + primaryPath
+                + ", localShardDataTree=" + ObjectUtils.identityToString(localShardDataTree) + "]";
     }
 }
index d3e27db..fbe34b2 100644 (file)
@@ -34,9 +34,7 @@ public class RemotePrimaryShardFound implements Serializable {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("RemotePrimaryShardFound [primaryPath=").append(primaryPath).append(", primaryVersion=")
-                .append(primaryVersion).append("]");
-        return builder.toString();
+        return "RemotePrimaryShardFound [primaryPath=" + primaryPath
+                + ", primaryVersion=" + primaryVersion + "]";
     }
 }
index e3c222d..63b8f65 100644 (file)
@@ -38,11 +38,10 @@ final class SwitchShardBehavior {
 
     @Override
     public String toString() {
-        final StringBuilder sb = new StringBuilder("SwitchShardBehavior{");
-        sb.append("shardId='").append(shardId).append('\'');
-        sb.append(", newState='").append(newState).append('\'');
-        sb.append(", term=").append(term);
-        sb.append('}');
-        return sb.toString();
+        return "SwitchShardBehavior{"
+                + "shardId='" + shardId + '\''
+                + ", newState='" + newState + '\''
+                + ", term=" + term
+                + '}';
     }
 }
index eabb170..58abcac 100644 (file)
@@ -61,9 +61,7 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
         Set<String> routedRpc = new HashSet<>(table.getRoutes().size());
         for (DOMRpcIdentifier route : table.getRoutes()) {
             if (!route.getContextReference().isEmpty()) {
-                StringBuilder builder = new StringBuilder(ROUTE_CONSTANT);
-                builder.append(route.getContextReference().toString()).append(NAME_CONSTANT).append(route.getType());
-                routedRpc.add(builder.toString());
+                routedRpc.add(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + route.getType());
             }
         }
 
@@ -114,9 +112,7 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
             if (!route.getContextReference().isEmpty()) {
                 String routeString = route.getContextReference().toString();
                 if (routeString.contains(routeName)) {
-                    StringBuilder builder = new StringBuilder(ROUTE_CONSTANT);
-                    builder.append(routeString).append(NAME_CONSTANT).append(route.getType());
-                    rpcMap.put(builder.toString(), address);
+                    rpcMap.put(ROUTE_CONSTANT + routeString + NAME_CONSTANT + route.getType(), address);
                 }
             }
         }
@@ -134,9 +130,7 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot
             if (!route.getContextReference().isEmpty()) {
                 String type = route.getType().toString();
                 if (type.contains(name)) {
-                    StringBuilder builder = new StringBuilder(ROUTE_CONSTANT);
-                    builder.append(route.getContextReference()).append(NAME_CONSTANT).append(type);
-                    rpcMap.put(builder.toString(), address);
+                    rpcMap.put(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + type, address);
                 }
             }
         }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.