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));
}
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());
}
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());
}
Aggregations