Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typify internal list in DirectGraphLayout and convert to Deque #247

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
package org.eclipse.draw2d.test;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;

import org.eclipse.draw2d.graph.DirectedGraph;
import org.eclipse.draw2d.graph.DirectedGraphLayout;
Expand Down Expand Up @@ -146,10 +147,9 @@ private static DirectedGraphLayout createDirectedGraphLayoutWithSelectedStepOnly
DirectedGraphLayout layout = new DirectedGraphLayout();
Field stepsField = DirectedGraphLayout.class.getDeclaredField("steps"); //$NON-NLS-1$
stepsField.setAccessible(true);
ArrayList steps = (ArrayList) stepsField.get(layout);
ArrayList filteredSteps = new ArrayList();
for (int i = 0; i < steps.size(); i++) {
Object graphVisitor = steps.get(i);
Deque<?> steps = (Deque<?>) stepsField.get(layout);
Deque<Object> filteredSteps = new ArrayDeque<>();
for (Object graphVisitor : steps) {
for (String graphVisitorClassName : graphVisitorClassNames) {
if (graphVisitorClassName.equals(graphVisitor.getClass().getName())) {
filteredSteps.add(graphVisitor);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2010 IBM Corporation and others.
* Copyright (c) 2003, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -10,8 +10,8 @@
*******************************************************************************/
package org.eclipse.draw2d.graph;

import java.util.ArrayList;
import java.util.List;
import java.util.ArrayDeque;
import java.util.Deque;

/**
* Performs a graph layout of a <code>DirectedGraph</code>. The directed graph
Expand Down Expand Up @@ -70,7 +70,7 @@
*/
public class DirectedGraphLayout {

List steps = new ArrayList();
Deque<GraphVisitor> steps = new ArrayDeque<>();

/**
* @since 3.1
Expand Down Expand Up @@ -101,14 +101,8 @@ void init() {
public void visit(DirectedGraph graph) {
if (graph.nodes.isEmpty())
return;
for (int i = 0; i < steps.size(); i++) {
GraphVisitor visitor = (GraphVisitor) steps.get(i);
visitor.visit(graph);
}
for (int i = steps.size() - 1; i >= 0; i--) {
GraphVisitor visitor = (GraphVisitor) steps.get(i);
visitor.revisit(graph);
}
steps.iterator().forEachRemaining(visitor -> visitor.visit(graph));
steps.descendingIterator().forEachRemaining(visitor -> visitor.revisit(graph));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2005, CHISEL Group, University of Victoria, Victoria, BC, Canada.
* Copyright 2005, 2023 CHISEL Group, University of Victoria, Victoria, BC, Canada.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
Expand All @@ -10,9 +10,9 @@
package org.eclipse.zest.layouts.algorithms;

import java.lang.reflect.Field;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.graph.DirectedGraph;
Expand All @@ -34,20 +34,14 @@ public void visit(DirectedGraph graph) {
field = DirectedGraphLayout.class.getDeclaredField("steps");
azoitl marked this conversation as resolved.
Show resolved Hide resolved
field.setAccessible(true);
Object object = field.get(this);
List steps = (List) object;
Deque<?> steps = (Deque<?>) object;
steps.remove(10);
steps.remove(9);
steps.remove(8);
steps.remove(2);
field.setAccessible(false);
super.visit(graph);
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (SecurityException | ReflectiveOperationException | IllegalArgumentException e) {
e.printStackTrace();
}
}
Expand Down