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

net.jqwik.engine.properties.shrinking.ShrinkableString Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.engine.properties.shrinking;

import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import net.jqwik.api.*;
import net.jqwik.engine.support.*;

public class ShrinkableString extends ShrinkableContainer {

	public ShrinkableString(List> elements, int minSize, int maxSize) {
		super(elements, minSize, maxSize, Collections.emptySet());
	}

	@Override
	Collector containerCollector() {
		return new CharacterCollector();
	}

	@Override
	Shrinkable createShrinkable(List> shrunkElements) {
		return new ShrinkableString(shrunkElements, minSize, maxSize);
	}

	@Override
	public Stream> shrink() {
		if (elements.size() > 100) {
			return JqwikStreamSupport.concat(
					shrinkSizeAggressively(),
					shrinkSizeOfList(),
					shrinkElementsOneAfterTheOther(100)
			);
		}
		return JqwikStreamSupport.concat(
				shrinkSizeOfList(),
				shrinkElementsOneAfterTheOther(0),
				shrinkPairsOfElements(),
				sortElements()
		);
	}

	private static class CharacterCollector implements Collector {
		@Override
		public Supplier supplier() {
			return StringBuilder::new;
		}

		@Override
		public BiConsumer accumulator() {
			return StringBuilder::appendCodePoint;
		}

		@Override
		public BinaryOperator combiner() {
			return StringBuilder::append;
		}

		@Override
		public Function finisher() {
			return StringBuilder::toString;
		}

		@Override
		public Set characteristics() {
			return Collections.emptySet();
		}

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy