
org.davidmoten.kool.internal.util.Iterables Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kool Show documentation
Show all versions of kool Show documentation
Streaming library supporting reuse and many operators
package org.davidmoten.kool.internal.util;
import java.util.Iterator;
import java.util.NoSuchElementException;
public final class Iterables {
private Iterables() {
// prevent instantiation
}
public static Iterable fromArray(T[] array) {
return new Iterable() {
@Override
public Iterator iterator() {
return new Iterator() {
int i = 0;
@Override
public boolean hasNext() {
return i < array.length;
}
@Override
public T next() {
i++;
if (i > array.length) {
throw new NoSuchElementException();
} else {
return array[i - 1];
}
}
};
}
};
}
@SafeVarargs
public static Iterable ofNoCopy(T... values) {
return new Iterable() {
@Override
public Iterator iterator() {
return new Iterator() {
int i = 0;
@Override
public boolean hasNext() {
return i < values.length;
}
@Override
public T next() {
if (i >= values.length) {
throw new NoSuchElementException();
} else {
T t = values[i];
i++;
return t;
}
}
};
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy