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

org.tensorics.expression.WindowedExpression Maven / Gradle / Ivy

Go to download

Tensoric expression is able to solve an expression tree. Much like a tree coming from a traditional equation, where both operations and operands can be objects and can implement custom behavior

The newest version!
/**
 * Copyright (c) 2016 European Organisation for Nuclear Research (CERN), All Rights Reserved.
 */

package org.tensorics.expression;

import java.util.Arrays;
import java.util.List;

import org.tensorics.core.tree.domain.AbstractDeferredExpression;
import org.tensorics.core.tree.domain.Expression;
import org.tensorics.expression.resolvers.WindowedExpressionResolver;

/**
 * Expression that evaluates the targetExpression given the result of the enabling expression. The enabling
 * expression is an {@link Expression} of {@link Boolean} that decides if the targetExpression is
 * resolved or not. This expression resolves into an {@link EvaluationStatus}.
 * 
 * @see WindowedExpressionResolver
 * @param T the type of the target expression
 * @author acalia, caguiler
 */
public class WindowedExpression> extends AbstractDeferredExpression {

    private final T targetExpression;
    private final Expression enablingExpression;

    public WindowedExpression(T targetExpression, Expression enablingExpression) {
        this.targetExpression = targetExpression;
        this.enablingExpression = enablingExpression;
    }

    @Override
    public List> getChildren() {
        return Arrays.asList(targetExpression, enablingExpression);
    }

    public T targetExpression() {
        return targetExpression;
    }

    public Expression enablingExpression() {
        return enablingExpression;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((enablingExpression == null) ? 0 : enablingExpression.hashCode());
        result = prime * result + ((targetExpression == null) ? 0 : targetExpression.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        WindowedExpression other = (WindowedExpression) obj;
        if (enablingExpression == null) {
            if (other.enablingExpression != null) {
                return false;
            }
        } else if (!enablingExpression.equals(other.enablingExpression)) {
            return false;
        }
        if (targetExpression == null) {
            if (other.targetExpression != null) {
                return false;
            }
        } else if (!targetExpression.equals(other.targetExpression)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.getClass().getSimpleName() + " [targetExpression=" + targetExpression + ", enablingExpression="
                + enablingExpression + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy