org.irlab.cartesianproduct.CartesianProduct Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cartesian-product Show documentation
Show all versions of cartesian-product Show documentation
Iterable of the cartesian product of Iterables
The newest version!
/*
* Copyright 2019 Information Retrieval Lab - University of A Coruña
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.irlab.cartesianproduct;
/**
* Cartesian product of iterables.
*
* @author [email protected]
*/
public class CartesianProduct {
/**
* Instantiates a new cartesian product.
*
*/
private CartesianProduct() {
}
/**
* Cartesian product of two iterables as an iterable.
*
* @param the type of the elements of the first iterable
* @param the type of the elements of the first iterable
* @param col1 the first iterable
* @param col2 the second iterable
* @return the cartesian product as an iterable
*/
public static Iterable2 of(final Iterable col1, final Iterable col2) {
return () -> new Iterator2<>(col1, col2);
}
/**
* Cartesian product of three iterables as an iterable.
*
* @param the type of the elements of the first iterable
* @param the type of the elements of the second iterable
* @param the type of the elements of the third iterable
* @param col1 the first iterable
* @param col2 the second iterable
* @param col3 the third iterable
* @return the cartesian product as an iterable
*/
public static Iterable3 of(final Iterable col1,
final Iterable col2, final Iterable col3) {
return () -> new Iterator3<>(col1, col2, col3);
}
/**
* Cartesian product of four iterables as an iterable.
*
* @param the type of the elements of the first iterable
* @param the type of the elements of the second iterable
* @param the type of the elements of the third iterable
* @param the type of the elements of the fourth iterable
* @param col1 the first iterable
* @param col2 the second iterable
* @param col3 the third iterable
* @param col4 the fourth iterable
* @return the cartesian product as an iterable
*/
public static Iterable4 of(final Iterable col1,
final Iterable col2, final Iterable col3, final Iterable col4) {
return () -> new Iterator4<>(col1, col2, col3, col4);
}
/**
* Cartesian product of five iterables as an iterable.
*
* @param the type of the elements of the first iterable
* @param the type of the elements of the second iterable
* @param the type of the elements of the third iterable
* @param the type of the elements of the fourth iterable
* @param the type of the elements of the fifth iterable
* @param col1 the first iterable
* @param col2 the second iterable
* @param col3 the third iterable
* @param col4 the fourth iterable
* @param col5 the fifth iterable
* @return the cartesian product as an iterable
*/
public static Iterable5 of(final Iterable col1,
final Iterable col2, final Iterable col3, final Iterable col4,
final Iterable col5) {
return () -> new Iterator5<>(col1, col2, col3, col4, col5);
}
/**
* Cartesian product of six iterables as an iterable.
*
* @param the type of the elements of the first iterable
* @param the type of the elements of the second iterable
* @param the type of the elements of the third iterable
* @param the type of the elements of the fourth iterable
* @param the type of the elements of the fifth iterable
* @param the type of the elements of the sixth iterable
* @param col1 the first iterable
* @param col2 the second iterable
* @param col3 the third iterable
* @param col4 the fourth iterable
* @param col5 the fifth iterable
* @param col6 the sixth iterable
* @return the cartesian product as an iterable
*/
public static Iterable6 of(
final Iterable col1, final Iterable col2, final Iterable col3,
final Iterable col4, final Iterable col5, final Iterable col6) {
return () -> new Iterator6<>(col1, col2, col3, col4, col5, col6);
}
/**
* Cartesian product of seven iterables as an iterable.
*
* @param the type of the elements of the first iterable
* @param the type of the elements of the second iterable
* @param the type of the elements of the third iterable
* @param the type of the elements of the fourth iterable
* @param the type of the elements of the fifth iterable
* @param the type of the elements of the sixth iterable
* @param the type of the elements of the seventh iterable
* @param col1 the first iterable
* @param col2 the second iterable
* @param col3 the third iterable
* @param col4 the fourth iterable
* @param col5 the fifth iterable
* @param col6 the sixth iterable
* @param col7 the seventh iterable
* @return the cartesian product as an iterable
*/
public static Iterable7 of(
final Iterable col1, final Iterable col2, final Iterable col3,
final Iterable col4, final Iterable col5, final Iterable col6,
final Iterable col7) {
return () -> new Iterator7<>(col1, col2, col3, col4, col5, col6, col7);
}
/**
* Cartesian product of eight iterables as an iterable.
*
* @param the type of the elements of the first iterable
* @param the type of the elements of the second iterable
* @param the type of the elements of the third iterable
* @param the type of the elements of the fourth iterable
* @param the type of the elements of the fifth iterable
* @param the type of the elements of the sixth iterable
* @param the type of the elements of the seventh iterable
* @param the type of the elements of the eighth iterable
* @param col1 the first iterable
* @param col2 the second iterable
* @param col3 the third iterable
* @param col4 the fourth iterable
* @param col5 the fifth iterable
* @param col6 the sixth iterable
* @param col7 the seventh iterable
* @param col8 the eighth iterable
* @return the cartesian product as an iterable
*/
public static Iterable8 of(
final Iterable col1, final Iterable col2, final Iterable col3,
final Iterable col4, final Iterable col5, final Iterable col6,
final Iterable col7, final Iterable col8) {
return () -> new Iterator8<>(col1, col2, col3, col4, col5, col6, col7, col8);
}
/**
* Cartesian product of nine iterables as an iterable.
*
* @param the type of the elements of the first iterable
* @param the type of the elements of the second iterable
* @param the type of the elements of the third iterable
* @param the type of the elements of the fourth iterable
* @param the type of the elements of the fifth iterable
* @param the type of the elements of the sixth iterable
* @param the type of the elements of the seventh iterable
* @param the type of the elements of the eighth iterable
* @param the type of the elements of the ninth iterable
* @param col1 the first iterable
* @param col2 the second iterable
* @param col3 the third iterable
* @param col4 the fourth iterable
* @param col5 the fifth iterable
* @param col6 the sixth iterable
* @param col7 the seventh iterable
* @param col8 the eighth iterable
* @param col9 the ninth iterable
* @return the cartesian product as an iterable
*/
public static Iterable9 of(
final Iterable col1, final Iterable col2, final Iterable col3,
final Iterable col4, final Iterable col5, final Iterable col6,
final Iterable col7, final Iterable col8, final Iterable col9) {
return () -> new Iterator9<>(col1, col2, col3, col4, col5, col6, col7, col8, col9);
}
/**
* Cartesian product of ten iterables as an iterable.
*
* @param the type of the elements of the first iterable
* @param the type of the elements of the second iterable
* @param the type of the elements of the third iterable
* @param the type of the elements of the fourth iterable
* @param the type of the elements of the fifth iterable
* @param the type of the elements of the sixth iterable
* @param the type of the elements of the seventh iterable
* @param the type of the elements of the eighth iterable
* @param the type of the elements of the ninth iterable
* @param the type of the elements of the tenth iterable
* @param col1 the first iterable
* @param col2 the second iterable
* @param col3 the third iterable
* @param col4 the fourth iterable
* @param col5 the fifth iterable
* @param col6 the sixth iterable
* @param col7 the seventh iterable
* @param col8 the eighth iterable
* @param col9 the ninth iterable
* @param col10 the tenth iterable
* @return the cartesian product as an iterable
*/
public static Iterable10 of(
final Iterable col1, final Iterable col2, final Iterable col3,
final Iterable col4, final Iterable col5, final Iterable col6,
final Iterable col7, final Iterable col8, final Iterable col9,
final Iterable col10) {
return () -> new Iterator10<>(col1, col2, col3, col4, col5, col6, col7, col8, col9, col10);
}
}