use of org.simpleflatmapper.reflect.TypeAffinity in project SimpleFlatMapper by arnaudroger.
the class InstantiatorDefinitionTest method testTypeAffinityCompatibilityScorers.
@Test
public void testTypeAffinityCompatibilityScorers() {
InstantiatorDefinitions.CompatibilityScorer compatibilityScorer = InstantiatorDefinitions.getCompatibilityScorer(new TypeAffinity() {
@Override
public Class<?>[] getAffinities() {
return new Class<?>[] { Date.class, URL.class };
}
});
assertEquals(0, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", InputStream.class))));
assertEquals(12, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", Date.class))));
assertEquals(11, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", URL.class))));
assertEquals(1, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", Number.class))));
}
use of org.simpleflatmapper.reflect.TypeAffinity in project SimpleFlatMapper by arnaudroger.
the class InstantiatorDefinitions method getCompatibilityScorer.
public static InstantiatorDefinitions.CompatibilityScorer getCompatibilityScorer(Object key) {
if (key instanceof TypeAffinity) {
TypeAffinity ta = (TypeAffinity) key;
Class<?>[] affinities = ta.getAffinities();
if (affinities != null && affinities.length > 0) {
return new TypeAffinityCompatibilityScorer(affinities);
}
}
return new DefaultCompatibilityScorer();
}
Aggregations