com.github.leeonky.jfactory.SingleValueExpression Maven / Gradle / Ivy
package com.github.leeonky.jfactory;
import com.github.leeonky.util.CollectionHelper;
import com.github.leeonky.util.Property;
import java.util.Objects;
class SingleValueExpression extends Expression
{
private final Object value;
private final TraitsSpec traitsSpec;
public SingleValueExpression(Object value, TraitsSpec traitsSpec, Property
property) {
super(property);
this.value = value;
this.traitsSpec = traitsSpec;
}
@Override
protected boolean isPropertyMatch(Object propertyValue) {
return property.getReaderType().isCollection() ? CollectionHelper.equals(propertyValue, value)
: Objects.equals(propertyValue, property.getReader().tryConvert(value));
}
@Override
public Producer> buildProducer(JFactory jFactory, Producer
parent) {
if (intently)
return traitsSpec.toBuilder(jFactory, property.getWriterType()).createProducer();
return new FixedValueProducer<>(property.getWriterType(), value);
}
}