Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
autofixture.publicinterface.thirdpartysupport.AnyVavr Maven / Gradle / Ivy
package autofixture.publicinterface.thirdpartysupport;
import autofixture.interfaces.InlineConstrainedGenerator;
import autofixture.publicinterface.Any;
import autofixture.publicinterface.InstanceOf;
import io.vavr.collection.*;
import io.vavr.control.Either;
import io.vavr.control.Option;
import io.vavr.control.Try;
import io.vavr.control.Validation;
import lombok.NonNull;
import static autofixture.generators.objects.implementationdetails.TypeAssertions.assertIsNotParameterized;
import static autofixture.implementationdetails.ErrorMessages.msg;
import static autofixture.implementationdetails.ErrorMessages.msgInline;
public class AnyVavr {
//todo add generics checks
//todo add first-party check to autofixture engine
@NonNull
public static List listOf(Class clazz) {
assertIsNotParameterized(clazz, msg("listOf"));
return io.vavr.collection.List.ofAll(Any.listOf(clazz));
}
@NonNull
public static List listOf(final InstanceOf clazz) {
return io.vavr.collection.List.ofAll(Any.listOf(clazz));
}
@NonNull
public static List listOf(final InstanceOf clazz, final InlineConstrainedGenerator generator) {
return io.vavr.collection.List.ofAll(Any.listOf(clazz, generator));
}
@NonNull
public static List listOf(final Class type, final InlineConstrainedGenerator omittedValues) {
assertIsNotParameterized(type, msgInline("listOf"));
return List.ofAll(Any.listOf(type, omittedValues));
}
/////////////// arrays
@NonNull
public static Array arrayOf(Class clazz) {
assertIsNotParameterized(clazz, msg("arrayOf"));
return Array.ofAll(Any.listOf(clazz));
}
@NonNull
public static Array arrayOf(final InstanceOf clazz) {
return Array.ofAll(Any.listOf(clazz));
}
@NonNull
public static Array arrayOf(final InstanceOf clazz, final InlineConstrainedGenerator generator) {
return Array.ofAll(Any.listOf(clazz, generator));
}
@NonNull
public static Array arrayOf(final Class type, final InlineConstrainedGenerator omittedValues) {
assertIsNotParameterized(type, msgInline("arrayOf"));
return Array.ofAll(Any.listOf(type, omittedValues));
}
/////////////// hashsets
@NonNull
public static HashSet hashSetOf(Class clazz) {
assertIsNotParameterized(clazz, msg("hashSetOf"));
return HashSet.ofAll(Any.listOf(clazz));
}
@NonNull
public static HashSet hashSetOf(final InstanceOf clazz) {
return HashSet.ofAll(Any.listOf(clazz));
}
@NonNull
public static HashSet hashSetOf(final InstanceOf clazz, final InlineConstrainedGenerator generator) {
return HashSet.ofAll(Any.listOf(clazz, generator));
}
@NonNull
public static HashSet hashSetOf(final Class type, final InlineConstrainedGenerator omittedValues) {
assertIsNotParameterized(type, msgInline("hashSetOf"));
return HashSet.ofAll(Any.listOf(type, omittedValues));
}
//////// tree sets
@NonNull
public static TreeSet treeSetOf(Class clazz) {
assertIsNotParameterized(clazz, msg("treeSetOf"));
return TreeSet.ofAll((Iterable)Any.iterableOf(clazz));
}
@NonNull
public static TreeSet treeSetOf(final InstanceOf clazz) {
return TreeSet.ofAll((Iterable)Any.listOf(clazz));
}
@NonNull
public static TreeSet treeSetOf(final InstanceOf clazz, final InlineConstrainedGenerator generator) {
return TreeSet.ofAll((Iterable)Any.listOf(clazz, generator));
}
@NonNull
public static TreeSet treeSetOf(final Class type, final InlineConstrainedGenerator omittedValues) {
assertIsNotParameterized(type, msgInline("treeSetOf"));
return TreeSet.ofAll((Iterable)Any.listOf(type, omittedValues));
}
//////// sets
@NonNull
public static Set setOf(Class clazz) {
assertIsNotParameterized(clazz, msg("setOf"));
return hashSetOf(clazz);
}
@NonNull
public static Set setOf(final InstanceOf clazz) {
return hashSetOf(clazz);
}
@NonNull
public static Set setOf(final InstanceOf clazz, final InlineConstrainedGenerator generator) {
return hashSetOf(clazz, generator);
}
@NonNull
public static Set setOf(final Class type, final InlineConstrainedGenerator omittedValues) {
assertIsNotParameterized(type, msgInline("setOf"));
return hashSetOf(type, omittedValues);
}
/////// sorted sets
@NonNull
public static SortedSet sortedSetOf(Class clazz) {
assertIsNotParameterized(clazz, msg("sortedSetOf"));
return treeSetOf(clazz);
}
@NonNull
public static SortedSet sortedSetOf(final InstanceOf clazz) {
return treeSetOf(clazz);
}
@NonNull
public static SortedSet sortedSetOf(final InstanceOf clazz, final InlineConstrainedGenerator generator) {
return treeSetOf(clazz, generator);
}
@NonNull
public static SortedSet sortedSetOf(final Class type, final InlineConstrainedGenerator omittedValues) {
assertIsNotParameterized(type, msgInline("sortedSetOf"));
return treeSetOf(type, omittedValues);
}
/////////////////////////////// hash maps
@NonNull
public static HashMap hashMapBetween(final Class keyClass, final Class valueClass) {
assertIsNotParameterized(keyClass, "generic key types are not allowed for this method.");
assertIsNotParameterized(valueClass, "generic value types are not allowed for this method.");
return HashMap.ofAll(Any.mapBetween(keyClass, valueClass));
}
@NonNull
public static HashMap hashMapBetween(final InstanceOf keyType, final InstanceOf valueType) {
return HashMap.ofAll(Any.mapBetween(keyType, valueType));
}
/////////////////////////////// maps
@NonNull
public static Map mapBetween(final Class keyClass, final Class valueClass) {
assertIsNotParameterized(keyClass, "generic key types are not allowed for this method.");
assertIsNotParameterized(valueClass, "generic value types are not allowed for this method.");
return hashMapBetween(keyClass, valueClass);
}
@NonNull
public static Map mapBetween(final InstanceOf keyType, final InstanceOf valueType) {
return hashMapBetween(keyType, valueType);
}
@NonNull
public static LinkedHashMap linkedHashMapBetween(final Class keyClass, final Class valueClass) {
assertIsNotParameterized(keyClass, "generic key types are not allowed for this method.");
assertIsNotParameterized(valueClass, "generic value types are not allowed for this method.");
return LinkedHashMap.ofAll(Any.mapBetween(keyClass, valueClass));
}
@NonNull
public static LinkedHashMap linkedHashMapBetween(final InstanceOf keyType, final InstanceOf valueType) {
return LinkedHashMap.ofAll(Any.mapBetween(keyType, valueType));
}
//////////////////// queues
@NonNull
public static Queue queueOf(Class clazz) {
assertIsNotParameterized(clazz, msg("queueOf"));
return Queue.ofAll(Any.queueOf(clazz));
}
@NonNull
public static Queue queueOf(final InstanceOf clazz) {
return Queue.ofAll(Any.queueOf(clazz));
}
@NonNull
public static Queue queueOf(final InstanceOf clazz, final InlineConstrainedGenerator generator) {
return Queue.ofAll(Any.queueOf(clazz, generator));
}
@NonNull
public static Queue queueOf(final Class type, final InlineConstrainedGenerator omittedValues) {
assertIsNotParameterized(type, msgInline("queueOf"));
return Queue.ofAll(Any.queueOf(type, omittedValues));
}
// options
@NonNull
public static Option option(final Class type) {
assertIsNotParameterized(type, msgInline("option"));
return Option.of(Any.instanceOf(type));
}
@NonNull
public static Option option(final InstanceOf type) {
return Option.of(Any.anonymous(type));
}
// eithers - left
@NonNull
public static Either left(final Class leftType) {
assertIsNotParameterized(leftType, msgInline("left"));
return Either.left(Any.instanceOf(leftType));
}
@NonNull
public static Either left(final InstanceOf leftType) {
return Either.left(Any.anonymous(leftType));
}
// eithers - right
@NonNull
public static Either right(final Class rightType) {
assertIsNotParameterized(rightType, msgInline("right"));
return Either.right(Any.instanceOf(rightType));
}
@NonNull
public static Either right(final InstanceOf rightType) {
return Either.right(Any.anonymous(rightType));
}
// validations - failures
@NonNull
public static Validation validationFailed(final Class type) {
assertIsNotParameterized(type, msgInline("validationFailed"));
return Validation.invalid(Any.instanceOf(type));
}
@NonNull
public static Validation validationFailed(final InstanceOf type) {
return Validation.invalid(Any.anonymous(type));
}
// validations - successful
@NonNull
public static Validation validationSuccess(final Class type) {
assertIsNotParameterized(type, msgInline("validationSuccess"));
return Validation.valid(Any.instanceOf(type));
}
@NonNull
public static Validation validationSuccess(final InstanceOf type) {
return Validation.valid(Any.anonymous(type));
}
// try - failures
@NonNull
public static Try tryFailed() {
return Try.failure(Any.throwable());
}
// try - successful
@NonNull
public static Try trySuccess(final Class type) {
assertIsNotParameterized(type, msgInline("trySuccess"));
return Try.success(Any.instanceOf(type));
}
@NonNull
public static Try trySuccess(final InstanceOf type) {
return Try.success(Any.anonymous(type));
}
//multimap, hashmultimap, linkedhashmultimap
//priorityqueue,
//charseq, indexedseq, seq
}