net.joala.condition.ExpressionFunction Maven / Gradle / Ivy
/*
* Copyright 2012 CoreMedia AG
*
* This file is part of Joala.
*
* Joala is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Joala is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Joala. If not, see .
*/
package net.joala.condition;
import com.google.common.base.Function;
import net.joala.condition.timing.IgnorableStateQueryException;
import net.joala.expression.Expression;
import net.joala.expression.ExpressionEvaluationException;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
/**
*
* A function to evaluate an expression. It especially wraps exceptions of type
* {@link ExpressionEvaluationException} into {@link IgnorableStateQueryException}.
*
*
* @param the type of the value the expression returns
* @since 9/18/12
*/
final class ExpressionFunction implements Function, T> {
/**
*
* Evaluates expression and makes any {@link ExpressionEvaluationException} ignorable.
*
*
* @param input the expression to evaluate
* @return the result of the expression
*/
@Override
@Nullable
public T apply(final Expression input) {
checkNotNull(input, "Expression must not be null.");
try {
return input.get();
} catch (ExpressionEvaluationException e) {
throw new IgnorableStateQueryException(this, e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy