Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ShapeNode list (Read 4474 times)
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
ShapeNode list
Oct 6th, 2015 at 10:48am
Print Post  
Hi,
I have a list of ShapeNode and I want to order it according to the left bounds of the nodes, I did in this way, but it doesn't work:
ShapeNode temp = null;
                    for(int z = 0; z < e.getPrevoiusNodes().size(); z++){
                        for(int i = e.getPrevoiusNodes().size() - 1; i >= z; i--){
                            if(e.getPrevoiusNodes().get(i).getBounds().left >= e.getPrevoiusNodes().get(i+1).getBounds().left){

                                temp = e.getPrevoiusNodes().get(i);
                                e.getPrevoiusNodes().get(i)= e.getPrevoiusNodes().get(i+1);
                                e.getPrevoiusNodes().get(i+1) = temp;
                            }
                        }
                    }
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeNode list
Reply #1 - Oct 6th, 2015 at 12:17pm
Print Post  
Hi,

You should call getPrevoiusNodes' set() method instead of assigning to get()'s result, which is just a temporary value in the function's stack.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: ShapeNode list
Reply #2 - Oct 6th, 2015 at 12:25pm
Print Post  
Sorry but it doesn't work the method set, maybe I was wrong, could you give me an example?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeNode list
Reply #3 - Oct 6th, 2015 at 12:39pm
Print Post  
I don't know what your getPrevoiusNodes method returns. If it's a standard Java List<> container, better call java.util.Collections.sort method on it instead of trying to sort yourself. The getBounds().left comparison from your code should go into the implementation of Comparator object you pass to sort().
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: ShapeNode list
Reply #4 - Oct 6th, 2015 at 12:56pm
Print Post  
Yes, it's a List of ShapeNode, but what can I pass to comparator? to get the bounds I need a ShapeNode but here I have a list of ShapeNode
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: ShapeNode list
Reply #5 - Oct 6th, 2015 at 1:11pm
Print Post  
Sorry, I solved, I made a cast to ShapeNode in the comparator and it works
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint