All Downloads are FREE. Search and download functionalities are using the official Maven repository.

apoc.coll.SetBackedList Maven / Gradle / Ivy

package apoc.coll;

import java.util.*;

/**
 * @author mh
 * @since 10.04.16
 */
class SetBackedList extends AbstractSequentialList {

    private final Set set;

    public SetBackedList(Set set) {
        this.set = set;
    }

    @Override
    public int size() {
        return set.size();
    }

    public ListIterator listIterator(int index) {
        return new ListIterator() {
            Iterator it = set.iterator();
            Object current = null;
            int idx = 0;
            {
                moveTo(index);
            }

            @Override
            public boolean hasNext() {
                return it.hasNext();
            }

            @Override
            public Object next() {
                idx++;
                return current = it.next();
            }

            @Override
            public boolean hasPrevious() {
                return idx > 0;
            }

            @Override
            public Object previous() {
                if (!hasPrevious()) throw new NoSuchElementException();
                Object tmp = current;
                moveTo(idx-1);
                return tmp;
            }

            private void moveTo(int pos) {
                Iterator it2 = set.iterator();
                Object value = null;
                int i=0; while (i++




© 2015 - 2025 Weber Informatics LLC | Privacy Policy