From f884464e47de487e1bdb5beef6774aa0559a3cb9 Mon Sep 17 00:00:00 2001 From: Alois Zoitl Date: Mon, 8 Jan 2024 22:05:43 +0100 Subject: [PATCH] [Modernize Code] Fixed untyped generics in draw2d connection routers --- .../draw2d/BendpointConnectionRouter.java | 23 +++++++++---------- .../draw2d/ShortestPathConnectionRouter.java | 15 ++++++------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/BendpointConnectionRouter.java b/org.eclipse.draw2d/src/org/eclipse/draw2d/BendpointConnectionRouter.java index d0715a2eb..6896b4a3b 100644 --- a/org.eclipse.draw2d/src/org/eclipse/draw2d/BendpointConnectionRouter.java +++ b/org.eclipse.draw2d/src/org/eclipse/draw2d/BendpointConnectionRouter.java @@ -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 @@ -27,7 +27,7 @@ */ public class BendpointConnectionRouter extends AbstractRouter { - private Map constraints = new HashMap<>(11); + private final Map> constraints = new HashMap<>(11); private static final PrecisionPoint A_POINT = new PrecisionPoint(); @@ -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 getConstraint(Connection connection) { return constraints.get(connection); } @@ -63,7 +64,7 @@ public void route(Connection conn) { PointList points = conn.getPoints(); points.removeAllPoints(); - List bendpoints = (List) getConstraint(conn); + List bendpoints = getConstraint(conn); if (bendpoints == null) { bendpoints = Collections.emptyList(); } @@ -75,9 +76,9 @@ 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); } @@ -85,10 +86,7 @@ public void route(Connection conn) { 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); @@ -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 */ + @SuppressWarnings("unchecked") @Override public void setConstraint(Connection connection, Object constraint) { - constraints.put(connection, constraint); + constraints.put(connection, (List) constraint); } } diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/ShortestPathConnectionRouter.java b/org.eclipse.draw2d/src/org/eclipse/draw2d/ShortestPathConnectionRouter.java index adc39e16f..3e40567a4 100644 --- a/org.eclipse.draw2d/src/org/eclipse/draw2d/ShortestPathConnectionRouter.java +++ b/org.eclipse.draw2d/src/org/eclipse/draw2d/ShortestPathConnectionRouter.java @@ -53,7 +53,7 @@ public void setConstraint(IFigure child, Object constraint) { } } - private final Map constraintMap = new HashMap<>(); + private final Map> constraintMap = new HashMap<>(); private Map figuresToBounds; private Map connectionToPaths; private boolean isDirty; @@ -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 getConstraint(Connection connection) { return constraintMap.get(connection); } @@ -181,7 +182,7 @@ private void processStaleConnections() { algorithm.addPath(path); } - List constraint = (List) getConstraint(conn); + List constraint = getConstraint(conn); if (constraint == null) { constraint = Collections.emptyList(); } @@ -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); @@ -312,12 +310,13 @@ public List 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) constraint); isDirty = true; }