Skip to content

Commit

Permalink
[Modernize Code] Fixed untyped generics in draw2d connection routers
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl authored and ptziegler committed Jan 10, 2024
1 parent fd75841 commit f884464
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -27,7 +27,7 @@
*/
public class BendpointConnectionRouter extends AbstractRouter {

private Map<Connection, Object> constraints = new HashMap<>(11);
private final Map<Connection, List<Bendpoint>> constraints = new HashMap<>(11);

private static final PrecisionPoint A_POINT = new PrecisionPoint();

Expand All @@ -36,9 +36,10 @@ public class BendpointConnectionRouter extends AbstractRouter {
*
* @param connection The connection whose constraint we are retrieving
* @return The constraint
* @since 3.15
*/
@Override
public Object getConstraint(Connection connection) {
public List<Bendpoint> getConstraint(Connection connection) {
return constraints.get(connection);
}

Expand All @@ -63,7 +64,7 @@ public void route(Connection conn) {
PointList points = conn.getPoints();
points.removeAllPoints();

List bendpoints = (List) getConstraint(conn);
List<Bendpoint> bendpoints = getConstraint(conn);
if (bendpoints == null) {
bendpoints = Collections.emptyList();
}
Expand All @@ -75,20 +76,17 @@ public void route(Connection conn) {
ref1 = conn.getTargetAnchor().getReferencePoint();
ref2 = conn.getSourceAnchor().getReferencePoint();
} else {
ref1 = new Point(((Bendpoint) bendpoints.get(0)).getLocation());
ref1 = new Point(bendpoints.get(0).getLocation());
conn.translateToAbsolute(ref1);
ref2 = new Point(((Bendpoint) bendpoints.get(bendpoints.size() - 1)).getLocation());
ref2 = new Point(bendpoints.get(bendpoints.size() - 1).getLocation());
conn.translateToAbsolute(ref2);
}

A_POINT.setLocation(conn.getSourceAnchor().getLocation(ref1));
conn.translateToRelative(A_POINT);
points.addPoint(A_POINT);

for (Object bendpoint : bendpoints) {
Bendpoint bp = (Bendpoint) bendpoint;
points.addPoint(bp.getLocation());
}
bendpoints.forEach(bp -> points.addPoint(bp.getLocation()));

A_POINT.setLocation(conn.getTargetAnchor().getLocation(ref2));
conn.translateToRelative(A_POINT);
Expand All @@ -100,11 +98,12 @@ public void route(Connection conn) {
* Sets the constraint for the given {@link Connection}.
*
* @param connection The connection whose constraint we are setting
* @param constraint The constraint
* @param constraint The constraint, which as to be a List<Bendpoint>
*/
@SuppressWarnings("unchecked")
@Override
public void setConstraint(Connection connection, Object constraint) {
constraints.put(connection, constraint);
constraints.put(connection, (List<Bendpoint>) constraint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setConstraint(IFigure child, Object constraint) {
}
}

private final Map<Connection, Object> constraintMap = new HashMap<>();
private final Map<Connection, List<Bendpoint>> constraintMap = new HashMap<>();
private Map<IFigure, Rectangle> figuresToBounds;
private Map<Connection, Path> connectionToPaths;
private boolean isDirty;
Expand Down Expand Up @@ -128,9 +128,10 @@ private void unhookAll() {
*
* @param connection The connection whose constraint we are retrieving
* @return The constraint
* @since 3.15
*/
@Override
public Object getConstraint(Connection connection) {
public List<Bendpoint> getConstraint(Connection connection) {
return constraintMap.get(connection);
}

Expand Down Expand Up @@ -181,7 +182,7 @@ private void processStaleConnections() {
algorithm.addPath(path);
}

List constraint = (List) getConstraint(conn);
List<Bendpoint> constraint = getConstraint(conn);
if (constraint == null) {
constraint = Collections.emptyList();
}
Expand All @@ -197,10 +198,7 @@ private void processStaleConnections() {

if (!constraint.isEmpty()) {
PointList bends = new PointList(constraint.size());
for (Object element : constraint) {
Bendpoint bp = (Bendpoint) element;
bends.addPoint(bp.getLocation());
}
constraint.forEach(bp -> bends.addPoint(bp.getLocation()));
path.setBendPoints(bends);
} else {
path.setBendPoints(null);
Expand Down Expand Up @@ -312,12 +310,13 @@ public List<Path> getPathsAfterRouting() {
/**
* @see ConnectionRouter#setConstraint(Connection, Object)
*/
@SuppressWarnings("unchecked")
@Override
public void setConstraint(Connection connection, Object constraint) {
// Connection.setConstraint() already calls revalidate, so we know that a
// route() call will follow.
staleConnections.add(connection);
constraintMap.put(connection, constraint);
constraintMap.put(connection, (List<Bendpoint>) constraint);
isDirty = true;
}

Expand Down

0 comments on commit f884464

Please sign in to comment.