Sho SHIMIZU
Committed by Gerrit Code Review

Simplify statements

Change-Id: I3622055e0615552be7de143b38c6ac8ec75c7f8d
...@@ -114,11 +114,10 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -114,11 +114,10 @@ public class ResourcesCommand extends AbstractShellCommand {
114 if (resource.equals(Resource.ROOT)) { 114 if (resource.equals(Resource.ROOT)) {
115 print("ROOT"); 115 print("ROOT");
116 } else { 116 } else {
117 + String resourceName = resource.simpleTypeName();
117 if (resource instanceof ContinuousResource) { 118 if (resource instanceof ContinuousResource) {
118 - String s = resource.simpleTypeName();
119 - String simpleName = s.substring(s.lastIndexOf('.') + 1);
120 print("%s%s: %f", Strings.repeat(" ", level), 119 print("%s%s: %f", Strings.repeat(" ", level),
121 - simpleName, 120 + resourceName,
122 // Note: last() does not return, what we've registered 121 // Note: last() does not return, what we've registered
123 // following does not work 122 // following does not work
124 //((Class<?>) resource.last()).getSimpleName(), 123 //((Class<?>) resource.last()).getSimpleName(),
...@@ -126,8 +125,6 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -126,8 +125,6 @@ public class ResourcesCommand extends AbstractShellCommand {
126 // Continuous resource is terminal node, stop here 125 // Continuous resource is terminal node, stop here
127 return; 126 return;
128 } else { 127 } else {
129 - String resourceName = resource.simpleTypeName();
130 -
131 String toString = String.valueOf(resource.valueAs(Object.class).orElse("")); 128 String toString = String.valueOf(resource.valueAs(Object.class).orElse(""));
132 if (toString.startsWith(resourceName)) { 129 if (toString.startsWith(resourceName)) {
133 print("%s%s", Strings.repeat(" ", level), 130 print("%s%s", Strings.repeat(" ", level),
...@@ -161,8 +158,8 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -161,8 +158,8 @@ public class ResourcesCommand extends AbstractShellCommand {
161 nonAggregatable.add(r); 158 nonAggregatable.add(r);
162 } else if (Iterables.any(aggregatableTypes, r::isTypeOf)) { 159 } else if (Iterables.any(aggregatableTypes, r::isTypeOf)) {
163 // aggregatable & terminal node 160 // aggregatable & terminal node
164 - String className = r.simpleTypeName(); 161 + String simpleName = r.simpleTypeName();
165 - aggregatables.put(className, r); 162 + aggregatables.put(simpleName, r);
166 } else { 163 } else {
167 nonAggregatable.add(r); 164 nonAggregatable.add(r);
168 } 165 }
...@@ -214,18 +211,15 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -214,18 +211,15 @@ public class ResourcesCommand extends AbstractShellCommand {
214 return true; 211 return true;
215 } 212 }
216 213
217 - String resourceName; 214 + String resourceName = resource.simpleTypeName();
218 - if (resource instanceof ContinuousResource) { 215 + if (resource instanceof DiscreteResource) {
219 - resourceName = resource.simpleTypeName();
220 - } else if (resource instanceof DiscreteResource) {
221 // TODO This distributed store access incurs overhead. 216 // TODO This distributed store access incurs overhead.
222 // This should be merged with the one in printResource() 217 // This should be merged with the one in printResource()
223 if (!resourceService.getRegisteredResources(((DiscreteResource) resource).id()).isEmpty()) { 218 if (!resourceService.getRegisteredResources(((DiscreteResource) resource).id()).isEmpty()) {
224 // resource which has children should be printed 219 // resource which has children should be printed
225 return true; 220 return true;
226 } 221 }
227 - resourceName = resource.simpleTypeName(); 222 + } else if (!(resource instanceof ContinuousResource)) {
228 - } else {
229 log.warn("Unexpected resource class: {}", resource.getClass().getSimpleName()); 223 log.warn("Unexpected resource class: {}", resource.getClass().getSimpleName());
230 return false; 224 return false;
231 } 225 }
......