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

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

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, boolean selfScoreFullName) {
        super(selfScoreFullName);
        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){
        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); } @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