All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.reflect.meta.OptionalPropertyFinder Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.reflect.meta;

import org.simpleflatmapper.reflect.InstantiatorDefinition;
import org.simpleflatmapper.util.Predicate;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Optional;

public class OptionalPropertyFinder extends PropertyFinder> {


    private final OptionalClassMeta optionalClassMeta;
    private final PropertyFinder propertyFinder;
    private final ClassMeta innerMeta;

    public OptionalPropertyFinder(OptionalClassMeta optionalClassMeta, Predicate> propertyFilter, boolean selfScoreFullName) {
        super(propertyFilter, selfScoreFullName);
        this.optionalClassMeta = optionalClassMeta;
        innerMeta = optionalClassMeta.getInnerMeta();
        this.propertyFinder = innerMeta != null ? innerMeta.newPropertyFinder(propertyFilter) : null;
	}


    @SuppressWarnings("unchecked")
    @Override
    public void lookForProperties(
            PropertyNameMatcher propertyNameMatcher,
            Object[] properties, FoundProperty matchingProperties,
            PropertyMatchingScore score, boolean allowSelfReference, PropertyFinderTransformer propertyFinderTransformer){
        propertyFinderTransformer.apply(propertyFinder).lookForProperties(propertyNameMatcher, properties, new FoundProperty() {
            @Override
            public 

> void found(P propertyMeta, Runnable selectionCallback, PropertyMatchingScore score) { matchingProperties.found(getSubPropertyMeta(propertyMeta), selectionCallback, score); } }, score, allowSelfReference, propertyFinderTransformer); } @SuppressWarnings("unchecked") private PropertyMeta, E> getSubPropertyMeta(PropertyMeta property) { return new SubPropertyMeta, I, E>( optionalClassMeta.getReflectionService(), (PropertyMeta, I>) optionalClassMeta.getProperty(), (PropertyMeta)property); } @Override public List getEligibleInstantiatorDefinitions() { return optionalClassMeta.getInstantiatorDefinitions(); } @Override public PropertyFinder getSubPropertyFinder(PropertyMeta owner) { if (owner.equals(optionalClassMeta.getProperty())) { return propertyFinder; } throw new IllegalArgumentException("Unexpected owner " + owner); } @Override public PropertyFinder getOrCreateSubPropertyFinder(SubPropertyMeta subPropertyMeta) { return getSubPropertyFinder(subPropertyMeta.getOwnerProperty()); } @Override public Type getOwnerType() { return optionalClassMeta.getType(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy