I don't understand why he doesn't include the last two conditions.
In my opinion, the add method works correctly according to the task conditions.
However, the validator doesn't like it.
Hits me already ..
package com.codegym.task.task37.task3707;
import java.io.Serializable;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;
//Krok 1. Całe zadanie robimy zgodnie ze wskazówkami
//Zakładamy klasę AmigoSet, która jest dzieckiem AbstactSet i implementuje
//interfejsy Serializable, Cloneable, Set
//Zakładamy public static void main
//Implementujemy wszystkie metody, które podpowiada edytor
//Krok 2
public class AmigoSet<E> extends AbstractSet implements Serializable, Cloneable, Set
{
//Krok 2
private static final Object PRESENT = new Object();
private transient HashMap<E, Object> map;
public static void main(String[] args)
{
}
//Krok 2
public AmigoSet()
{
map = new HashMap<>();
}
//Krok 2
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);
}
}
//Krok 2
public boolean addMy(E e)
{
if (map.containsKey(e))
{
return false;
}
else
{
map.put(e, PRESENT);
return true;
}
}
@Override
public Iterator iterator()
{
return null;
}
@Override
public int size()
{
return 0;
}
@Override
public boolean removeIf(Predicate filter) {
return false;
}
@Override
public Stream stream() {
return super.stream();
}
@Override
public Stream parallelStream() {
return super.parallelStream();
}
@Override
public Spliterator spliterator() {
return super.spliterator();
}
@Override
public void forEach(Consumer action) {
super.forEach(action);
}
}