org.simpleflatmapper.reflect.meta.ConstructorPropertyMeta Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-reflect Show documentation
Show all versions of sfm-reflect Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.simpleflatmapper.reflect.meta;
import org.simpleflatmapper.reflect.Getter;
import org.simpleflatmapper.reflect.InstantiatorDefinition;
import org.simpleflatmapper.reflect.ScoredSetter;
import org.simpleflatmapper.reflect.Parameter;
import org.simpleflatmapper.reflect.ReflectionService;
import org.simpleflatmapper.reflect.ScoredGetter;
import org.simpleflatmapper.reflect.Setter;
import java.lang.reflect.Type;
public class ConstructorPropertyMeta extends PropertyMeta {
private final ScoredSetter scoredSetter;
private final ScoredGetter scoredGetter;
private final Parameter parameter;
private final InstantiatorDefinition instantiatorDefinition;
private final Object[] defineProperties;
public ConstructorPropertyMeta(String name,
Type ownerType,
ReflectionService reflectService,
Parameter parameter,
InstantiatorDefinition instantiatorDefinition,
Object[] defineProperties) {
this(name, ownerType, reflectService, parameter, ScoredGetter.nullGetter(), ScoredSetter.nullSetter(), instantiatorDefinition, defineProperties);
}
public ConstructorPropertyMeta(String name,
Type ownerType,
ReflectionService reflectService,
Parameter parameter,
ScoredGetter scoredGetter,
ScoredSetter scoredSetter,
InstantiatorDefinition instantiatorDefinition, Object[] defineProperties) {
super(name, ownerType, reflectService);
this.parameter = parameter;
this.scoredGetter = scoredGetter;
this.scoredSetter = scoredSetter;
this.instantiatorDefinition = instantiatorDefinition;
this.defineProperties = defineProperties;
}
@Override
public Setter super T, ? super P> getSetter() {
return scoredSetter.getSetter();
}
@Override
public Getter super T, ? extends P> getGetter() {
return scoredGetter.getGetter();
}
public ConstructorPropertyMeta defineProperties(Object[] defineProperties) {
if (defineProperties != null) {
return new ConstructorPropertyMeta(getName(), getOwnerType(), reflectService, parameter, scoredGetter, scoredSetter, instantiatorDefinition, ObjectPropertyMeta.concatenate(this.defineProperties, defineProperties));
} else {
return this;
}
}
public ConstructorPropertyMeta getter(ScoredGetter getter) {
if (getter.isBetterThan(this.scoredGetter)) {
return new ConstructorPropertyMeta(getName(), getOwnerType(), reflectService, parameter, getter, scoredSetter, instantiatorDefinition, defineProperties);
} else {
return this;
}
}
public ConstructorPropertyMeta setter(ScoredSetter setter) {
if (setter.isBetterThan(this.scoredSetter)) {
return new ConstructorPropertyMeta(getName(), getOwnerType(), reflectService, parameter, scoredGetter, setter, instantiatorDefinition, defineProperties);
} else {
return this;
}
}
@Override
public Type getPropertyType() {
return parameter.getGenericType();
}
public Parameter getParameter() {
return parameter;
}
public boolean isConstructorProperty() {
return true;
}
@Override
public Object[] getDefinedProperties() {
return defineProperties;
}
@Override
public String getPath() {
return getName();
}
@Override
public String toString() {
return "ConstructorPropertyMeta{" +
"owner=" + getOwnerType() +
", constructorParameter=" + parameter +
'}';
}
public ConstructorPropertyMeta withReflectionService(ReflectionService reflectionService) {
return new ConstructorPropertyMeta(getName(), getOwnerType(), reflectionService, parameter, scoredGetter, scoredSetter, instantiatorDefinition, defineProperties);
}
@Override
public PropertyMeta toNonMapped() {
throw new UnsupportedOperationException();
}
}