Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRLab
Cartesian Product
Commits
f85d312c
Commit
f85d312c
authored
Dec 17, 2019
by
Alfonso Landin
🤷
Browse files
Initial code for release
parents
e8b0da54
c5f9b424
Changes
24
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
f85d312c
/target/
.classpath
.project
.settings/
.jqwik-database
pom.xml
0 → 100644
View file @
f85d312c
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.irlab
</groupId>
<artifactId>
cartesian-product
</artifactId>
<version>
1.0.0
</version>
<name>
Cartesian product
</name>
<description>
Iterable of the cartesian product of Iterables
</description>
<url>
https://gitlab.irlab.org/irlab/cartesian-product
</url>
<licenses>
<license>
<name>
The Apache License, Version 2.0
</name>
<url>
http://www.apache.org/licenses/LICENSE-2.0.txt
</url>
</license>
</licenses>
<developers>
<developer>
<name>
Alfonso Landin
</name>
<email>
alfonso.landin@udc.es
</email>
<organization>
Information Retrieval Lab (IRLab)
</organization>
<organizationUrl>
https://irlab.org/
</organizationUrl>
</developer>
</developers>
<scm>
<connection>
scm:git:https://gitlab.irlab.org/irlab/cartesian-product.git
</connection>
<developerConnection>
scm:git:ssh://git@gitlab.irlab.org:7022/irlab/cartesian-product.git
</developerConnection>
<url>
https://gitlab.irlab.org/irlab/cartesian-product
</url>
</scm>
<properties>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<distributionManagement>
<snapshotRepository>
<id>
ossrh
</id>
<url>
https://oss.sonatype.org/content/repositories/snapshots
</url>
</snapshotRepository>
<repository>
<id>
ossrh
</id>
<url>
https://oss.sonatype.org/service/local/staging/deploy/maven2/
</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>
org.jooq
</groupId>
<artifactId>
jool-java-8
</artifactId>
<version>
0.9.14
</version>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter
</artifactId>
<version>
5.5.2
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
net.jqwik
</groupId>
<artifactId>
jqwik
</artifactId>
<version>
1.2.1
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
2.22.2
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.8.0
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<version>
3.1.1
</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<configuration>
<forkCount>
1
</forkCount>
<reuseForks>
false
</reuseForks>
</configuration>
</plugin>
<plugin>
<groupId>
org.jacoco
</groupId>
<artifactId>
jacoco-maven-plugin
</artifactId>
<version>
0.8.5
</version>
<executions>
<execution>
<id>
jacoco-initialize
</id>
<phase>
process-test-classes
</phase>
<goals>
<goal>
prepare-agent
</goal>
</goals>
</execution>
<execution>
<id>
jacoco-test-report
</id>
<phase>
prepare-package
</phase>
<goals>
<goal>
report
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- Configure javadoc plugin for JDK 9+ -->
<id>
java9-javadoc
</id>
<activation>
<jdk>
[9,)
</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<configuration>
<javadocExecutable>
${java.home}/bin/javadoc
</javadocExecutable>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>
release
</id>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<version>
2.2.1
</version>
<executions>
<execution>
<id>
attach-sources
</id>
<goals>
<goal>
jar-no-fork
</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<executions>
<execution>
<id>
attach-javadocs
</id>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-gpg-plugin
</artifactId>
<version>
1.5
</version>
<executions>
<execution>
<id>
sign-artifacts
</id>
<phase>
verify
</phase>
<goals>
<goal>
sign
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
\ No newline at end of file
src/main/java/org/irlab/cartesianproduct/CartesianProduct.java
0 → 100644
View file @
f85d312c
/*
* 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 alfonso.landin@udc.es
*/
public
class
CartesianProduct
{
/**
* Instantiates a new cartesian product.
*
*/
private
CartesianProduct
()
{
}
/**
* Cartesian product of two iterables as an iterable.
*
* @param <E1> the type of the elements of the first iterable
* @param <E2> 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
<
E1
,
E2
>
Iterable2
<
E1
,
E2
>
of
(
final
Iterable
<
E1
>
col1
,
final
Iterable
<
E2
>
col2
)
{
return
()
->
new
Iterator2
<>(
col1
,
col2
);
}
/**
* Cartesian product of three iterables as an iterable.
*
* @param <E1> the type of the elements of the first iterable
* @param <E2> the type of the elements of the second iterable
* @param <E3> 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
<
E1
,
E2
,
E3
>
Iterable3
<
E1
,
E2
,
E3
>
of
(
final
Iterable
<
E1
>
col1
,
final
Iterable
<
E2
>
col2
,
final
Iterable
<
E3
>
col3
)
{
return
()
->
new
Iterator3
<>(
col1
,
col2
,
col3
);
}
/**
* Cartesian product of four iterables as an iterable.
*
* @param <E1> the type of the elements of the first iterable
* @param <E2> the type of the elements of the second iterable
* @param <E3> the type of the elements of the third iterable
* @param <E4> 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
<
E1
,
E2
,
E3
,
E4
>
Iterable4
<
E1
,
E2
,
E3
,
E4
>
of
(
final
Iterable
<
E1
>
col1
,
final
Iterable
<
E2
>
col2
,
final
Iterable
<
E3
>
col3
,
final
Iterable
<
E4
>
col4
)
{
return
()
->
new
Iterator4
<>(
col1
,
col2
,
col3
,
col4
);
}
/**
* Cartesian product of five iterables as an iterable.
*
* @param <E1> the type of the elements of the first iterable
* @param <E2> the type of the elements of the second iterable
* @param <E3> the type of the elements of the third iterable
* @param <E4> the type of the elements of the fourth iterable
* @param <E5> 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
<
E1
,
E2
,
E3
,
E4
,
E5
>
Iterable5
<
E1
,
E2
,
E3
,
E4
,
E5
>
of
(
final
Iterable
<
E1
>
col1
,
final
Iterable
<
E2
>
col2
,
final
Iterable
<
E3
>
col3
,
final
Iterable
<
E4
>
col4
,
final
Iterable
<
E5
>
col5
)
{
return
()
->
new
Iterator5
<>(
col1
,
col2
,
col3
,
col4
,
col5
);
}
/**
* Cartesian product of six iterables as an iterable.
*
* @param <E1> the type of the elements of the first iterable
* @param <E2> the type of the elements of the second iterable
* @param <E3> the type of the elements of the third iterable
* @param <E4> the type of the elements of the fourth iterable
* @param <E5> the type of the elements of the fifth iterable
* @param <E6> 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
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
>
Iterable6
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
>
of
(
final
Iterable
<
E1
>
col1
,
final
Iterable
<
E2
>
col2
,
final
Iterable
<
E3
>
col3
,
final
Iterable
<
E4
>
col4
,
final
Iterable
<
E5
>
col5
,
final
Iterable
<
E6
>
col6
)
{
return
()
->
new
Iterator6
<>(
col1
,
col2
,
col3
,
col4
,
col5
,
col6
);
}
/**
* Cartesian product of seven iterables as an iterable.
*
* @param <E1> the type of the elements of the first iterable
* @param <E2> the type of the elements of the second iterable
* @param <E3> the type of the elements of the third iterable
* @param <E4> the type of the elements of the fourth iterable
* @param <E5> the type of the elements of the fifth iterable
* @param <E6> the type of the elements of the sixth iterable
* @param <E7> 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
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
>
Iterable7
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
>
of
(
final
Iterable
<
E1
>
col1
,
final
Iterable
<
E2
>
col2
,
final
Iterable
<
E3
>
col3
,
final
Iterable
<
E4
>
col4
,
final
Iterable
<
E5
>
col5
,
final
Iterable
<
E6
>
col6
,
final
Iterable
<
E7
>
col7
)
{
return
()
->
new
Iterator7
<>(
col1
,
col2
,
col3
,
col4
,
col5
,
col6
,
col7
);
}
/**
* Cartesian product of eight iterables as an iterable.
*
* @param <E1> the type of the elements of the first iterable
* @param <E2> the type of the elements of the second iterable
* @param <E3> the type of the elements of the third iterable
* @param <E4> the type of the elements of the fourth iterable
* @param <E5> the type of the elements of the fifth iterable
* @param <E6> the type of the elements of the sixth iterable
* @param <E7> the type of the elements of the seventh iterable
* @param <E8> 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
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
>
Iterable8
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
>
of
(
final
Iterable
<
E1
>
col1
,
final
Iterable
<
E2
>
col2
,
final
Iterable
<
E3
>
col3
,
final
Iterable
<
E4
>
col4
,
final
Iterable
<
E5
>
col5
,
final
Iterable
<
E6
>
col6
,
final
Iterable
<
E7
>
col7
,
final
Iterable
<
E8
>
col8
)
{
return
()
->
new
Iterator8
<>(
col1
,
col2
,
col3
,
col4
,
col5
,
col6
,
col7
,
col8
);
}
/**
* Cartesian product of nine iterables as an iterable.
*
* @param <E1> the type of the elements of the first iterable
* @param <E2> the type of the elements of the second iterable
* @param <E3> the type of the elements of the third iterable
* @param <E4> the type of the elements of the fourth iterable
* @param <E5> the type of the elements of the fifth iterable
* @param <E6> the type of the elements of the sixth iterable
* @param <E7> the type of the elements of the seventh iterable
* @param <E8> the type of the elements of the eighth iterable
* @param <E9> 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
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
,
E9
>
Iterable9
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
,
E9
>
of
(
final
Iterable
<
E1
>
col1
,
final
Iterable
<
E2
>
col2
,
final
Iterable
<
E3
>
col3
,
final
Iterable
<
E4
>
col4
,
final
Iterable
<
E5
>
col5
,
final
Iterable
<
E6
>
col6
,
final
Iterable
<
E7
>
col7
,
final
Iterable
<
E8
>
col8
,
final
Iterable
<
E9
>
col9
)
{
return
()
->
new
Iterator9
<>(
col1
,
col2
,
col3
,
col4
,
col5
,
col6
,
col7
,
col8
,
col9
);
}
/**
* Cartesian product of ten iterables as an iterable.
*
* @param <E1> the type of the elements of the first iterable
* @param <E2> the type of the elements of the second iterable
* @param <E3> the type of the elements of the third iterable
* @param <E4> the type of the elements of the fourth iterable
* @param <E5> the type of the elements of the fifth iterable
* @param <E6> the type of the elements of the sixth iterable
* @param <E7> the type of the elements of the seventh iterable
* @param <E8> the type of the elements of the eighth iterable
* @param <E9> the type of the elements of the ninth iterable
* @param <E10> 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
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
,
E9
,
E10
>
Iterable10
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
,
E9
,
E10
>
of
(
final
Iterable
<
E1
>
col1
,
final
Iterable
<
E2
>
col2
,
final
Iterable
<
E3
>
col3
,
final
Iterable
<
E4
>
col4
,
final
Iterable
<
E5
>
col5
,
final
Iterable
<
E6
>
col6
,
final
Iterable
<
E7
>
col7
,
final
Iterable
<
E8
>
col8
,
final
Iterable
<
E9
>
col9
,
final
Iterable
<
E10
>
col10
)
{
return
()
->
new
Iterator10
<>(
col1
,
col2
,
col3
,
col4
,
col5
,
col6
,
col7
,
col8
,
col9
,
col10
);
}
}
src/main/java/org/irlab/cartesianproduct/Iterable10.java
0 → 100644
View file @
f85d312c
/*
* 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
;
import
java.util.Iterator
;
import
java.util.Spliterator
;
import
java.util.function.Consumer
;
import
org.jooq.lambda.function.Consumer10
;
import
org.jooq.lambda.tuple.Tuple10
;
/**
* Iterable of nine-arity tuples that also has a forEach with nine arguments.
*
* @param <E1> the type of the first element
* @param <E2> the type of the second element
* @param <E3> the type of the third element
* @param <E4> the type of the fourth element
* @param <E5> the type of the fifth element
* @param <E6> the type of the sixth element
* @param <E7> the type of the seventh element
* @param <E8> the type of the eight element
* @param <E9> the type of the ninth element
* @param <E10> the type of the tenth element
*
* @author alfonso.landin@udc.es
*/
@FunctionalInterface
public
interface
Iterable10
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
,
E9
,
E10
>
extends
Iterable
<
Tuple10
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
,
E9
,
E10
>>
{
/**
* Performs the give action for each tuple of the {@link Iterable10}.
*
* @param action The action to be performed for each tuple.
*/
default
void
forEach
(
final
Consumer10
<?
super
E1
,
?
super
E2
,
?
super
E3
,
?
super
E4
,
?
super
E5
,
?
super
E6
,
?
super
E7
,
?
super
E8
,
?
super
E9
,
?
super
E10
>
action
)
{
forEach
(
tuple
->
action
.
accept
(
tuple
.
v1
,
tuple
.
v2
,
tuple
.
v3
,
tuple
.
v4
,
tuple
.
v5
,
tuple
.
v6
,
tuple
.
v7
,
tuple
.
v8
,
tuple
.
v9
,
tuple
.
v10
));
}
/**
* {@inheritDoc}
*/
@Override
Iterator
<
Tuple10
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
,
E9
,
E10
>>
iterator
();
/**
* {@inheritDoc}
*/
@Override
default
void
forEach
(
final
Consumer
<?
super
Tuple10
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
,
E9
,
E10
>>
action
)
{
Iterable
.
super
.
forEach
(
action
);
}
/**
* {@inheritDoc}
*/
@Override
default
Spliterator
<
Tuple10
<
E1
,
E2
,
E3
,
E4
,
E5
,
E6
,
E7
,
E8
,
E9
,
E10
>>
spliterator
()
{
return
Iterable
.
super
.
spliterator
();
}
}
src/main/java/org/irlab/cartesianproduct/Iterable2.java
0 → 100644
View file @
f85d312c
/*
* 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
;
import
java.util.Iterator
;
import
java.util.Spliterator
;
import
java.util.function.Consumer
;
import
org.jooq.lambda.function.Consumer2
;
import
org.jooq.lambda.tuple.Tuple2
;
/**
* Iterable of two-arity tuples that also has a forEach with two arguments.
*
* @param <E1> the type of the first element
* @param <E2> the type of the second element
*
* @author alfonso.landin@udc.es
*/
@FunctionalInterface
public
interface
Iterable2
<
E1
,
E2
>
extends
Iterable
<
Tuple2
<
E1
,
E2
>>
{
/**
* Performs the give action for each tuple of the {@link Iterable2}.
*
* @param action The action to be performed for each tuple.
*/
default
void
forEach
(
final
Consumer2
<?
super
E1
,
?
super
E2
>
action
)
{
forEach
(
pair
->
action
.
accept
(
pair
.
v1
,
pair
.
v2
));
}
/**
* {@inheritDoc}
*/
@Override
Iterator
<
Tuple2
<
E1
,
E2
>>
iterator
();
/**
* {@inheritDoc}
*/
@Override
default
void
forEach
(
final
Consumer
<?
super
Tuple2
<
E1
,
E2
>>
action
)
{
Iterable
.
super
.
forEach
(
action
);
}
/**
* {@inheritDoc}
*/
@Override
default
Spliterator
<
Tuple2
<
E1
,
E2
>>
spliterator
()
{
return
Iterable
.
super
.
spliterator
();
}
}
src/main/java/org/irlab/cartesianproduct/Iterable3.java
0 → 100644
View file @
f85d312c
/*
* Copyright 2019 Information Retrieval Lab - University of A Coruña