1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2003, 2010 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
package org.eclipse.draw2d.graph;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
|
15
|
/**
|
16
|
* A list of <code>Edge</code>s.
|
17
|
*
|
18
|
* @author hudsonr
|
19
|
* @since 2.1.2
|
20
|
*/
|
21
|
public class EdgeList extends ArrayList {
|
22
|
|
23
|
/**
|
24
|
* Returns the edge for the given index.
|
25
|
*
|
26
|
* @param index
|
27
|
* the index of the requested edge
|
28
|
* @return the edge at the given index
|
29
|
*/
|
30
|
public Edge getEdge(int index) {
|
31
|
return (Edge) super.get(index);
|
32
|
}
|
33
|
|
34
|
/**
|
35
|
* For intrenal use only.
|
36
|
*
|
37
|
* @param i
|
38
|
* and index
|
39
|
* @return a value
|
40
|
*/
|
41
|
public int getSourceIndex(int i) {
|
42
|
return getEdge(i).source.index;
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* For internal use only.
|
47
|
*
|
48
|
* @param i
|
49
|
* an index
|
50
|
* @return a value
|
51
|
*/
|
52
|
public int getTargetIndex(int i) {
|
53
|
return getEdge(i).target.index;
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* For internal use only.
|
58
|
*
|
59
|
* @return the minimum slack for this edge list
|
60
|
*/
|
61
|
public int getSlack() {
|
62
|
int slack = Integer.MAX_VALUE;
|
63
|
for (int i = 0; i < this.size(); i++)
|
64
|
slack = Math.min(slack, getEdge(i).getSlack());
|
65
|
return slack;
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* For internal use only.
|
70
|
*
|
71
|
* @return the total weight of all edges
|
72
|
*/
|
73
|
public int getWeight() {
|
74
|
int w = 0;
|
75
|
for (int i = 0; i < this.size(); i++)
|
76
|
w += getEdge(i).weight;
|
77
|
return w;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* For internal use only
|
82
|
*
|
83
|
* @return <code>true</code> if completely flagged
|
84
|
*/
|
85
|
public boolean isCompletelyFlagged() {
|
86
|
for (int i = 0; i < size(); i++) {
|
87
|
if (!getEdge(i).flag)
|
88
|
return false;
|
89
|
}
|
90
|
return true;
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* For internal use only. Resets all flags.
|
95
|
*
|
96
|
* @param resetTree
|
97
|
* internal
|
98
|
*/
|
99
|
public void resetFlags(boolean resetTree) {
|
100
|
for (int i = 0; i < size(); i++) {
|
101
|
getEdge(i).flag = false;
|
102
|
if (resetTree)
|
103
|
getEdge(i).tree = false;
|
104
|
}
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* For internal use only.
|
109
|
*
|
110
|
* @param value
|
111
|
* value
|
112
|
*/
|
113
|
public void setFlags(boolean value) {
|
114
|
for (int i = 0; i < size(); i++)
|
115
|
getEdge(i).flag = value;
|
116
|
}
|
117
|
|
118
|
}
|