Hi all!
I would really appreciate your help with this. I have an arrayList of objects that are to be represented by a treemap. I want to traverse
backwards through the arrayList and increase the size of each items bounds as I do so. The code appears to be traversing backwards through the arrayList but is increasing the size of the items in the wrong order! The top left rectangle in the treemap should be the biggest but at the moment it is the smallest. Perhaps my logic is flawed but if what I'm trying to do is possible I would love to know where my mistake is!
Here is my code (This method is called repeatedly for each new item to be added):
- void addRank(TitleItem title){
- int arraySize = ranks.size();
- ranks.add(title);
- println("SIZE: " + ranks.size());
- ListIterator listIterator = ranks.listIterator();//DECREASES the size of
- //each position after the first position, making first the largest
- while(listIterator.hasNext() && listIterator.next() != ranks.get(ranks.size() - 1)) {
- //move to end of the arrayList
- listIterator.next();
- }
- if (listIterator.hasPrevious()) {
- println("AT: " + listIterator.previousIndex());//tracking position for debugging purposes
- while(listIterator.hasPrevious()) {
- title.incrementSize();
- listIterator.previous();
- println("NOW AT: " + listIterator.previousIndex());//tracking position
- }
- }
- }
1