// Path: datagen/src/main/java/io/qala/datagen/adaptors/DatagenRandom.java
// @SuppressWarnings("AnonymousHasLambdaAlternative"/*this is compiled for Java5*/)
// public class DatagenRandom extends Random {
//     //Public Morozov. Need this to be available for classes in this package.
//     @Override public int next(int bits) {
//         long oldseed = getCurrentSeed(), nextseed;
//         do {
//             nextseed = (oldseed * multiplier + addend) & mask;
//         } while (oldseed == nextseed);
// 
//         super.setSeed(nextseed);
//         overrideSeed(nextseed);
//         return (int)(nextseed >>> (48 - bits));
//     }
// 
//     @SuppressWarnings("WeakerAccess")
//     public static void overrideSeed(long seed) { SEEDS.set(seed)   ;}
//     @SuppressWarnings("WeakerAccess")
//     public static long getCurrentSeed()        { return SEEDS.get();}
// 
//     private static final long multiplier = 0x5DEECE66DL;
//     private static final long addend = 0xBL;
//     private static final long mask = (1L << 48) - 1;
//     private static final ThreadLocal<Long> SEEDS = new ThreadLocal<Long>() {
//         @Override protected Long initialValue() {
//             return System.nanoTime();
//         }
//     };
// }


import io.qala.datagen.adaptors.DatagenRandom;
import io.qala.datagen.Seed;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
package io.qala.datagen.junit.jupiter;



public class DatagenUtils {
    private static final Logger LOG = LoggerFactory.getLogger(DatagenUtils.class);

    static boolean passCaseNameToTestMethod(ExtensionContext context) {
        Optional<Method> testMethod = context.getTestMethod();
        return testMethod.filter(method -> method.getParameterCount() == 2).isPresent();
    }

    public static void setCurrentSeedIfNotSetYet(ExtensionContext context) {
        if(getCurrentLevelSeedFromStore(context) != null) return;

        Optional<Method> testMethod = context.getTestMethod();
        Optional<Class<?>> testClass = context.getTestClass();
        if(testMethod.isPresent()) {
            Seed annotation = testMethod.get().getAnnotation(Seed.class);
// Path: datagen/src/main/java/io/qala/datagen/adaptors/DatagenRandom.java
// @SuppressWarnings("AnonymousHasLambdaAlternative"/*this is compiled for Java5*/)
// public class DatagenRandom extends Random {
//     //Public Morozov. Need this to be available for classes in this package.
//     @Override public int next(int bits) {
//         long oldseed = getCurrentSeed(), nextseed;
//         do {
//             nextseed = (oldseed * multiplier + addend) & mask;
//         } while (oldseed == nextseed);
// 
//         super.setSeed(nextseed);
//         overrideSeed(nextseed);
//         return (int)(nextseed >>> (48 - bits));
//     }
// 
//     @SuppressWarnings("WeakerAccess")
//     public static void overrideSeed(long seed) { SEEDS.set(seed)   ;}
//     @SuppressWarnings("WeakerAccess")
//     public static long getCurrentSeed()        { return SEEDS.get();}
// 
//     private static final long multiplier = 0x5DEECE66DL;
//     private static final long addend = 0xBL;
//     private static final long mask = (1L << 48) - 1;
//     private static final ThreadLocal<Long> SEEDS = new ThreadLocal<Long>() {
//         @Override protected Long initialValue() {
//             return System.nanoTime();
//         }
//     };
// }


// Path: junit5/src/main/java/io/qala/datagen/junit/jupiter/DatagenUtils.java
import io.qala.datagen.adaptors.DatagenRandom;
import io.qala.datagen.Seed;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;

package io.qala.datagen.junit.jupiter;



public class DatagenUtils {
    private static final Logger LOG = LoggerFactory.getLogger(DatagenUtils.class);

    static boolean passCaseNameToTestMethod(ExtensionContext context) {
        Optional<Method> testMethod = context.getTestMethod();
        return testMethod.filter(method -> method.getParameterCount() == 2).isPresent();
    }

    public static void setCurrentSeedIfNotSetYet(ExtensionContext context) {
        if(getCurrentLevelSeedFromStore(context) != null) return;

        Optional<Method> testMethod = context.getTestMethod();
        Optional<Class<?>> testClass = context.getTestClass();
        if(testMethod.isPresent()) {
            Seed annotation = testMethod.get().getAnnotation(Seed.class);
            if (annotation != null) DatagenRandom.overrideSeed(annotation.value());