// maybe without startV
List connectedVertices = sg.getVertices();
SimpleVertex tempV;
SimpleVertex otherV;
SimpleEdge tempE;
int i = 0;
List edges;
boolean flag;
boolean hasUnusedEdges;
boolean alreadyVisited = false;
int subGraphNumber = 1;
LinkedList nodeStack = new LinkedList();
LinkedList edgeStack = new LinkedList();
ListIterator li = connectedVertices.listIterator();
while (li.hasNext()) {
SimpleVertex v = (SimpleVertex) li.next();
v.setProperty(DFSNUM_KEY,
new Integer(0));
v.setProperty(ISOLD_KEY, Boolean.FALSE);
v.setProperty(LOWNUM_KEY,
new Integer(0));
v.setProperty(SUBGRAPH_KEY,
new Integer(0));
}
edges = sg.getEdges();
li = edges.listIterator();
while (li.hasNext()) {
SimpleEdge e = (SimpleEdge) li.next();
e.setProperty(ISUSED_KEY, Boolean.FALSE);
e.setProperty(ESUBGRAPH_KEY,
new Integer(0));
e.setProperty(WASADDED_KEY, Boolean.FALSE);
}
tempV = (SimpleVertex) connectedVertices.get(0);
do {
if (!alreadyVisited) {
i++;
tempV.setProperty(DFSNUM_KEY,
new Integer(i));
tempV.setProperty(LOWNUM_KEY,
new Integer(i));
nodeStack.addLast(tempV);
}
li = tempV.getEdgesRelative(sg)
.listIterator();
flag = false;
hasUnusedEdges = false;
alreadyVisited = false;
while (li.hasNext()) {
tempE = (SimpleEdge) li.next();
if (!tempE.getBooleanProperty(ISUSED_KEY)) {
tempE.setProperty(ISUSED_KEY, Boolean.TRUE);
tempE.setProperty(WASADDED_KEY, Boolean.TRUE);
edgeStack.addLast(tempE);
hasUnusedEdges = true;
otherV = tempE.getAnother(tempV);
if (otherV.getIntProperty(DFSNUM_KEY) == 0) {
otherV.setProperty(PARENT_KEY, tempV);
tempV = otherV;
} else {
tempV.setProperty(LOWNUM_KEY,
new Integer(Math.min(
tempV.getIntProperty(LOWNUM_KEY),
otherV.getIntProperty(DFSNUM_KEY))));
alreadyVisited = true;
}
break;
}
}
if (!hasUnusedEdges) {
if (tempV.getVertexProperty(PARENT_KEY)
.getIntProperty(DFSNUM_KEY) != 1) {
if (tempV.getIntProperty(LOWNUM_KEY) < tempV.getVertexProperty(PARENT_KEY)
.getIntProperty(DFSNUM_KEY)) {
tempV.getVertexProperty(PARENT_KEY)
.setProperty(LOWNUM_KEY,
new Integer(Math.min(
tempV.getVertexProperty(PARENT_KEY).getIntProperty(LOWNUM_KEY),
tempV.getIntProperty(LOWNUM_KEY))));
} else {
while (nodeStack.getLast() != tempV) {
((SimpleVertex) nodeStack.removeLast()).setProperty(SUBGRAPH_KEY,
new Integer(subGraphNumber));
}
if (nodeStack.getLast() == tempV) {
((SimpleVertex) nodeStack.removeLast()).setProperty(SUBGRAPH_KEY,
new Integer(subGraphNumber));
}
while (((SimpleEdge) edgeStack.getLast()).getAnother(tempV) != tempV
.getVertexProperty(PARENT_KEY)) {
tempE = (SimpleEdge) edgeStack.removeLast();
tempE.setProperty(WASADDED_KEY,
Boolean.valueOf(false));
tempE.setProperty(ESUBGRAPH_KEY,
new Integer(subGraphNumber));
}
if (((SimpleEdge) edgeStack.getLast()).getAnother(tempV) == tempV
.getVertexProperty(PARENT_KEY)) {
tempE = (SimpleEdge) edgeStack.removeLast();
tempE.setProperty(WASADDED_KEY,
Boolean.valueOf(false));
tempE.setProperty(ESUBGRAPH_KEY,
new Integer(subGraphNumber));
}
subGraphNumber++;
if ((tempV.getVertexProperty(PARENT_KEY) == null)
|| !(tempV.getVertexProperty(PARENT_KEY).getBooleanProperty(ISOLD_KEY))) {
tempV.getVertexProperty(PARENT_KEY)
.setProperty(SUBGRAPH_KEY,
new Integer(0));
tempV.getVertexProperty(PARENT_KEY)
.setProperty(ISOLD_KEY,
Boolean.valueOf(true));
separatingVertices.add(tempV.getVertexProperty(PARENT_KEY));
}
}
tempV = tempV.getVertexProperty(PARENT_KEY);
alreadyVisited = true;
flag = true;
}
if (!flag) {
while (nodeStack.getLast() != tempV) {
((SimpleVertex) nodeStack.removeLast()).setProperty(SUBGRAPH_KEY,
new Integer(subGraphNumber));
}
if (nodeStack.getLast() == tempV) {
((SimpleVertex) nodeStack.removeLast()).setProperty(SUBGRAPH_KEY,
new Integer(subGraphNumber));
}
((SimpleVertex) connectedVertices.get(0)).setProperty(SUBGRAPH_KEY,
new Integer(subGraphNumber));
;
while (((SimpleEdge) edgeStack.getLast()).getAnother(tempV) != (SimpleVertex) connectedVertices
.get(0)) {
tempE = (SimpleEdge) edgeStack.removeLast();
tempE.setProperty(WASADDED_KEY,
Boolean.valueOf(false));
tempE.setProperty(ESUBGRAPH_KEY,
new Integer(subGraphNumber));
}
if (((SimpleEdge) edgeStack.getLast()).getAnother(tempV) == (SimpleVertex) connectedVertices
.get(0)) {
tempE = (SimpleEdge) edgeStack.removeLast();
tempE.setProperty(WASADDED_KEY,
Boolean.valueOf(false));
tempE.setProperty(ESUBGRAPH_KEY,
new Integer(subGraphNumber));
}
subGraphNumber++;
ListIterator enum2 =
((SimpleVertex) connectedVertices
.get(0)).getEdgesRelative(sg)
.listIterator();
boolean flag2 = false;
while (enum2.hasNext()) {
SimpleEdge element = (SimpleEdge) enum2.next();
if (!element.getBooleanProperty(ISUSED_KEY)) {
flag2 = true;
}
}
if (!flag2) {