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

net.jqwik.vavr.arbitraries.collection.set.VavrBitSetArbitrary Maven / Gradle / Ivy

package net.jqwik.vavr.arbitraries.collection.set;

import net.jqwik.vavr.arbitraries.base.SetBasedArbitrary;
import io.vavr.collection.BitSet;
import net.jqwik.api.Arbitrary;

import java.util.Set;

/**
 * TODO  net.jqwik.api.providers.ArbitraryProvider -> add line net.jqwik.vavr.providers.collection.set.VavrBitSetArbitraryProvider
 *
 * @author Benno Müller
 */
public class VavrBitSetArbitrary extends SetBasedArbitrary> {

    public VavrBitSetArbitrary(final Arbitrary elementArbitrary) {
        super(elementArbitrary);
    }

    @SuppressWarnings("unchecked")
    @Override
    protected BitSet convertJavaSetToVavrCollection(final java.util.Set javaSet) {
        if (javaSet.isEmpty()) {
            return BitSet.empty();
        } else {
            final Class elementClass = javaSet.iterator().next().getClass();
            if (Integer.class.isAssignableFrom(elementClass)) {
                final Set javaSet1 = (Set) javaSet;
                return BitSet.ofAll(javaSet1);
            } else if (Short.class.isAssignableFrom(elementClass)) {
                final Set javaSet1 = (Set) javaSet;
                return BitSet.withShorts().ofAll(javaSet1);
            } else if (Long.class.isAssignableFrom(elementClass)) {
                final Set javaSet1 = (Set) javaSet;
                return BitSet.withLongs().ofAll(javaSet1);
//            } else if (Boolean.class.isAssignableFrom(elementClass)) { // TODO Läuft ewig
//                final Set javaSet1 = (Set) javaSet;
//                // see io.vavr.collection.BitSet.ofAll(boolean...)
//                return BitSet.withRelations(i -> i != 0, b -> b ? 1 : 0).ofAll(javaSet1);
            } else if (Byte.class.isAssignableFrom(elementClass)) {
                final Set javaSet1 = (Set) javaSet;
                return BitSet.withBytes().ofAll(javaSet1);
            } else if (Character.class.isAssignableFrom(elementClass)) {
                final Set javaSet1 = (Set) javaSet;
                return BitSet.withCharacters().ofAll(javaSet1);
//            } else if (Enum.class.isAssignableFrom(elementClass)) { // TODO Läuft ewig
//                final Set javaSet1 = (Set) javaSet;
//                return BitSet.withEnum((Class) elementClass).ofAll(javaSet1);
            } else {
                throw new IllegalArgumentException("element class [" + elementClass.getName() + "] not supported for "
                        + BitSet.class.getName());
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy