From 473d89deb81774a24cffd2503ea58616e2f730d7 Mon Sep 17 00:00:00 2001 From: Jean-Christian Kouame Date: Wed, 30 Sep 2015 17:11:55 -0400 Subject: [PATCH] tmf : extract duplicate code into sortNodes() in GraphNode Change-Id: I6309676ab960c0791bb8b0ce39d44951a8ed3075 Signed-off-by: Jean-Christian Kouame Reviewed-on: https://git.eclipse.org/r/57246 Reviewed-by: Matthew Khouzam Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- .../tmf/ui/views/uml2sd/core/GraphNode.java | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/uml2sd/core/GraphNode.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/uml2sd/core/GraphNode.java index 965da7e142..1a77048dbe 100755 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/uml2sd/core/GraphNode.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/uml2sd/core/GraphNode.java @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -104,10 +103,8 @@ public abstract class GraphNode { return; } - Iterator it = fIndexes.keySet().iterator(); - while (it.hasNext()) { - String nodeType = it.next(); - fIndexes.put(nodeType, Integer.valueOf(0)); + for (Map.Entry entry : fIndexes.entrySet()) { + entry.setValue(Integer.valueOf(0)); } } @@ -634,35 +631,16 @@ public abstract class GraphNode { } // If the nodes have not been added ordered, the array is ordered for (Map.Entry entry : fForwardSort.entrySet()) { - String nodeType = entry.getKey(); boolean sort = entry.getValue().booleanValue(); if (sort) { - List forwardNodes = checkNotNull(fForwardNodes.get(nodeType)); - GraphNode[] temp = forwardNodes.toArray(new GraphNode[forwardNodes.size()]); - GraphNode node = checkNotNull(fNodes.get(nodeType)).get(0); - Arrays.sort(temp, node.getComparator()); - entry.setValue(Boolean.FALSE); - fNodes.put(nodeType, Arrays.asList(temp)); - fForwardNodes.put(nodeType, Arrays.asList(temp)); - if (TmfUiTracer.isSortingTraced()) { - TmfUiTracer.traceSorting(nodeType + " array sorted\n"); //$NON-NLS-1$ - } + sortNodes(fForwardNodes, entry, true); } } for (Map.Entry entry : fBackwardSort.entrySet()) { - String nodeType = entry.getKey(); boolean sort = entry.getValue().booleanValue(); if (sort) { - List backwardNodes = checkNotNull(fBackwardNodes.get(nodeType)); - GraphNode[] temp = backwardNodes.toArray(new GraphNode[backwardNodes.size()]); - GraphNode node = checkNotNull(fNodes.get(nodeType)).get(0); - Arrays.sort(temp, node.getBackComparator()); - entry.setValue(Boolean.FALSE); - fBackwardNodes.put(nodeType, Arrays.asList(temp)); - if (TmfUiTracer.isSortingTraced()) { - TmfUiTracer.traceSorting(nodeType + " back array sorted\n"); //$NON-NLS-1$ - } + sortNodes(fBackwardNodes, entry, false); } } @@ -676,10 +654,9 @@ public abstract class GraphNode { } int count = 0; - Iterator it3 = fForwardSort.keySet().iterator(); - while (it3.hasNext()) { + for (Map.Entry entry : fForwardSort.entrySet()) { count = 0; - Object nodeType = it3.next(); + String nodeType = entry.getKey(); GraphNode node = checkNotNull(fNodes.get(nodeType)).get(0); context.setFont(SDViewPref.getInstance().getFont(node.fPrefId)); int index = checkNotNull(fIndexes.get(nodeType)).intValue(); @@ -694,6 +671,23 @@ public abstract class GraphNode { } + private void sortNodes(Map> nodesToSort, Map.Entry sortMapEntry, boolean forward) { + String nodeType = sortMapEntry.getKey(); + GraphNode[] temp = nodesToSort.get(nodeType).toArray(new GraphNode[nodesToSort.get(nodeType).size()]); + GraphNode node = fNodes.get(nodeType).get(0); + if (forward) { + Arrays.sort(temp, node.getComparator()); + fNodes.put(nodeType, Arrays.asList(temp)); + } else { + Arrays.sort(temp, node.getBackComparator()); + } + nodesToSort.put(nodeType, Arrays.asList(temp)); + sortMapEntry.setValue(Boolean.FALSE); + if (TmfUiTracer.isSortingTraced()) { + TmfUiTracer.traceSorting(nodeType + " array sorted\n"); //$NON-NLS-1$ + } + } + /** * Draw the GraphNode stored in the given list, starting at index startIndex with the given step * -- 2.34.1