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

com.github.leeonky.dal.runtime.ArrayAccessor Maven / Gradle / Ivy

package com.github.leeonky.dal.runtime;

import java.util.Iterator;

public interface ArrayAccessor extends ListAccessor {
    Object get(T t, int index);

    int size(T t);

    @Override
    default Iterable toIterable(T instance) {
        return new Iterable() {
            private final int length = size(instance);
            private int index = 0;

            @Override
            public Iterator iterator() {
                return new Iterator() {

                    @Override
                    public boolean hasNext() {
                        return index < length;
                    }

                    @Override
                    public Object next() {
                        return get(instance, index++);
                    }
                };
            }
        };
    }
}