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

com.g2forge.alexandria.expression.eval.SimpleEvaluator Maven / Gradle / Ivy

Go to download

A library for expressions and their evaluation. Includes a basic implementation for math.

There is a newer version: 0.0.18
Show newest version
package com.g2forge.alexandria.expression.eval;

import java.util.function.Supplier;

import com.g2forge.alexandria.expression.ExpressionNotEvaluableException;
import com.g2forge.alexandria.expression.IEnvironment;
import com.g2forge.alexandria.expression.IExpression;
import com.g2forge.alexandria.expression.IVariable;
import com.g2forge.alexandria.java.close.ICloseable;
import com.g2forge.alexandria.java.function.IFunction2;

public class SimpleEvaluator, N extends IEnvironment, E extends IExpression> implements IEvaluator {
	@Override
	public E apply(E expression, N environment, Supplier supplier) {
		return supplier.get();
	}

	@SuppressWarnings("unchecked")
	@Override
	public E apply(String description, E expression, N environment) {
		if (expression == null) { throw new NullPointerException(); }
		return (E) expression.apply(environment);
	}

	@Override
	public ICloseable debug() {
		return () -> {};
	}

	@Override
	public  T eval(E expression, Class type, Supplier supplier) throws ExpressionNotEvaluableException {
		return supplier.get();
	}

	@Override
	public  T eval(String description, E expression, Class type, IFunction2, ? extends T> function) throws ExpressionNotEvaluableException {
		return function.apply(expression, type);
	}

	@Override
	public E reduce(E expression, Supplier supplier) {
		return supplier.get();
	}

	@SuppressWarnings("unchecked")
	@Override
	public E reduce(String description, E expression) {
		return (E) expression.reduce();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy