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

io.nosqlbench.virtdata.library.basics.shared.from_long.to_uuid.Expr Maven / Gradle / Ivy

Go to download

Statistical sampling library for use in virtdata libraries, based on apache commons math 4

There is a newer version: 5.17.0
Show newest version
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_uuid;

import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.core.MVELExpr;
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
import org.mvel2.MVEL;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.LongFunction;

@ThreadSafeMapper
public class Expr implements LongFunction {

    private final String expr;
    private final Serializable compiledExpr;

    public Expr(String expr) {
        this.expr = expr;
        this.compiledExpr = MVELExpr.compile(long.class, "cycle", expr);
    }

    @Override
    public UUID apply(long operand) {
        ConcurrentHashMap gl_map = SharedState.gl_ObjectMap;
        HashMap map = SharedState.tl_ObjectMap.get();

        // merge gl into tl, for duplicates use the value from tl
        for (Map.Entry stringObjectEntry : gl_map.entrySet()) {
            map.merge(stringObjectEntry.getKey(), stringObjectEntry.getValue(), (entry1, entry2) -> entry1);
        }

        map.put("cycle",operand);
        UUID result = MVEL.executeExpression(compiledExpr, map, UUID.class);
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy