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

org.paukov.combinatorics3.PermutationGenerator Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
/**
 * 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 - 2024 Weber Informatics LLC | Privacy Policy