de.tsl2.nano.bean.def.AttributeFinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.descriptor Show documentation
Show all versions of tsl2.nano.descriptor Show documentation
TSL2 Framework Descriptor (currency-handling, generic formatter, descriptors for beans, collections, actions and values)
/*
* 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;
}
}