"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!"
8
Opgave
Java Collections, niveau, lektie
AmigoSet (part 1)
Let's write some sort of collection. Let it be your very own Set.
Let this class allow null values to be added.
1. Create an AmigoSet class. Let this class inherit AbstractSet.
The set must support the Serializable and Cloneable interfaces (how could it not??).
It's also obvious that it must imple
30
Opgave
Java Collections, niveau, lektie
AmigoSet (part 2)
We won't re-invent the mechanism for working with hashes — It has already been implemented in lots of collections.
We'll grab HashMap and use it.
1. Create a private Object PRESENT constant and initialize it with an Object. This will be our stub.
2. Create a private transient HashMap m
14
Opgave
Java Collections, niveau, lektie
AmigoSet (part 3)
Write your own implementation of the following methods that allow you to work with the keys in map:
* Iterator iterator () - Obviously, this is a key iterator. Get the set of keys in map, and return its iterator
* int size() - This is the number of keys in map. It is equal to the number of eleme
14
Opgave
Java Collections, niveau, lektie
AmigoSet (part 4)
Your AmigoSet set implements the Cloneable interface. However, it doesn't clone properly.
Write your own implementation of the Object clone() method, so that it creates a shallow clone.
* Clone the set, and clone map.
* Throw an InternalError if an exception occurs.
* Eliminate the throwing of oth
30
Opgave
Java Collections, niveau, lektie
AmigoSet (part 5)
Your AmigoSet set implements the Serializable interface. However, it doesn't serialize properly.
1. Implement your own logic for serializing and deserializing.
Remember which private methods you need to add in order to serialize correctly.
To serialize:
* serialize the set
* serialize the map obje
8
Opgave
Java Collections, niveau, lektie
AmigoSet (part 6)
Open the HashSet's source (if you don't have the Java source, download it, and connect it), and compare it to your code.
You can do this quickly by comparing with the clipboard. Copy the HashSet class's source code to the clipboard.
Go to the AmigoSet class, and then right-click -> Compare with Cli