55 lines
1.3 KiB
Java
55 lines
1.3 KiB
Java
package jef.expressions;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.EqualsAndHashCode;
|
|
import lombok.Getter;
|
|
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Getter
|
|
@AllArgsConstructor
|
|
@EqualsAndHashCode
|
|
public class AndExpression implements Expression {
|
|
private final List<Expression> exprs;
|
|
|
|
public AndExpression(Expression... exprs) {
|
|
this.exprs = List.of(exprs);
|
|
}
|
|
|
|
@Override
|
|
public Type getType() {
|
|
return Type.AND;
|
|
}
|
|
|
|
@Override
|
|
public Priority getPriority() {
|
|
return Priority.LOGIC_AND;
|
|
}
|
|
|
|
// @Override
|
|
// public boolean equals(Object o) {
|
|
// if (this == o) return true;
|
|
// if (o == null || getClass() != o.getClass()) return false;
|
|
// AndExpression that = (AndExpression) o;
|
|
// return exprs.equals(that.exprs);
|
|
// }
|
|
//
|
|
// @Override
|
|
// public int hashCode() {
|
|
// return Objects.hash(exprs);
|
|
// }
|
|
|
|
@Override
|
|
public String toString() {
|
|
return exprs.stream().map(e -> {
|
|
if (e.getPriority().getValue() < getPriority().getValue()) {
|
|
return "(" + e + ")";
|
|
} else {
|
|
return e.toString();
|
|
}
|
|
}).collect(Collectors.joining(" AND "));
|
|
}
|
|
}
|