Example usage for org.apache.commons.lang3.reflect TypeLiteral TypeLiteral

List of usage examples for org.apache.commons.lang3.reflect TypeLiteral TypeLiteral

Introduction

In this page you can find the example usage for org.apache.commons.lang3.reflect TypeLiteral TypeLiteral.

Prototype

protected TypeLiteral() 

Source Link

Document

The default constructor.

Usage

From source file:QuickTest.java

@Test
public void testTyped() {
    final Typed stringList = new TypeLiteral<List<String>>() {
    };//  w ww .  j av  a 2s . c o  m

    final Typed stringArrayList = new TypeLiteral<ArrayList<String>>() {
    };

    log.info(String.format("stringList : %s", stringList));
    log.info(String.format("stringList.getType() : %s", stringList.getType()));

    assertThat(TypeUtils.isAssignable(stringArrayList.getType(), stringList.getType()), is(true));
    assertThat(TypeUtils.isAssignable(stringList.getType(), stringArrayList.getType()), is(false));
    assertThat(TypeUtils.isAssignable(stringList.getType(), stringArrayList.getType()), is(false));
}

From source file:org.talend.daikon.properties.property.PropertyFactory.java

public static Property<Double> newDouble(String name) {
    return new Property<>(new TypeLiteral<Double>() {// left empty on purpose
    }, name);//from  ww w  .  ja  v a2 s .c om
}

From source file:org.talend.daikon.properties.property.PropertyFactory.java

public static Property<Float> newFloat(String name) {
    return new Property<>(new TypeLiteral<Float>() {// left empty on purpose
    }, name);/*from www .j  a  v a2 s .c om*/
}

From source file:org.talend.daikon.properties.property.PropertyFactory.java

public static Property<Boolean> newBoolean(String name) {
    return new Property<>(new TypeLiteral<Boolean>() {// left empty on purpose
    }, name).setValue(Boolean.FALSE);
}

From source file:org.talend.daikon.properties.property.PropertyFactory.java

public static Property<Date> newDate(String name) {
    return new Property<>(new TypeLiteral<Date>() {// left empty on purpose
    }, name);/*from  w w  w  .jav a  2  s.  com*/
}

From source file:org.talend.daikon.properties.PropertyFactoryTest.java

@Test
public void testNewProperty_WithTypeAndTitle() {
    Property<Boolean> element = PropertyFactory.newProperty(new TypeLiteral<Boolean>() {// left empty on purpose
    }, "testProperty", "title");
    assertEquals("testProperty", element.getName());
    assertNull(element.getValue());/*from   ww w .ja v a  2s .  co  m*/
    assertEquals("title", element.getTitle());
    assertEquals(TypeUtils.toString(Boolean.class), element.getType());
}

From source file:org.talend.daikon.properties.PropertyFactoryTest.java

@Test
public void testNewProperty_WithType() {
    Property<Boolean> element = PropertyFactory.newProperty(new TypeLiteral<Boolean>() {// left empty on purpose
    }, "testProperty");
    assertEquals("testProperty", element.getName());
    assertNull(element.getValue());/*from   w w w  . jav a2 s  . c om*/
    assertNull(element.getTitle());
    assertEquals(TypeUtils.toString(Boolean.class), element.getType());
}

From source file:therian.operator.add.AddEntryToMapTest.java

@Test
public void testTypedMap() {
    final Map<String, MetasyntacticVariable> m = new HashMap<>();
    assertTrue(therianContext/*from ww  w  .  j  a  v a  2 s .c om*/
            .eval(Add.to(Positions.readWrite(new TypeLiteral<Map<String, MetasyntacticVariable>>() {
            }, m), Positions.readOnly(Pair.of(MetasyntacticVariable.FOO.name(), MetasyntacticVariable.FOO))))
            .booleanValue());
    assertEquals(1, m.size());
    assertEquals(Pair.of(MetasyntacticVariable.FOO.name(), MetasyntacticVariable.FOO),
            m.entrySet().iterator().next());
}

From source file:therian.operator.add.AddEntryToMapTest.java

@Test(expected = OperationException.class)
public void testImmutableMap() {
    therianContext.eval(Add.to(Positions.readWrite(new TypeLiteral<Map<String, MetasyntacticVariable>>() {
    }, Collections.singletonMap(MetasyntacticVariable.FOO.name(), MetasyntacticVariable.FOO)),
            Positions.readOnly(Pair.of(MetasyntacticVariable.BAR.name(), MetasyntacticVariable.BAR))));
}

From source file:therian.operator.add.AddEntryToMapTest.java

@Test(expected = OperationException.class)
public void testWrongKeyTypeMap() {
    therianContext.eval(Add.to(Positions.readWrite(new TypeLiteral<Map<String, String>>() {
    }, new HashMap<>()), Positions.readOnly(new TypeLiteral<Map.Entry<Integer, String>>() {
    }, Pair.of(Integer.valueOf(666), "foo"))));
}