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

org.babyfish.jimmer.sql.ast.impl.TupleProjectionCollection Maven / Gradle / Ivy

There is a newer version: 0.8.180
Show newest version
package org.babyfish.jimmer.sql.ast.impl;

import org.jetbrains.annotations.NotNull;

import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;

class TupleProjectionCollection extends AbstractCollection {

    private final Collection tuples;

    private final int index;

    public TupleProjectionCollection(Collection tuples, int index) {
        this.tuples = tuples;
        this.index = index;
    }

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

    @Override
    public void clear() {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean add(Object o) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean addAll(@NotNull Collection c) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean remove(Object o) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean removeAll(@NotNull Collection c) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean retainAll(@NotNull Collection c) {
        throw new UnsupportedOperationException();
    }

    @NotNull
    @Override
    public Iterator iterator() {
        return new Itr(tuples.iterator(), index);
    }

    private static class Itr implements Iterator {

        private final Iterator baseItr;

        private final int index;

        private Itr(Iterator baseItr, int index) {
            this.baseItr = baseItr;
            this.index = index;
        }

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

        @Override
        public Object next() {
            return baseItr.next().get(index);
        }
    }
}