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

de.tsl2.nano.modelkit.impl.Func Maven / Gradle / Ivy

Go to download

TSL2 Framework to provide and use a structure of elements referenced by unique names - to declare a kit of logic in a json/yaml/xml text file

The newest version!
/*
 * File: $HeadURL$
 * Id  : $Id$
 * 
 * created by: Tom
 * created on: 31.03.2017
 * 
 * Copyright: (c) Thomas Schneider 2017, all rights reserved
 */
package de.tsl2.nano.modelkit.impl;

import java.util.Objects;
import java.util.function.BiFunction;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class Func extends AIdentified {
    static {
        ModelKitLoader.registereElement(Func.class);
    }

    @JsonIgnore
    private BiFunction func;

    Func() {
    }

    public Func(String name, BiFunction func) {
        super(name);
        this.func = func;
    }

    @Override
    public void validate() {
        Objects.requireNonNull(func,
                () -> config.name + ": func lambda code unavailable (not registered!) on: " + toString());
    }

    public BiFunction getFunction() {
        visited();
        return func;
    }

    public R eval(T par) {
        return eval(null, par);
    }

    public R eval(AIdentified caller, T par) {
        visited(par);
        return func.apply(caller, par);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy