io.github.kiryu1223.expressionTree.expressions.NewArrayExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ExpressionTree Show documentation
Show all versions of ExpressionTree Show documentation
java static expressionTree
package io.github.kiryu1223.expressionTree.expressions;
import java.util.List;
public class NewArrayExpression extends Expression
{
private final Class> type;
private final List counts;
private final List elems;
public NewArrayExpression(Class> type, List counts, List elems)
{
this.type = type;
this.counts = counts;
this.elems = elems;
}
public Class> getType()
{
return type;
}
public List getCounts()
{
return counts;
}
public List getElems()
{
return elems;
}
@Override
public Kind getKind()
{
return Kind.NewArray;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("new ").append(type.getSimpleName());
if(!counts.isEmpty())
{
for (Expression count : counts)
{
sb.append("[").append(count).append("]");
}
}
else
{
sb.append("[]");
}
if(!elems.isEmpty())
{
sb.append("{");
for (Expression elem : elems)
{
sb.append(elem).append(",");
}
if (sb.charAt(sb.length() - 1) == ',')
{
sb.deleteCharAt(sb.length() - 1);
}
sb.append("}");
}
return sb.toString();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
NewArrayExpression that = (NewArrayExpression) obj;
return type.equals(that.type) && counts.equals(that.counts)
&& elems.equals(that.elems);
}
}