Goodmorning everybody,
I'm having a little problem with a project for school. We are told to make an Iterator that implements Enumeration over a Hashmap.
So i made this Enumeration:
public Enumeration<Object> getEnumeration() {
return new Enumeration<Object>() {
private int itemsDone = 0;
Collection<Long> keysCollection = getContent().keySet();
Long [] keys = keysCollection.toArray(new Long[keysCollection.size()]);
@Override
public boolean hasMoreElements() {
if(itemsDone < getContent().size() +1 ) {
return true;
}else {
return false;
}
}
@Override
public Object nextElement() {
return getContent().get(keys[itemsDone++]);
}
};
}
This goes in my Backpack class
public class Backpack extends Item implements Carrier, Enumeration<Object>{
The hashmap is returned by getContent(). The problem now is that eclipse keeps telling me I havent implemented the methods from Enumeration. If I use the quick fix it just adds the hasMoreElements() and nextElement() dummy methods in my class. Somehow it doesn't see these methods in the inner class..
Can anyone help me please? Any help is appreciated.