problem with contains in ArrayList
in
Library and Tool Development
•
10 months ago
I can't post all code so i hope someone still have a clue what it might be.
I have a path and a selection tool to select anchors.
If i hold shift i want a toggle selection.
For debugging i print A, B, C etc. at serveral steps.
If i select a anchor, and then select it again while holding shift then it prints
A and B are correct.
howver, there is this line:
I only don't understand how that can be.
An ArrayList holds a reference right...
anyone a clue?
I have a path and a selection tool to select anchors.
If i hold shift i want a toggle selection.
For debugging i print A, B, C etc. at serveral steps.
- public void handleReleased(float x, float y) {
- if(startX != x || startY != y) {
- // rectangular selection
- float x1 = PApplet.min(x, startX);
- float y1 = PApplet.min(y, startY);
- float x2 = PApplet.max(x, startX);
- float y2 = PApplet.max(y, startY);
- boolean toggle = checkToggle();
- if(toggle == false) {
- toolHandler.layerStack.clearAnchorSelection();
- }
- lastAnchorSelection = new ArrayList<CVector>(toolHandler.layerStack.anchorSelection);
- newAnchorSelection.clear();
- System.out.println(lastAnchorSelection.size());
- for (Layer layer : toolHandler.layerStack.layers) {
- rectangularSelection(x1, y1, x2, y2, layer, toggle);
- }
- toolHandler.layerStack.anchorSelection.clear();
- toolHandler.layerStack.anchorSelection.addAll(newAnchorSelection);
- }
- }
- public void rectangularSelection(float x1, float y1, float x2, float y2, Layer layer, boolean toggle) {
- for (BezierVertexPath p : layer.paths) {
- if(p.locked()) continue;
- for(CVector v : p.getAnchors()) {
- if(x1 <= v.x() && y1 <= v.y() && x2 >= v.x() && y2 >= v.y()) {
- // CVectors can be shared, there for with toggle we don't want to turn them on and off
- // every time we meat them. So we look if they where present in the old selection.
- // And based on we add them to the new selection.
- System.out.println("A");
- if(toggle) {
- System.out.println("B");
- // ->
- if(lastAnchorSelection.contains(v) == false) {
- System.out.println("lastAnchorSelection.size(): "+lastAnchorSelection.size());
- System.out.println("C");
- // we only want to add it once
- if(newAnchorSelection.contains(v) == false) {
- System.out.println("D");
- newAnchorSelection.add(v);
- }
- }
- else {
- System.out.println("E");
- if(newAnchorSelection.contains(v) == false) {
- System.out.println("F");
- newAnchorSelection.add(v);
- }
- }
- }
- else {
- System.out.println("G");
- if(newAnchorSelection.contains(v) == false) {
- System.out.println("H");
- newAnchorSelection.add(v);
- }
- }
- }
- }
- }
- // now the subLayers
- if(layer.subLayers != null) {
- for(Layer l : layer.subLayers) {
- rectangularSelection(x1, y1, x2, y2, l, toggle);
- }
- }
- }
If i select a anchor, and then select it again while holding shift then it prints
A
B
lastAnchorSelection.size(): 1
C
D
A and B are correct.
howver, there is this line:
- if(lastAnchorSelection.contains(v) == false) {
I only don't understand how that can be.
An ArrayList holds a reference right...
anyone a clue?
1