org.paukov.combinatorics3.PermutationGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of combinatoricslib3 Show documentation
Show all versions of combinatoricslib3 Show documentation
Combinatorial objects stream generators for Java.
/**
* Combinatorics Library 3
* Copyright 2016 Dmytro Paukov [email protected]
*/
package org.paukov.combinatorics3;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class PermutationGenerator {
public enum TreatDuplicatesAs {
DIFFERENT,
IDENTICAL
}
final Collection originalVector;
public static boolean hasDuplicates(Collection collection) {
if (collection.size() <= 1) {
return false;
}
Set set = new HashSet<>(collection);
return set.size() < collection.size();
}
public PermutationGenerator(Collection originalVector) {
this.originalVector = originalVector;
}
public IGenerator>simple() {
return new SimplePermutationGenerator<>(originalVector, false);
}
public IGenerator> simple(TreatDuplicatesAs treatAsIdentical) {
return new SimplePermutationGenerator<>(originalVector, TreatDuplicatesAs.IDENTICAL.equals(treatAsIdentical));
}
public IGenerator> withRepetitions(int permutationLength) {
return new PermutationWithRepetitionGenerator<>(originalVector, permutationLength);
}
}