ArrayList<LaserData> options = new ArrayList<LaserData>();
options.addAll(lasers);
Iterator<LaserData> iLasers = lasers.iterator();
while(iLasers.hasNext()) {
boolean compressed = false;
LaserData data = iLasers.next();
LPPosition next = new LPPosition(data.getPosX(), data.getPosY(), data.getPosZ());
next.moveForward(data.getDir(), data.getLength());
boolean found = false;
do {
found = false;
Iterator<LaserData> iOptions = options.iterator();
while(iOptions.hasNext()) {
LaserData d = iOptions.next();
if(d.getPosX() == next.getX() && d.getPosY() == next.getY() && d.getPosZ() == next.getZ()) {
if(data.getDir().equals(d.getDir()) && data.getConnectionType().equals(d.getConnectionType())) {
data.setLength(data.getLength() + d.getLength());
next.moveForward(data.getDir(), d.getLength());
found = true;
iOptions.remove();
lasers.remove(d);
compressed = true;
} else if(data.getDir().equals(d.getDir())) {
data.setFinalPipe(false);
}
}
}
} while (found);