"Hej, soldat!"
"Tillykke med opgraderingen af dine færdigheder. Vi har brug for fyre, der er parate til at gøre alt."
"Jeg er sikker på, at du stadig har mange ufærdige opgaver. Det er tid til at afslutte nogle af dem!"
14
Opgave
Java Collections, niveau, lektie
Build a tree (part 1)
Amigo, it seems you may now have an adequate foundation. It's time to test your skills by doing a big task!
Today, we'll implement our own tree in a slightly non-standard way (based on AbstractList).
To get background information, use your favorite search engine and the text below.
14
Opgave
Java Collections, niveau, lektie
Build a tree (part 2)
Despite the fact that our tree descends from the AbstractList class, it is not a list in the traditional sense.
In particular, we don't have access to methods that take an element's index as an argument.
You need to override such methods and throw a new type of exception: UnsupportedOperationExcept
14
Opgave
Java Collections, niveau, lektie
Build a tree (part 3)
We've created a class that defines a tree. Now we need a class that defines the nodes of a tree:
1) In the CustomTree class, create a static inner generic class Entry<T> with the default access modifier.
2) Make this class support the Serializable interface.
28
Opgave
Java Collections, niveau, lektie
Build a tree (part 4)
Every tree starts with a root, so don't forget to add an Entry<String> field called root with the default access modifier to the CustomTree class. Initialize it in the CustomTree constructor. It's name (elementName) isn't important.
28
Opgave
Java Collections, niveau, lektie
Build a tree (part 5)
We can add elements to the tree. Now let's work on deleting them:
Implement the remove(Object o) method, which will remove the tree node whose name was passed as an argument.
The method must throw an UnsupportedOperationException if the argument is not a String.