I have two state objects ( e1
and e2
) in Java. These have a list of key objects as an attribute that have an X position and a Y with their respective llave.getX()
, llave.getY()
. I want to check that these attributes of e1
and e2
have keys in the same positions or not, but being in different order I can not make a simple comparison.
if (i.getX()==j.getX() && i.getY()==j.getY()) { ... }
within:
for (Llave i : e1.llavesE) {
for (Llave j : e2.llavesE) {
/// COMPROBAR
}
}
With this algorithm:
boolean llaveaux = true;
for (Llave i : e1.llavesE) {
if (llaveaux) {
llaveaux = false;
for (Llave j : e2.llavesE) {
if (i.getX()==j.getX() && i.getY()==j.getY()) {
llaveaux = true;
break;
}
}
} else {
return false;
}
}
return true;
I thought that my problem would be solved, but no. Any idea how I can solve this? and why does not my second idea work?
Greetings and thank you very much :)