"Ciao, soldato!"
"Congratulazioni per aver migliorato le tue capacità. Abbiamo bisogno di ragazzi pronti a fare qualsiasi cosa".
"Sono sicuro che hai ancora molti compiti incompiuti. È ora di finirne alcuni!"
14
Compito
Java Collections, livello 1, lezione 15
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
Compito
Java Collections, livello 1, lezione 15
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
Compito
Java Collections, livello 1, lezione 15
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
Compito
Java Collections, livello 1, lezione 15
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
Compito
Java Collections, livello 1, lezione 15
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.