Search in sources :

Example 1 with TypeAffinity

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))));
}
Also used : ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) InstantiatorDefinitions(org.simpleflatmapper.reflect.instantiator.InstantiatorDefinitions) InputStream(java.io.InputStream) TypeAffinity(org.simpleflatmapper.reflect.TypeAffinity) Parameter(org.simpleflatmapper.reflect.Parameter) Date(java.util.Date) URL(java.net.URL) Test(org.junit.Test)

Example 2 with TypeAffinity

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();
}
Also used : TypeAffinity(org.simpleflatmapper.reflect.TypeAffinity)

Aggregations

TypeAffinity (org.simpleflatmapper.reflect.TypeAffinity)2 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Date (java.util.Date)1 Test (org.junit.Test)1 Parameter (org.simpleflatmapper.reflect.Parameter)1 ExecutableInstantiatorDefinition (org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition)1 InstantiatorDefinitions (org.simpleflatmapper.reflect.instantiator.InstantiatorDefinitions)1