vendredi 1 décembre 2017

Pattern iterator

I have a task, which consists of pattern implementation (Iterator) and addition of the method iterator() in previously created classes Hotel and Tours. Unfortunately, I'm still new to Java, so I don't know how to use methods from IIterator for arraylist inter. Info - interface

public class IIterator<T> implements Iterator<T> {

    private Object elements;
    int index = 0;


    public boolean hasNext() {
        return index< Array.getLength(elements);
    }
    public T next() {
        return (T) Array.get(elements, index++);
    }
    public void remove() {
        throw new UnsupportedOperationException("remove");
    }
}
public class Hotel implements Info, Serializable, Cloneable, Comparable{
    public Iterator iterator() {
        return new IIterator();
    }
}
public class Tours implements Info, Serializable, Cloneable, Comparable{
    public Iterator iterator() {
        return new IIterator();
    }
}

ArrayList<Info> inter = new ArrayList();
        inter.add(new Hotel("Lara", 100, 5));
        inter.add(new Hotel("Katya", 10, 1));
        inter.add(new Tours("Lara", 1000, length));
        inter.add(new Tours("HelsinkiPanorama", 1010, length));

Aucun commentaire:

Enregistrer un commentaire