嘿,我现在在我的程序的最后润色中,我遇到了最奇怪的错误,基本上我正在比较两个都包含两个字符串的对象,所以我正在比较字符串的所有组合以查看对象是否相关通过一个共同的字符串。
它是用于 kruskals 循环检查器的,所以它比这更复杂一点,但这就是这个错误的基础,我添加了一些手动 system.out 调试,它告诉我最奇怪的事情,例如这是它的基础,它只是将 label1 与 label1 进行比较,但会重复 1 1 1 2 2 1 2 2
private static ArrayList<Graph> caseForConnection(
Connection consideredConnection, ArrayList<Graph> subTrees)
throws Exception {
ArrayList<Graph> ret = new ArrayList<Graph>();
System.out.println("Considering connection " +consideredConnection.getSaveDetails()[1] +consideredConnection.getSaveDetails()[2] + " "+consideredConnection.getSaveDetails()[3]);
String label1 = consideredConnection.getNode(1).getLabel();
String label2 = consideredConnection.getNode(2).getLabel();
for (Graph x : subTrees) {
for (Connection c : x.getConnectionList()) {
System.out.println("Comparing to connection "+ c.getSaveDetails()[1] +c.getSaveDetails()[2] +" " +c.getSaveDetails()[3]);
if (c.getNode(1)
.getLabel()
.equalsIgnoreCase(label1)) {
if (ret.contains(x)) {
System.out.print(("Found " + c.getNode(1)
.getLabel() +" is the same as " + label1+ " And this is twice"));
throw new Exception("Cycle Found");
}
System.out.print(("Found " + c.getNode(1)
.getLabel() +" is the same as " + label1));
ret.add(x);
} else if (c
.getNode(1)
.getLabel()
.equalsIgnoreCase(label2)) {
if (ret.contains(x)) {
System.out.print(("Found " + c.getNode(1)
.getLabel() +" is the same as " + label1+ " And this is twice"));
throw new Exception("Cycle Found");
}
System.out.print(("Found " + c.getNode(1)
.getLabel() +" is the same as " + label2));
ret.add(x);
}
if (c.getNode(2)
.getLabel()
.equalsIgnoreCase(label1)) {
if (ret.contains(x)) {
System.out.print(("Found " + c.getNode(1)
.getLabel() +" is the same as " + label1+ " And this is twice"));
throw new Exception("Cycle Found");
}
System.out.print(("Found " + c.getNode(2)
.getLabel() +" is the same as " + label1));
ret.add(x);
} else if (c
.getNode(2)
.getLabel()
.equalsIgnoreCase(label2)) {
if (ret.contains(x)) {
System.out.print(("Found " + c.getNode(1)
.getLabel() +" is the same as " + label1+ " And this is twice"));
throw new Exception("Cycle Found");
}
System.out.print(("Found " + c.getNode(2)
.getLabel() +" is the same as " + label2));
ret.add(x);
}
}
}
return ret;
}
现在奇怪的是,我的控制台输出了这个
找到 C 与 B 相同 找到 D 与 A 相同
通过连接 AC BC BD AD CG BF GF CF,其中 label1 为 a,第一个为 label 2 c,它只发生在这两个上,当然,给我一个无效的结果。