我正在做一个编程项目,我想将一些对象存储在一个列表中,但是我无法摆脱重复项。
这是我的对象
nd = nodeAddress16=0x10,0x03, nodeAddress64=0x00,0x13,0xa2,0x00,0x40,0x6f,0x8d,0xfc, rssi=-47, nodeIdentifier= [0x10,0x03]
代码在线程内,所以代码是循环的。
private void handleAtCommandResponse(XBeeResponse response) {
//TODO Implement your code here, to handle particular AT command responses, if desired.
System.out.println("NetworkNode: Received AT Response:"+((AtCommandResponse)response).getCommand());
if (response.getApiId() == ApiId.AT_RESPONSE) {
NodeDiscover nd = NodeDiscover.parse((AtCommandResponse)response);
System.out.println("Node discover response is: " + nd);
nodeDiscoverList.add(nd); //add to list, but gives duplicates of nd.
//add to list if not already in it
//if already in list replace that object with the new object
//duplicate objects are not allowed ==> only one object in the list can contain a specific address.
// Only addresses are static values, other values may change over time.
}
else {
log.debug("Ignoring unexpected response: " + response);
}
}