@Override
public Object clone(){
try
{
AmigoSet amigo = (AmigoSet) super.clone();
amigo.map = (HashMap) map.clone();
return amigo;
}
catch (Exception e)
{
throw new InternalError();
}
}
package com.javarush.task.task37.task3707;
import java.io.Serializable;
import java.util.*;
public class AmigoSet<E> extends AbstractSet<E> implements Serializable, Cloneable, Set<E> {
private static final Object PRESENT = new Object();
private transient HashMap<E,Object> map;
public AmigoSet() {
this.map = new HashMap<>();
}
public AmigoSet(Collection<? extends E> collection) {
map = new HashMap<E, Object>(Math.max((int)Math.ceil(collection.size() / 0.75F), 16));
this.addAll(collection);
}
@Override
public Object clone(){
try
{
AmigoSet amigo = (AmigoSet) super.clone();
amigo.map = (HashMap) map.clone();
return amigo;
}
catch (Exception e)
{
throw new InternalError();
}
}
@Override
public int size() {
return map.size();
}
@Override
public Iterator iterator() {
return map.keySet().iterator();
}
@Override
public boolean remove(Object o) {
Object object = map.remove(o);
return object != null;
}
@Override
public boolean isEmpty() {
return map.isEmpty();
}
@Override
public boolean contains(Object o) {
return map.containsKey(o);
}
@Override
public void clear() {
map.clear();
}
}