Skip to content

Commit

Permalink
[Modernize Code] Use typed generics for EdgeList
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl committed Aug 13, 2023
1 parent ad59455 commit 581e792
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/graph/EdgeList.java
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 @@ -14,100 +14,93 @@

/**
* A list of <code>Edge</code>s.
*
*
* @author hudsonr
* @since 2.1.2
*/
public class EdgeList extends ArrayList {
public class EdgeList extends ArrayList<Edge> {

/**
* Returns the edge for the given index.
*
*
* @param index the index of the requested edge
* @return the edge at the given index
*
* @deprecated use Use {@link #get(int)} instead.
*/
@Deprecated(since = "3.13.100", forRemoval = true)
public Edge getEdge(int index) {
return (Edge) super.get(index);
return super.get(index);
}

/**
* For intrenal use only.
*
*
* @param i and index
* @return a value
*/
public int getSourceIndex(int i) {
return getEdge(i).source.index;
return get(i).source.index;
}

/**
* For internal use only.
*
*
* @param i an index
* @return a value
*/
public int getTargetIndex(int i) {
return getEdge(i).target.index;
return get(i).target.index;
}

/**
* For internal use only.
*
*
* @return the minimum slack for this edge list
*/
public int getSlack() {
int slack = Integer.MAX_VALUE;
for (int i = 0; i < this.size(); i++)
slack = Math.min(slack, getEdge(i).getSlack());
return slack;
return stream().mapToInt(Edge::getSlack).min().orElse(Integer.MAX_VALUE);
}

/**
* For internal use only.
*
*
* @return the total weight of all edges
*/
public int getWeight() {
int w = 0;
for (int i = 0; i < this.size(); i++)
w += getEdge(i).weight;
return w;
return stream().mapToInt(e -> e.weight).sum();
}

/**
* For internal use only
*
*
* @return <code>true</code> if completely flagged
*/
public boolean isCompletelyFlagged() {
for (int i = 0; i < size(); i++) {
if (!getEdge(i).flag)
return false;
}
return true;
return stream().allMatch(e -> e.flag);
}

/**
* For internal use only. Resets all flags.
*
*
* @param resetTree internal
*/
public void resetFlags(boolean resetTree) {
for (int i = 0; i < size(); i++) {
getEdge(i).flag = false;
if (resetTree)
getEdge(i).tree = false;
}
forEach(e -> {
e.flag = false;
if (resetTree) {
e.tree = false;
}
});
}

/**
* For internal use only.
*
*
* @param value value
*/
public void setFlags(boolean value) {
for (int i = 0; i < size(); i++)
getEdge(i).flag = value;
forEach(e -> e.flag = value);
}

}

0 comments on commit 581e792

Please sign in to comment.