
org.sfm.reflect.meta.OptionalPropertyFinder Maven / Gradle / Ivy
package org.sfm.reflect.meta;
import org.sfm.reflect.InstantiatorDefinition;
import java.util.Arrays;
import java.util.List;
public class OptionalPropertyFinder implements PropertyFinder {
private final OptionalClassMeta tupleClassMeta;
private final PropertyFinder> propertyFinder;
private int nbProp = 0;
private final ClassMeta innerMeta;
public OptionalPropertyFinder(OptionalClassMeta tupleClassMeta) {
this.tupleClassMeta = tupleClassMeta;
innerMeta = tupleClassMeta.getInnerMeta();
this.propertyFinder = innerMeta != null ? innerMeta.newPropertyFinder() : null;
}
@SuppressWarnings("unchecked")
@Override
public PropertyMeta findProperty(PropertyNameMatcher propertyNameMatcher) {
if (!innerMeta.isLeaf()) {
final PropertyMeta, Object> property = propertyFinder.findProperty(propertyNameMatcher);
if (property != null) {
return getSubPropertyMeta((PropertyMeta) property);
}
} else if (nbProp == 0){
nbProp++;
return (PropertyMeta) tupleClassMeta.getProperty();
}
return null;
}
@SuppressWarnings("unchecked")
private PropertyMeta getSubPropertyMeta(PropertyMeta property) {
return new SubPropertyMeta(tupleClassMeta.getReflectionService(), (PropertyMeta) tupleClassMeta.getProperty(), property);
}
@Override
public List getEligibleInstantiatorDefinitions() {
return Arrays.asList(tupleClassMeta.getInstantiatorDefinition());
}
@Override
public ConstructorPropertyMeta findConstructor(InstantiatorDefinition instantiatorDefinition) {
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy