
com.github.czyzby.kiwi.util.tuple.Tuples Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gdx-kiwi Show documentation
Show all versions of gdx-kiwi Show documentation
Guava-inspired set of utilities for LibGDX.
package com.github.czyzby.kiwi.util.tuple;
import java.util.Iterator;
import com.github.czyzby.kiwi.util.common.UtilitiesClass;
/** Contains utilties for creating tuples. Note that factory methods are provided by classes that are implementation of
* specific tuple interfaces.
*
* @author MJ */
public class Tuples extends UtilitiesClass {
private Tuples() {
}
/** @param tuple will be iterated over.
* @return a new instance of an iterator that iterates over tuple's values.
* @param iterator type. */
public static Iterator getTupleIterator(final Tuple tuple) {
return new Iterator() {
private int currentIndex;
@Override
public boolean hasNext() {
return currentIndex < tuple.getSize();
}
@Override
@SuppressWarnings("unchecked")
public Type next() {
return (Type) tuple.get(currentIndex++);
}
@Override
public void remove() {
if (tuple.isMutable()) {
tuple.set(currentIndex, null);
} else {
throw new UnsupportedOperationException("Tuple is immutable.");
}
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy