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
Simple java library to generate permutations, combinations and other combinatorial sequences
/**
* 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);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy