"Xin chào, quân nhân!"
"Chúc mừng bạn đã nâng cấp kỹ năng của mình. Chúng tôi cần những người sẵn sàng làm bất cứ điều gì."
"Tôi chắc chắn rằng bạn vẫn còn nhiều nhiệm vụ chưa hoàn thành. Đã đến lúc hoàn thành một số trong số chúng!"
8
Nhiệm vụ
Java Collections, mức độ, bài học
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
Nhiệm vụ
Java Collections, mức độ, bài học
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
Nhiệm vụ
Java Collections, mức độ, bài học
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
Nhiệm vụ
Java Collections, mức độ, bài học
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
Nhiệm vụ
Java Collections, mức độ, bài học
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
Nhiệm vụ
Java Collections, mức độ, bài học
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