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;

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


    @SuppressWarnings("unchecked")
    @Override
    public void lookForProperties(
            PropertyNameMatcher propertyNameMatcher,
            Object[] properties, 
            FoundProperty> matchingProperties,
            PropertyMatchingScore score, boolean allowSelfReference, 
            PropertyFinderTransformer propertyFinderTransformer, 
            TypeAffinityScorer typeAffinityScorer, 
            PropertyFilter propertyFilter, ShortCircuiter shortCircuiter) {

        propertyFinderTransformer.apply(propertyFinder).lookForProperties(propertyNameMatcher, properties, new FoundProperty() {
            @Override
            public 

> void found(P propertyMeta, Runnable selectionCallback, PropertyMatchingScore score, TypeAffinityScorer typeAffinityScorer) { matchingProperties.found(getSubPropertyMeta(propertyMeta), selectionCallback, score, typeAffinityScorer); } }, score, allowSelfReference, propertyFinderTransformer, typeAffinityScorer, propertyFilter, shortCircuiter); } @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