Search in sources :

Example 1 with FastTuple

use of com.boundary.tuple.FastTuple in project SimpleFlatMapper by arnaudroger.

the class FastTupleTest method testCsvParser.

@Test
public void testCsvParser() throws IOException {
    final CsvParser.StaticMapToDSL<? extends FastTuple> mapToDSL = CsvParser.mapTo(tuple.getClass()).defaultHeaders();
    final Iterator<? extends FastTuple> iterator = mapToDSL.iterator(new StringReader("6,7,3\n7,8,9"));
    final FastTuple tuple1 = iterator.next();
    final FastTuple tuple2 = iterator.next();
    assertEquals(6l, tuple1.getLong(1));
    assertEquals(7, tuple1.getInt(2));
    assertEquals((short) 3, tuple1.getShort(3));
    assertEquals(7l, tuple2.getLong(1));
    assertEquals(8, tuple2.getInt(2));
    assertEquals((short) 9, tuple2.getShort(3));
}
Also used : FastTuple(com.boundary.tuple.FastTuple) StringReader(java.io.StringReader) CsvParser(org.simpleflatmapper.csv.CsvParser) Test(org.junit.Test)

Example 2 with FastTuple

use of com.boundary.tuple.FastTuple in project SimpleFlatMapper by arnaudroger.

the class FastTupleTest method testMetaDataOnFastTuple.

@Test
public void testMetaDataOnFastTuple() throws Exception {
    // creates a new tuple allocated on the JVM heap
    @SuppressWarnings("unchecked") ClassMeta<FastTuple> cm = ReflectionService.newInstance().getClassMeta((Class<FastTuple>) tuple.getClass());
    final PropertyFinder<FastTuple> propertyFinder = cm.newPropertyFinder(ConstantPredicate.<PropertyMeta<?, ?>>truePredicate());
    final PropertyMeta<FastTuple, Long> fieldA = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldA", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, Integer> fieldB = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldB", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, Short> fieldC = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldC", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, ?> fieldD = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldD", 0, true, true), new Object[0]);
    assertNotNull(fieldA);
    assertNotNull(fieldB);
    assertNotNull(fieldC);
    assertNull(fieldD);
    fieldA.getSetter().set(tuple, 6l);
    assertEquals(6l, fieldA.getGetter().get(tuple).longValue());
    fieldB.getSetter().set(tuple, 7);
    assertEquals(7, fieldB.getGetter().get(tuple).intValue());
    fieldC.getSetter().set(tuple, (short) 3);
    assertEquals(3, fieldC.getGetter().get(tuple).shortValue());
}
Also used : FastTuple(com.boundary.tuple.FastTuple) DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Test(org.junit.Test)

Example 3 with FastTuple

use of com.boundary.tuple.FastTuple in project SimpleFlatMapper by arnaudroger.

the class FastTupleTest method testMetaDataOnFastTupleDirectMemory.

@Test
public void testMetaDataOnFastTupleDirectMemory() throws Exception {
    final TupleSchema tupleSchema = TupleSchema.builder().addField("fieldA", Long.TYPE).addField("fieldB", Integer.TYPE).addField("fieldC", Short.TYPE).directMemory().build();
    final FastTuple tuple = tupleSchema.createTuple();
    // creates a new tuple allocated on the JVM heap
    @SuppressWarnings("unchecked") ClassMeta<FastTuple> cm = ReflectionService.newInstance().getClassMeta((Class<FastTuple>) tuple.getClass());
    final PropertyFinder<FastTuple> propertyFinder = cm.newPropertyFinder(ConstantPredicate.<PropertyMeta<?, ?>>truePredicate());
    final PropertyMeta<FastTuple, Long> fieldA = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldA", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, Integer> fieldB = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldB", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, Short> fieldC = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldC", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, ?> fieldD = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldD", 0, true, true), new Object[0]);
    assertNotNull(fieldA);
    assertNotNull(fieldB);
    assertNotNull(fieldC);
    assertNull(fieldD);
    fieldA.getSetter().set(tuple, 6l);
    assertEquals(6l, fieldA.getGetter().get(tuple).longValue());
    fieldB.getSetter().set(tuple, 7);
    assertEquals(7, fieldB.getGetter().get(tuple).intValue());
    fieldC.getSetter().set(tuple, (short) 3);
    assertEquals(3, fieldC.getGetter().get(tuple).shortValue());
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) TupleSchema(com.boundary.tuple.TupleSchema) FastTuple(com.boundary.tuple.FastTuple) Test(org.junit.Test)

Aggregations

FastTuple (com.boundary.tuple.FastTuple)3 Test (org.junit.Test)3 DefaultPropertyNameMatcher (org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher)2 TupleSchema (com.boundary.tuple.TupleSchema)1 StringReader (java.io.StringReader)1 CsvParser (org.simpleflatmapper.csv.CsvParser)1