我创建自定义节点,左侧有一个圆圈,右侧有一个圆圈。
每次我连接两个节点时,我想将Boolean left
或Boolean right
设置为true。当我将两个节点连接到一个节点时,我想将Boolean right
和left
都设置为true。目前我添加了多个条目,但没有更新我的Generics内容。
我的代码:
public static List<NodeList<Boolean,Boolean,String>> connectList = new ArrayList<NodeList<Boolean,Boolean,String>>();
private String linkedNodeID;
private Boolean right = false;
private Boolean left = false;
和实际的代码,这里是我在leftTrue()
/ rightTrue()
内添加总是犯了实际错误的地方:
public void leftTrue(){
left = true;
connectList.add(new NodeList<Boolean, Boolean, String>(left, right, linkedNodeID));
}
public void rightTrue(){
right = true;
connectList.add(new NodeList<Boolean, Boolean, String>(left, right, linkedNodeID));
}
我得到的是:
right connected: false ,left connected: true ,ID: 81def74e-4cb6-428c-b7ca-a57279534814
right connected: true ,left connected: false ,ID: 46514df2-da7a-41e0-bdd7-43e6f15b4220
right connected: true ,left connected: true ,ID: 46514df2-da7a-41e0-bdd7-43e6f15b4220
right connected: true ,left connected: false ,ID: 2e85f320-43cf-4d83-8670-4e917f31cd25
我想要的是:
right connected: false ,left connected: true ,ID: 81def74e-4cb6-428c-b7ca-a57279534814
right connected: true ,left connected: true ,ID: 46514df2-da7a-41e0-bdd7-43e6f15b4220
right connected: true ,left connected: false ,ID: 2e85f320-43cf-4d83-8670-4e917f31cd25
如何设置左/右连接而不在我的列表中添加其他条目?
修改
public void registerSource(String linkId, DragNode linkNode) {
linkedNodeID = linkNode.getId();
double nodeWidth1 = linkNode.getWidth()/2;
if(DragNode.linkNodeOneX <= nodeWidth1){
leftTrue();
}else{
rightTrue();
}
}
public void registerTarget(String linkId, DragNode linkNode) {
linkedNodeID = linkNode.getId();
double nodeWidth2 = linkNode.getWidth()/2;
if( DragNode.linkNodeTwoX < nodeWidth2){
leftTrue();
testprint();
}else{
rightTrue();
}
}
EDIT2:
我的问题是,当我致电leftTrue();
时,我会创建一个新的connectList.add(new NodeList<Boolean, Boolean, String>(left, right, linkedNodeID));
条目,但如果我的列表中已有ID,则应更新left
或{{1} }。有任何想法吗?与right
类似,如果这等于另一个ID,则只需设置connectList.get(i).getL();
EDIT3:
right/false = true;
答案 0 :(得分:1)
存储这些左右值,并在确定它们是左,右还是两者之后,仅使用它们创建一个新节点。
if( DragNode.linkNodeTwoX < nodeWidth2){
leftTrue();
}else{
rightTrue();
}
if(left || right){
connectList.add(new NodeList<Boolean, Boolean, String>(left, right, linkedNodeID));
left = false;
right = false;
}
public void leftTrue(){
left = true;
}
public void rightTrue(){
right = true;
}
答案 1 :(得分:0)
我通过更新leftTrue()和rightTrue()方法使其工作:
public void leftTrue(){
left = true;
//if the function is rightTrue() then set right = true;
if(left && right){
String testID = self.getId();
for(int i = 0; i < connectList.size(); i++){
String testID2 = connectList.get(i).getL();
if(testID == testID2){
left = true;
right = true;
connectList.get(i).setT(left);
connectList.get(i).setI(right);
}
}
}else{
connectList.add(new NodeList<Boolean, Boolean, String>(left, right, linkedNodeID));
}
}
然后我的输出只有三个唯一的ID,左/右是正确的:
right connected: false ,left connected: true ,ID: 6036bf0c-c514-454e-abbb-c9298800a585, listsize 3
right connected: true ,left connected: true ,ID: b78abcb8-a940-44e7-9429-11006b54dc79, listsize 3
right connected: true ,left connected: false ,ID: b3188490-2183-44ee-8fc6-5af0309766a8, listsize 3