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

net.jqwik.engine.properties.configurators.UniqueCharsConfigurator Maven / Gradle / Ivy

The newest version!
package net.jqwik.engine.properties.configurators;

import net.jqwik.api.*;
import net.jqwik.api.arbitraries.*;
import net.jqwik.api.configurators.*;
import net.jqwik.api.constraints.*;
import net.jqwik.api.providers.*;

public class UniqueCharsConfigurator extends ArbitraryConfiguratorBase {

	@Override
	protected boolean acceptTargetType(TypeUsage targetType) {
		return targetType.canBeAssignedTo(TypeUsage.of(CharSequence.class));
	}

	public Arbitrary configure(Arbitrary arbitrary, UniqueChars uniqueChars) {
		if (arbitrary instanceof StringArbitrary) {
			return ((StringArbitrary) arbitrary).uniqueChars();
		} else {
			return arbitrary.filter(this::hasUniqueChars);
		}
	}

	private boolean hasUniqueChars(CharSequence charSequence) {
		return charSequence.chars().distinct().count() == charSequence.length();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy