Code cleanup
Whitespace fixes, and addition of newlines at end of some files.
Use StringBuilder.append() rather than String += in loops.
Add equals() and hashCode() for class that implements Comparable.

Signed-off-by: James Ren <[email protected]>

--- autotest/frontend/client/src/autotest/afe/AfeUtils.java     2010-05-26 
16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/afe/AfeUtils.java     2010-05-26 
16:30:23.000000000 -0700
@@ -33,28 +33,31 @@
     public static final String PLATFORM_SUFFIX = " (platform)";
     public static final String ATOMIC_GROUP_SUFFIX = " (atomic group)";
     public static final String REINSTALL_TEST_NAME = "Re-install Machine";
-    
+
     public static final ClassFactory factory = new SiteClassFactory();
 
     private static StaticDataRepository staticData = 
StaticDataRepository.getRepository();
-    
+
     public static String formatStatusCounts(JSONObject counts, String 
joinWith) {
-        String result = "";
+        StringBuilder result = new StringBuilder();
         Set<String> statusSet = counts.keySet();
         for (Iterator<String> i = statusSet.iterator(); i.hasNext();) {
             String status = i.next();
             int count = (int) counts.get(status).isNumber().doubleValue();
-            result += Integer.toString(count) + " " + status;
-            if (i.hasNext())
-                result += joinWith;
+            result.append(Integer.toString(count));
+            result.append(" ");
+            result.append(status);
+            if (i.hasNext()) {
+                result.append(joinWith);
+            }
         }
-        return result;
+        return result.toString();
     }
-    
+
     public static String[] getLabelStrings() {
         return getFilteredLabelStrings(false, false);
     }
-    
+
     protected static String[] getFilteredLabelStrings(boolean onlyPlatforms,
                                                       boolean 
onlyNonPlatforms) {
         assert( !(onlyPlatforms && onlyNonPlatforms));
@@ -84,7 +87,7 @@
     public static String[] getPlatformStrings() {
         return getFilteredLabelStrings(true, false);
     }
-    
+
     public static String[] getNonPlatformLabelStrings() {
         return getFilteredLabelStrings(false, true);
     }
@@ -106,20 +109,20 @@
         boolean locked = host.get("locked").isBoolean().booleanValue();
         return new JSONString(locked ? "Yes" : "No");
     }
-    
-    public static void abortHostQueueEntries(Collection<JSONObject> entries, 
+
+    public static void abortHostQueueEntries(Collection<JSONObject> entries,
                                              final SimpleCallback onSuccess) {
         if (entries.isEmpty()) {
             NotifyManager.getInstance().showError("No entries selected to 
abort");
             return;
         }
-        
+
         final JSONArray asynchronousEntryIds = new JSONArray();
         Set<JSONObject> synchronousEntries = new JSONObjectSet<JSONObject>();
         for (JSONObject entry : entries) {
             JSONObject job = entry.get("job").isObject();
             int synchCount = (int) 
job.get("synch_count").isNumber().doubleValue();
-            boolean hasExecutionSubdir = 
+            boolean hasExecutionSubdir =
                 !Utils.jsonToString(entry.get("execution_subdir")).equals("");
             if (synchCount > 1 && hasExecutionSubdir) {
                 synchronousEntries.add(entry);
@@ -134,7 +137,7 @@
                 asynchronousEntryIds.set(asynchronousEntryIds.size(), 
entry.get("id"));
             }
         }
-        
+
         SimpleCallback abortAsynchronousEntries = new SimpleCallback() {
             public void doCallback(Object source) {
                 JSONObject params = new JSONObject();
@@ -142,7 +145,7 @@
                 AfeUtils.callAbort(params, onSuccess);
             }
         };
-        
+
         if (synchronousEntries.size() == 0) {
             abortAsynchronousEntries.doCallback(null);
         } else {
@@ -157,7 +160,7 @@
             array.set(array.size(), value);
         }
     }
-    
+
     public static void callAbort(JSONObject params, final SimpleCallback 
onSuccess,
                                  final boolean showMessage) {
         JsonRpcProxy rpcProxy = JsonRpcProxy.getProxy();
@@ -173,28 +176,28 @@
             }
         });
     }
-    
+
     public static void callAbort(JSONObject params, final SimpleCallback 
onSuccess) {
         callAbort(params, onSuccess, true);
     }
-    
+
     public static void callReverify(JSONObject params, final SimpleCallback 
onSuccess,
                                     final String messagePrefix) {
         JsonRpcProxy rpcProxy = JsonRpcProxy.getProxy();
         rpcProxy.rpcCall("reverify_hosts", params, new JsonRpcCallback() {
             @Override
             public void onSuccess(JSONValue result) {
-                
+
                 NotifyManager.getInstance().showMessage(
                         messagePrefix + " scheduled for reverification");
-                    
+
                 if (onSuccess != null) {
                     onSuccess.doCallback(null);
                 }
             }
         });
     }
-    
+
     private static void scheduleReinstallHelper(JSONArray hosts, JSONObject 
controlInfo,
                                                 final String messagePrefix,
                                                 final JobCreateListener 
listener) {
@@ -202,11 +205,11 @@
         if (hosts.size() > 1) {
             name += "_etc";
         }
-        
+
         // Get the option for "Never"
         JSONValue rebootBefore = 
staticData.getData("reboot_before_options").isArray().get(0);
         JSONValue rebootAfter = 
staticData.getData("reboot_after_options").isArray().get(0);
-        
+
         JSONObject args = new JSONObject();
         args.put("name", new JSONString(name));
         args.put("priority", staticData.getData("default_priority"));
@@ -220,7 +223,7 @@
         args.put("reboot_before", rebootBefore);
         args.put("reboot_after", rebootAfter);
         args.put("hosts", hosts);
-        
+
         JsonRpcProxy rpcProxy = JsonRpcProxy.getProxy();
         rpcProxy.rpcCall("create_job", args, new JsonRpcCallback() {
             @Override
@@ -232,7 +235,7 @@
             }
         });
     }
-    
+
     public static void scheduleReinstall(final JSONArray hosts, final String 
messagePrefix,
                                          final JobCreateListener listener) {
         // Find the test
@@ -245,16 +248,16 @@
                 break;
             }
         }
-        
+
         if (reinstallTest == null) {
             NotifyManager.getInstance().showError("No test found: " + 
REINSTALL_TEST_NAME);
             return;
         }
-        
+
         JSONObject params = new JSONObject();
         JSONArray array = new JSONArray();
         JsonRpcProxy rpcProxy = JsonRpcProxy.getProxy();
-        
+
         array.set(0, reinstallTest.get("id"));
         params.put("tests", array);
         rpcProxy.rpcCall("generate_control_file", params, new 
JsonRpcCallback() {
@@ -265,7 +268,7 @@
             }
         });
     }
-    
+
     public static void callModifyHosts(JSONObject params, final SimpleCallback 
onSuccess) {
         JsonRpcProxy rpcProxy = JsonRpcProxy.getProxy();
         rpcProxy.rpcCall("modify_hosts", params, new JsonRpcCallback() {
@@ -277,19 +280,19 @@
             }
         });
     }
-    
+
     public static void changeHostLocks(JSONArray hostIds, final boolean lock,
                                        final String messagePrefix, final 
SimpleCallback callback) {
         JSONObject hostFilterData = new JSONObject();
         JSONObject updateData = new JSONObject();
         JSONObject params = new JSONObject();
-        
+
         hostFilterData.put("id__in", hostIds);
         updateData.put("locked", JSONBoolean.getInstance(lock));
-        
+
         params.put("host_filter_data", hostFilterData);
         params.put("update_data", updateData);
-        
+
         callModifyHosts(params, new SimpleCallback() {
             public void doCallback(Object source) {
                 String message = messagePrefix + " ";
@@ -297,9 +300,9 @@
                     message += "un";
                 }
                 message += "locked";
-                
+
                 NotifyManager.getInstance().showMessage(message);
-                
+
                 callback.doCallback(source);
             }
         });
@@ -315,14 +318,14 @@
             chooser.addChoice(Utils.jsonToString(jsonOption));
         }
     }
-    
+
     public static void popualateListBox(ListBox box, String staticDataKey) {
         JSONArray options = staticData.getData(staticDataKey).isArray();
         for (JSONString jsonOption : new JSONArrayList<JSONString>(options)) {
             box.addItem(Utils.jsonToString(jsonOption));
         }
     }
-    
+
     public static void setSelectedItem(ListBox box, String item) {
         box.setSelectedIndex(0);
         for (int i = 0; i < box.getItemCount(); i++) {
@@ -332,7 +335,7 @@
             }
         }
     }
-    
+
     public static void removeElement(String id) {
         Element element = DOM.getElementById(id);
         element.getParentElement().removeChild(element);
--- autotest/frontend/client/src/autotest/afe/HostDataSource.java       
2010-05-26 16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/afe/HostDataSource.java       
2010-05-26 16:30:23.000000000 -0700
@@ -17,7 +17,7 @@
     protected static final String LOCKED_TEXT = "locked_text";
     protected static final String OTHER_LABELS = "other_labels";
     protected static final String HOST_ACLS = "host_acls";
-    
+
     public HostDataSource() {
         super("get_hosts", "get_num_hosts");
     }
@@ -39,24 +39,27 @@
 
     protected void processHost(JSONObject host) {
         host.put(LOCKED_TEXT, AfeUtils.getLockedText(host));
-        
+
         JSONString jsonPlatform = host.get("platform").isString();
         String platform = "";
-        if (jsonPlatform != null)
+        if (jsonPlatform != null) {
             platform = jsonPlatform.stringValue();
+        }
         JSONArray labels = host.get("labels").isArray();
-        String labelString = "";
+        StringBuilder labelString = new StringBuilder();
         for (int i = 0; i < labels.size(); i++) {
             String label = labels.get(i).isString().stringValue();
-            if (label.equals(platform))
+            if (label.equals(platform)) {
                 continue;
-            if (!labelString.equals(""))
-                labelString += ", ";
-            labelString += label;
+            }
+            if (labelString.length() > 0) {
+                labelString.append(", ");
+            }
+            labelString.append(label);
         }
-        host.put(OTHER_LABELS, new JSONString(labelString));
-        
-        JSONArrayList<JSONString> aclsList = 
+        host.put(OTHER_LABELS, new JSONString(labelString.toString()));
+
+        JSONArrayList<JSONString> aclsList =
             new JSONArrayList<JSONString>(host.get("acls").isArray());
         String aclString = Utils.joinStrings(",", aclsList);
         host.put(HOST_ACLS, new JSONString(aclString));
--- autotest/frontend/client/src/autotest/afe/JobStatusDataSource.java  
2010-05-26 16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/afe/JobStatusDataSource.java  
2010-05-26 16:30:23.000000000 -0700
@@ -20,28 +20,28 @@
  * Custom RpcDataSource to process the list of host queue entries for a job and
  * consolidate metahosts of the same label.
  */
-class JobStatusDataSource extends RpcDataSource { 
+class JobStatusDataSource extends RpcDataSource {
     private JSONObject dictionary;
-    
+
     public JobStatusDataSource() {
         super("get_host_queue_entries", "get_num_host_queue_entries");
-        
+
         // retrieve the dictionary from static data
         StaticDataRepository staticData = StaticDataRepository.getRepository();
         dictionary = staticData.getData("status_dictionary").isObject();
     }
-    
+
     private String translateStatus(String status)  {
         if (dictionary.containsKey(status)) {
             return dictionary.get(status).isString().stringValue();
         }
         else {
-            NotifyManager.getInstance().showError("Unknown status", "Can not 
find status " + 
+            NotifyManager.getInstance().showError("Unknown status", "Can not 
find status " +
                                                   status);
             return status;
         }
     }
-    
+
     @Override
     protected List<JSONObject> handleJsonResult(JSONValue result) {
         List<JSONObject> queueEntries = super.handleJsonResult(result);
@@ -52,14 +52,14 @@
             String status = queueEntry.get("status").isString().stringValue();
             String translation = translateStatus(status);
             queueEntry.put("status", new JSONString(translation));
-            
+
             boolean hasHost = (queueEntry.get("host").isNull() == null);
             boolean hasMetaHost = (queueEntry.get("meta_host").isNull() == 
null);
-            
+
             if (!hasHost && !hasMetaHost) {
                 queueEntry.put("hostname", new JSONString("(hostless)"));
                 rows.add(queueEntry);
-                
+
             } else if (!hasHost && hasMetaHost) {
                 // metahost
                 incrementMetaHostCount(metaHostEntries, queueEntry);
@@ -69,12 +69,12 @@
                 rows.add(queueEntry);
             }
         }
-        
+
         addMetaHostRows(metaHostEntries, rows);
-        
+
         return rows;
     }
-    
+
     protected void processHostData(JSONObject queueEntry) {
         JSONObject host = queueEntry.get("host").isObject();
         queueEntry.put("hostname", host.get("hostname"));
@@ -87,7 +87,7 @@
         }
     }
 
-    private void incrementMetaHostCount(Map<List<String>, JSONObject> 
metaHostEntries, 
+    private void incrementMetaHostCount(Map<List<String>, JSONObject> 
metaHostEntries,
                                         JSONObject queueEntry) {
         String label = queueEntry.get("meta_host").isString().stringValue();
         String status = queueEntry.get("status").isString().stringValue();
@@ -110,17 +110,17 @@
         // arrays don't hash correctly, so use a list instead
         return Arrays.asList(new String[] {label, status});
     }
-    
+
     private void addMetaHostRows(Map<List<String>, JSONObject> metaHostEntries,
                                  List<JSONObject> rows) {
         for (JSONObject entry : metaHostEntries.values()) {
             String label = Utils.jsonToString(entry.get("meta_host"));
             String status = Utils.jsonToString(entry.get("status"));
             int count = entry.get("id_list").isArray().size();
-            
+
             entry.put("hostname", new JSONString(label + " (label)"));
             entry.put("status", new JSONString(Integer.toString(count) + " " + 
status));
             rows.add(entry);
         }
     }
-}
\ No newline at end of file
+}
--- autotest/frontend/client/src/autotest/common/table/CheckboxFilter.java      
2010-05-26 16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/common/table/CheckboxFilter.java      
2010-05-26 16:30:23.000000000 -0700
@@ -10,12 +10,12 @@
 
 public abstract class CheckboxFilter extends FieldFilter implements 
ClickHandler {
     private CheckBox checkBox = new CheckBox();
-    
+
     public CheckboxFilter(String fieldName) {
         super(fieldName);
         checkBox.addClickHandler(this);
     }
-    
+
     public void onClick(ClickEvent event) {
         notifyListeners();
     }
@@ -29,8 +29,8 @@
     public boolean isActive() {
         return checkBox.getValue();
     }
-    
+
     public void setActive(boolean active) {
         checkBox.setValue(active);
     }
-}
\ No newline at end of file
+}
--- autotest/frontend/client/src/autotest/common/table/FieldFilter.java 
2010-05-26 16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/common/table/FieldFilter.java 
2010-05-26 16:30:23.000000000 -0700
@@ -6,22 +6,23 @@
 public abstract class FieldFilter extends Filter {
     protected String fieldName;
     protected boolean isExactMatch = true;
-    
+
     public FieldFilter(String fieldName) {
         this.fieldName = fieldName;
     }
-    
+
     public void setExactMatch(boolean exactMatch) {
         isExactMatch = exactMatch;
     }
-    
+
     public abstract JSONValue getMatchValue();
-    
+
     @Override
     public void addParams(JSONObject params) {
         String queryField = fieldName;
-        if (!isExactMatch)
+        if (!isExactMatch) {
             queryField += "__icontains";
+        }
         params.put(queryField, getMatchValue());
     }
-}
\ No newline at end of file
+}
--- autotest/frontend/client/src/autotest/common/table/Filter.java      
2010-05-26 16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/common/table/Filter.java      
2010-05-26 16:30:23.000000000 -0700
@@ -10,7 +10,7 @@
 
 public abstract class Filter {
     protected List<SimpleCallback> callbacks = new ArrayList<SimpleCallback>();
-    
+
     public abstract void addParams(JSONObject params);
     public abstract boolean isActive();
     public abstract Widget getWidget();
@@ -23,14 +23,14 @@
     public void addCallback(SimpleCallback callback) {
         callbacks.add(callback);
     }
-    
+
     public void removeCallback(SimpleCallback callback) {
         callbacks.remove(callback);
     }
-    
+
     protected void notifyListeners() {
         for (SimpleCallback callback : callbacks) {
             callback.doCallback(this);
         }
     }
-}
\ No newline at end of file
+}
--- 
autotest/frontend/client/src/autotest/common/table/JSONObjectComparator.java    
    2010-05-26 16:30:23.000000000 -0700
+++ 
autotest/frontend/client/src/autotest/common/table/JSONObjectComparator.java    
    2010-05-26 16:30:23.000000000 -0700
@@ -8,7 +8,7 @@
 
 public class JSONObjectComparator implements Comparator<JSONObject> {
     SortSpec[] sortSpecs;
-    
+
     public JSONObjectComparator(SortSpec[] specs) {
         sortSpecs = new SortSpec[specs.length];
         System.arraycopy(specs, 0, sortSpecs, 0, specs.length);
@@ -24,8 +24,8 @@
                 return compareValue;
             }
         }
-        
-        // the given sort keys were all equal, but we'll ensure we're 
consistent with 
+
+        // the given sort keys were all equal, but we'll ensure we're 
consistent with
         // JSONObject.equals()
         if (arg0.equals(arg1)) {
             return 0;
@@ -33,4 +33,4 @@
         // arbitrary (but consistent) ordering in this case
         return arg0.hashCode() > arg1.hashCode() ? 1 : -1;
     }
-}
\ No newline at end of file
+}
--- autotest/frontend/client/src/autotest/common/table/JSONObjectSet.java       
2010-05-26 16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/common/table/JSONObjectSet.java       
2010-05-26 16:30:23.000000000 -0700
@@ -9,21 +9,21 @@
 import java.util.Map;
 
 /**
- * Set that hashes JSONObjects by their ID, so that identical objects get 
+ * Set that hashes JSONObjects by their ID, so that identical objects get
  * matched together.
  */
 public class JSONObjectSet<T extends JSONObject> extends AbstractSet<T> {
     protected Map<String, T> backingMap = new HashMap<String, T>();
-    
+
     public JSONObjectSet() {
         super();
     }
-    
+
     public JSONObjectSet(Collection<T> items) {
         super();
         addAll(items);
     }
-    
+
     protected String getKey(Object obj) {
         return ((JSONObject) obj).get("id").toString();
     }
@@ -52,4 +52,4 @@
     public int size() {
         return backingMap.size();
     }
-}
\ No newline at end of file
+}
--- autotest/frontend/client/src/autotest/common/table/ListFilter.java  
2010-05-26 16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/common/table/ListFilter.java  
2010-05-26 16:30:23.000000000 -0700
@@ -104,4 +104,4 @@
     public void setEnabled(boolean enabled) {
         select.setEnabled(enabled);
     }
