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

io.github.kiryu1223.expressionTree.expressions.LambdaExpression Maven / Gradle / Ivy

There is a newer version: 1.4.5
Show newest version
package io.github.kiryu1223.expressionTree.expressions;

import io.github.kiryu1223.expressionTree.delegate.Delegate;

import java.util.List;

public class LambdaExpression extends Expression
{
    private final Expression body;
    private final List parameters;
    private final Class returnType;

    public LambdaExpression(Expression body, List parameters, Class returnType)
    {
        this.body = body;
        this.parameters = parameters;
        this.returnType = returnType;
    }

    public Expression getBody()
    {
        return body;
    }

    public List getParameters()
    {
        return parameters;
    }

    public Class getReturnType()
    {
        return returnType;
    }

    @Override
    public Kind getKind()
    {
        return Kind.Lambda;
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("(");
        for (ParameterExpression parameter : parameters)
        {
            sb.append(parameter.getName()).append(",");
        }
        if (sb.charAt(sb.length() - 1) == ',')
        {
            sb.deleteCharAt(sb.length() - 1);
        }
        sb.append(") -> ");
        sb.append(body);
        return sb.toString();
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        LambdaExpression that = (LambdaExpression) obj;
        return body.equals(that.body) && parameters.equals(that.parameters)
                && returnType.equals(that.returnType);
    }

//    public T compile()
//    {
//        return DynamicCompilerUtil.dynamicCompile(this);
//    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy