Pleaseeeeeee
package com.codegym.task.task37.task3707;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.*;
public class AmigoSet<E> extends AbstractSet implements Serializable, Cloneable, Set {
private static final Object PRESENT = new Object();
private transient HashMap<E, Object> map;
@Override
public Iterator iterator() {
Set keys = this.map.keySet();
return keys.iterator();
}
@Override
public int size() {
return this.map.size();
}
@Override
public boolean isEmpty() {
return map.isEmpty();
}
@Override
public boolean contains(Object o) {
return map.containsKey(o);
}
@Override
public void clear() {
this.map.clear();
}
@Override
public boolean remove(Object o) {
this.map.remove(o);
return true;
}
public AmigoSet() {
map = new HashMap<>();
}
public AmigoSet(Collection<? extends E> collection) {
int capacity = Math.max(16, (int) (Math.ceil(collection.size() / .75f)));
this.map = new HashMap<>(capacity);
for (E e : collection) {
map.put(e, PRESENT);
}
}
public boolean add (Object e) {
if (map.containsKey(e)) {
return false;
} else {
map.put((E) e, PRESENT);
return true;
}
}
public Object clone(){
AmigoSet<E> clone;
try {
clone = (AmigoSet<E>)super.clone();
clone.map = (HashMap<E,Object>)map.clone();
} catch (Exception e) {
throw new InternalError(e);
}
return clone;
}
private void writeObject(ObjectOutputStream objoutstr) throws IOException {
objoutstr.writeObject(this.map);
}
private void readObject(ObjectInputStream objectInputStream){
try {
this.map = (HashMap<E, Object>) objectInputStream.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}