CodeGym /Courses /Java Collections /Big task: Java collections

Big task: Java collections

Java Collections
Level 4 , Lesson 15
Available

"Hello, soldier!"

"Congratulations on upgrading your skills. We need guys who are prepared to do anything."

"I'm sure you still have many unfinished tasks. It's time to finish some of them!"

8
Task
Java Collections, level 4, lesson 15
Locked
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
Task
Java Collections, level 4, lesson 15
Locked
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
Task
Java Collections, level 4, lesson 15
Locked
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
Task
Java Collections, level 4, lesson 15
Locked
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
Task
Java Collections, level 4, lesson 15
Locked
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
Task
Java Collections, level 4, lesson 15
Locked
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
Comments (4)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Skynet Level 40, USA
28 September 2021
Test code for part 5:

HashSet<String> hashSet = new HashSet<>();
hashSet.add("String 1");
hashSet.add("String 2");
AmigoSet amigoSet1 = new AmigoSet(hashSet);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(amigoSet1);
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
AmigoSet amigoSet2 = (AmigoSet) ois.readObject();
System.out.println("Before serialization:\n" + amigoSet1 + "\n");
System.out.println("After deserialization:\n" + amigoSet2 + "\n");
System.out.println("Are sets equal? - " + amigoSet1.equals(amigoSet2));
Nicholas Grube Level 41, Carrollton, TX, United States
22 June 2020
Hint for task 5: Look at what data type loadFactor is (it's not the same type as Capacity).
yz Level 37, Jakarta, Indonesia
8 April 2020
if u need help for 5th one text me
Seb Level 41, Crefeld, Germany
21 February 2020
Woohoo - task 5 was a little bit of a refresher in terms of serialization. Pretty cool to use this in conjunction with the provided HashMapReflectionHelper. Thank you, Captain Squirrels, Sir! :-)