-}
\ No newline at end of file
+}
--- autotest/frontend/client/src/autotest/common/ui/SimpleDialog.java   
2010-05-26 16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/common/ui/SimpleDialog.java   
2010-05-26 16:30:23.000000000 -0700
@@ -14,13 +14,13 @@
 public class SimpleDialog extends DialogBox {
     public SimpleDialog(String title, Widget contents) {
         super(false, false);
-        
+
         FlexTable flex = new FlexTable();
         flex.setText(0, 0, title);
         flex.getFlexCellFormatter().setStylePrimaryName(0, 0, "field-name");
-        
+
         flex.setWidget(1, 0, contents);
-        
+
         Button ok = new Button("OK");
         ok.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent event) {
@@ -28,7 +28,7 @@
             }
         });
         flex.setWidget(2, 0, ok);
-        
+
         add(flex);
     }
-}
\ No newline at end of file
+}
--- autotest/frontend/client/src/autotest/tko/StatusSummary.java        
2010-05-26 16:30:23.000000000 -0700
+++ autotest/frontend/client/src/autotest/tko/StatusSummary.java        
2010-05-26 16:30:23.000000000 -0700
@@ -69,4 +69,4 @@
     protected int getPassed() {
         return passed;
     }
-}
\ No newline at end of file
+}
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to