Jak zdefiniować metody addAll(), removeAll(),retainAll(),containsAll() dla inteffejsu Collection:
import java.util.*;
import pets.Pet;
import pets.Pets;
public class CollectionSequence2 implements Collection<Pet>
{
private Pet[] pets = Pets.createArray(8);
public boolean contains(Object p)
{
for(int i=0;i<pets.length;i++)
{
if(p==pets[i])return true;
}
return false;
}
public Pet remove(Pet p){return new Pet();}
public Iterator<Pet> iterator()
{
return new Iterator<Pet>()
{
//.....
};
}
public Pet[] toArray(){return new Pet[1];}
public Pet[] toArray(Object[] p){return new Pet[pets.length];}
public void removeAll(){}
public boolean add(Pet p){return true;}
public void clear(){return;}
public int size(){return pets.length;}
public boolean remove(Object o){ return true;}
public boolean isEmpty(){return false;}
public boolean removeAll(CollectionSequence2<Pet> c){return true;}// ????
public boolean retainAll(CollectionSequence2<Pet> c){return true;}
public boolean containsAll(CollectionSequence2<Pet> c){return true;}
public boolean addAll(CollectionSequence2<Pet> c){return true;}
}
dokumetacja do Collection: http://java.sun.com/javase/6/docs/api/java/util/Collection.html