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

org.tensorics.expression.PredicateExpression 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.List;
import java.util.function.Predicate;

import org.tensorics.core.tree.domain.AbstractDeferredExpression;
import org.tensorics.core.tree.domain.Expression;

import com.google.common.collect.ImmutableList;

public class PredicateExpression extends AbstractDeferredExpression {

    private final Expression source;
    private final Expression> predicate;

    private PredicateExpression(Expression source, Expression> predicate) {
        super();
        this.source = source;
        this.predicate = predicate;
    }

    public static  PredicateExpression ofSourceAndPredicate(Expression source,
            Expression> predicate) {
        return new PredicateExpression<>(source, predicate);
    }

    @Override
    public List> getChildren() {
        return ImmutableList.of(source, predicate);
    }

    public Expression source() {
        return source;
    }

    public Expression> predicate() {
        return predicate;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
        result = prime * result + ((source == null) ? 0 : source.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;
        }
        PredicateExpression other = (PredicateExpression) obj;
        if (predicate == null) {
            if (other.predicate != null) {
                return false;
            }
        } else if (!predicate.equals(other.predicate)) {
            return false;
        }
        if (source == null) {
            if (other.source != null) {
                return false;
            }
        } else if (!source.equals(other.source)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "PredicateCondition [source=" + source + ", predicate=" + predicate + "]";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy