Don\'t know if it\'s a bug, but can\'t add any Edge/Childs after creating OrderedKAryTree with \"2\" argument while making an object.
OrderedKAryTree tree = new OrderedKAryTree(2);
tree.addVertex(parent);
tree.addEdge(\"Edge parent->child\", parent, child, 0);
Where parent and child are intances of my class MusicItem (doesn\'t matter what it is).
Exception in thread \"main\" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at edu.uci.ics.jung.graph.OrderedKAryTree.addEdge(OrderedKAryTree.java:236)
at JUNG.Main.main(Main.java:30)
Java Result: 1
Please answer (lukasz.modlinski@gmail.com)
Yep, I faced the same problem and I believe it is a bug after checking the source code around OrderedKAryTree.java:236. Also, the method where you do not have to provide the child index is not properly implemented.
the code calls new ArrayList(2), which creates an ArrayList of size 0, despite having initial capacity of 2. Accessing the element at index 0 of a List of size 0 causes the out of bounds exception.
If line 232 is modified from
outedges = new ArrayList<E>(this.order);
to
outedges = new ArrayList(Collections.nCopies(this.order, null));
it might clear this bug.