use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.
the class TestTupleBuilder method testYellowTaxiRangeTupleBuilder.
/**
* Test the yellow taxi range tuple builder
* @throws ParseException
*/
@Test
public void testYellowTaxiRangeTupleBuilder() throws ParseException {
final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.YELLOWTAXI_RANGE);
final Tuple tuple = tupleBuilder.buildTuple("1", TAXI_TEST_LINE);
Assert.assertTrue(tuple != null);
Assert.assertEquals(Integer.toString(1), tuple.getKey());
final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
final Date dateLow = dateParser.parse("2016-01-01 00:00:00");
final Date dateHigh = dateParser.parse("2016-01-01 00:00:00");
final BoundingBox exptectedBox = new BoundingBox(-73.990371704101563, -73.981842041015625, 40.732406616210937, 40.734695434570313, (double) dateLow.getTime(), (double) dateHigh.getTime());
Assert.assertEquals(exptectedBox, tuple.getBoundingBox());
}
use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.
the class TestTupleBuilder method testTupleFile2.
/**
* Test the tuple file builder
* @throws IOException
*/
@Test
public void testTupleFile2() throws IOException {
final File tempFile = File.createTempFile("temp", ".txt");
tempFile.deleteOnExit();
// The reference tuple
final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.GEOJSON);
final Tuple tuple = tupleBuilder.buildTuple("1", GEO_JSON_LINE);
final BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
writer.write(GEO_JSON_LINE);
writer.write("\n");
writer.close();
final TupleFileReader tupleFile = new TupleFileReader(tempFile.getAbsolutePath(), TupleBuilderFactory.Name.GEOJSON);
final AtomicInteger seenTuples = new AtomicInteger(0);
tupleFile.addTupleListener(t -> {
Assert.assertEquals(tuple.getKey(), t.getKey());
Assert.assertEquals(tuple.getBoundingBox(), t.getBoundingBox());
Assert.assertArrayEquals(tuple.getDataBytes(), t.getDataBytes());
seenTuples.incrementAndGet();
});
tupleFile.processFile();
Assert.assertEquals(1, seenTuples.get());
}
use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.
the class TestTupleBuilder method testYellowTaxiPointTupleBuilder.
/**
* Test the yellow taxi range tuple builder
* @throws ParseException
*/
@Test
public void testYellowTaxiPointTupleBuilder() throws ParseException {
final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.YELLOWTAXI_POINT);
final Tuple tuple = tupleBuilder.buildTuple("1", TAXI_TEST_LINE);
Assert.assertTrue(tuple != null);
Assert.assertEquals(Integer.toString(1), tuple.getKey());
final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
final Date dateLow = dateParser.parse("2016-01-01 00:00:00");
final BoundingBox exptectedBox = new BoundingBox(-73.990371704101563, -73.990371704101563, 40.734695434570313, 40.734695434570313, (double) dateLow.getTime(), (double) dateLow.getTime());
Assert.assertEquals(exptectedBox, tuple.getBoundingBox());
}
use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.
the class TestTupleBuilder method testTPCHLineitemPointTupleBuilder.
/**
* Test the tpch point tuple builder
* @throws ParseException
*/
@Test
public void testTPCHLineitemPointTupleBuilder() throws ParseException {
final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.TPCH_LINEITEM_POINT);
final Tuple tuple = tupleBuilder.buildTuple("1", TPCH_LINEITEM_TEST_LINE);
Assert.assertTrue(tuple != null);
Assert.assertEquals(Integer.toString(1), tuple.getKey());
final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-mm-dd");
final Date date = dateParser.parse("1993-12-04");
final double doubleTime = (double) date.getTime();
final BoundingBox exptectedBox = new BoundingBox(doubleTime, doubleTime);
Assert.assertEquals(exptectedBox, tuple.getBoundingBox());
}
use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.
the class TestTupleBuilder method testTupleFile4.
/**
* Test the tuple file builder - Read 5 of 3 lines
* @throws IOException
*/
@Test
public void testTupleFile4() throws IOException {
final File tempFile = File.createTempFile("temp", ".txt");
tempFile.deleteOnExit();
// The reference tuple
final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.GEOJSON);
final Tuple tuple = tupleBuilder.buildTuple("1", GEO_JSON_LINE);
final BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
writer.write(GEO_JSON_LINE);
writer.write("\n");
writer.write(GEO_JSON_LINE);
writer.write("\n");
writer.write(GEO_JSON_LINE);
writer.write("\n");
writer.close();
final TupleFileReader tupleFile = new TupleFileReader(tempFile.getAbsolutePath(), TupleBuilderFactory.Name.GEOJSON);
final AtomicInteger seenTuples = new AtomicInteger(0);
tupleFile.addTupleListener(t -> {
Assert.assertEquals(tuple.getBoundingBox(), t.getBoundingBox());
Assert.assertArrayEquals(tuple.getDataBytes(), t.getDataBytes());
seenTuples.incrementAndGet();
});
tupleFile.processFile(3);
Assert.assertEquals(3, seenTuples.get());
}
Aggregations