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

com.github.czyzby.kiwi.util.tuple.Tuples Maven / Gradle / Ivy

There is a newer version: 1.9.1.9.6
Show newest version
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