I have two sets, I need to compare them using some entity inside the set.
Set<Node> appNodes = Sets.newHashSet(PropertyUtils.getInstance().getListOfAppNodes());
Set<Node> dataNodes = Sets.newHashSet(PropertyUtils.getInstance().getListOfDataNodes());
Set<Node> nodes = new HashSet<>();
Node POJO
public class Node {
String hostName;
String ip;
String userName;
String passWord;
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
}
I need to compare the two sets using ip and add them in nodes Set.
nodes.addAll(appNodes);
nodes.addAll(dataNodes);
When trying to doi it like in the above code, I get all the data from appnode set and datanode set, but I want to compare the ip in appnode set and datanode set, if they aren't the same I only need to add them in the new set.