tmf.ui: replace size()==0 with isEmpty()
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 19 Dec 2016 15:13:46 +0000 (10:13 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 19 Dec 2016 20:41:13 +0000 (15:41 -0500)
Changes CustomTxtParserInputWizardPage to better handle checks. Size is
not guaranteed to be O(1) whereas isEmpty() is.

Change-Id: I5646fa6fd019bcfb14697d748170462c38fd099b
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/87412
Reviewed-by: Marc-André Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-André Laperle <marc-andre.laperle@ericsson.com>
Reviewed-by: Hudson CI
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserInputWizardPage.java

index 3cf746d5632036b3bff6be20072e6eee6ddc6d24..76a738379d9bd812bae809a03f2b5aa127abfbe3 100644 (file)
@@ -279,7 +279,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$
-                if (((List<?>) treeViewer.getInput()).size() == 0) {
+                if (((List<?>) treeViewer.getInput()).isEmpty()) {
                     definition.inputs.add(inputLine);
                 } else if (treeViewer.getSelection().isEmpty()) {
                     return;
@@ -306,7 +306,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$
-                if (((List<?>) treeViewer.getInput()).size() == 0) {
+                if (((List<?>) treeViewer.getInput()).isEmpty()) {
                     definition.inputs.add(inputLine);
                 } else if (treeViewer.getSelection().isEmpty()) {
                     return;
@@ -497,7 +497,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
         @Override
         public boolean hasChildren(Object element) {
             InputLine inputLine = (InputLine) element;
-            return (inputLine.childrenInputs != null && inputLine.childrenInputs.size() > 0);
+            return (inputLine.childrenInputs != null && !inputLine.childrenInputs.isEmpty());
         }
 
         @Override
@@ -569,7 +569,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             timestampOutputFormatText.setText(""); //$NON-NLS-1$
         }
         treeViewer.setInput(def.inputs);
-        if (def.inputs.size() > 0) {
+        if (!def.inputs.isEmpty()) {
             InputLine inputLine = def.inputs.get(0);
             treeViewer.setSelection(new StructuredSelection(inputLine));
         }
@@ -733,7 +733,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                         }
                         HashMap<InputLine, Integer> countMap = new HashMap<>();
                         InputLine currentInput = null;
-                        if (rootInputLine.childrenInputs != null && rootInputLine.childrenInputs.size() > 0) {
+                        if (rootInputLine.childrenInputs != null && !rootInputLine.childrenInputs.isEmpty()) {
                             currentInput = rootInputLine.childrenInputs.get(0);
                             countMap.put(currentInput, 0);
                         }
@@ -757,7 +757,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                             } else {
                                 if (checkNotNull(countMap.get(currentInput)) >= currentInput.getMinCount()) {
                                     List<InputLine> nextInputs = currentInput.getNextInputs(countMap);
-                                    if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {
+                                    if (nextInputs.isEmpty() || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {
                                         for (InputLine input : definition.inputs) {
                                             try {
                                                 matcher = input.getPattern().matcher(log);
@@ -792,12 +792,12 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                                                     iter.remove();
                                                 }
                                             }
-                                            if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
+                                            if (currentInput.childrenInputs != null && !currentInput.childrenInputs.isEmpty()) {
                                                 currentInput = currentInput.childrenInputs.get(0);
                                                 countMap.put(currentInput, 0);
                                             } else {
                                                 if (checkNotNull(countMap.get(currentInput)) >= currentInput.getMaxCount()) {
-                                                    if (currentInput.getNextInputs(countMap).size() > 0) {
+                                                    if (!currentInput.getNextInputs(countMap).isEmpty()) {
                                                         currentInput = currentInput.getNextInputs(countMap).get(0);
                                                         if (countMap.get(currentInput) == null) {
                                                             countMap.put(currentInput, 0);
@@ -830,12 +830,12 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                                                 COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));
                                         updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);
                                         countMap.put(currentInput, checkNotNull(countMap.get(currentInput)) + 1);
-                                        if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
+                                        if (currentInput.childrenInputs != null && !currentInput.childrenInputs.isEmpty()) {
                                             currentInput = currentInput.childrenInputs.get(0);
                                             countMap.put(currentInput, 0);
                                         } else {
                                             if (checkNotNull(countMap.get(currentInput)) >= currentInput.getMaxCount()) {
-                                                if (currentInput.getNextInputs(countMap).size() > 0) {
+                                                if (!currentInput.getNextInputs(countMap).isEmpty()) {
                                                     currentInput = currentInput.getNextInputs(countMap).get(0);
                                                     if (countMap.get(currentInput) == null) {
                                                         countMap.put(currentInput, 0);
This page took 0.027058 seconds and 5 git commands to generate.