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

de.tsl2.nano.bean.def.AttributeFinder Maven / Gradle / Ivy

Go to download

TSL2 Framework Descriptor (currency-handling, generic formatter, descriptors for beans, collections, actions and values)

There is a newer version: 2.5.1
Show newest version
/*
 * File: $HeadURL$
 * Id  : $Id$
 * 
 * created by: Tom
 * created on: 24.03.2017
 * 
 * Copyright: (c) Thomas Schneider 2017, all rights reserved
 */
package de.tsl2.nano.bean.def;

import java.util.LinkedList;
import java.util.List;

import de.tsl2.nano.collection.CollectionUtil;
import de.tsl2.nano.core.ITransformer;
import de.tsl2.nano.core.cls.BeanClass;
import de.tsl2.nano.core.util.StringUtil;
import de.tsl2.nano.util.FuzzyFinder;
import de.tsl2.nano.util.IFuzzyDescriptor;

/**
 * 
 * @author Tom
 * @version $Revision$ 
 */
public class AttributeFinder extends FuzzyFinder {

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public AttributeFinder() {
        super(new IFuzzyDescriptor() {
//            List bvs = (List) BeanClass.getStatic(BeanValue.class, "beanValueCache");
            List bds = (List) BeanClass.getStatic(BeanDefinition.class, "virtualBeanCache");
            
            @Override
            public Iterable getAvailables() {
                return CollectionUtil.getTransforming(collectAttributes(bds), new ITransformer() {
                    @Override
                    public String transform(AttributeDefinition toTransform) {
                        return toTransform.getPath();
                    }
                });
            }

            @Override
            public double distance(String item, String expression) {
                return StringUtil.fuzzyMatch(item, expression);
            }
        });
    }
    @SuppressWarnings({ "rawtypes", "unchecked" })
    static List collectAttributes(List bds) {
        List attrs = new LinkedList();
        for (BeanDefinition bd : bds) {
            attrs.addAll(bd.getAttributeDefinitions().values());
        }
        return attrs;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy