Java Code Examples for mil.nga.geopackage.attributes.AttributesRow#columnCount()

The following examples show how to use mil.nga.geopackage.attributes.AttributesRow#columnCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttributesUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate an attributes row
 *
 * @param columns
 * @param attributesRow
 */
private static void validateAttributesRow(String[] columns,
                                          AttributesRow attributesRow) {
    TestCase.assertEquals(columns.length, attributesRow.columnCount());

    for (int i = 0; i < attributesRow.columnCount(); i++) {
        AttributesColumn column = attributesRow.getTable().getColumns()
                .get(i);
        GeoPackageDataType dataType = column.getDataType();
        TestCase.assertEquals(i, column.getIndex());
        TestCase.assertEquals(columns[i], attributesRow.getColumnName(i));
        TestCase.assertEquals(i, attributesRow.getColumnIndex(columns[i]));
        int rowType = attributesRow.getRowColumnType(i);
        Object value = attributesRow.getValue(i);

        switch (rowType) {

            case ResultUtils.FIELD_TYPE_INTEGER:
                TestUtils.validateIntegerValue(value, column.getDataType());
                break;

            case ResultUtils.FIELD_TYPE_FLOAT:
                TestUtils.validateFloatValue(value, column.getDataType());
                break;

            case ResultUtils.FIELD_TYPE_STRING:
                if (dataType == GeoPackageDataType.DATE || dataType == GeoPackageDataType.DATETIME) {
                    TestCase.assertTrue(value instanceof Date);
                    Date date = (Date) value;
                    DateConverter converter = DateConverter.converter(dataType);
                    String dateString = converter.stringValue(date);
                    TestCase.assertEquals(date.getTime(), converter.dateValue(dateString).getTime());
                } else {
                    TestCase.assertTrue(value instanceof String);
                }
                break;

            case ResultUtils.FIELD_TYPE_BLOB:
                TestCase.assertTrue(value instanceof byte[]);
                break;

            case ResultUtils.FIELD_TYPE_NULL:
                TestCase.assertNull(value);
                break;

        }
    }

    TestCase.assertTrue(attributesRow.getId() >= 0);
}
 
Example 2
Source File: AttributesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate an attributes row
 * 
 * @param columns
 * @param attributesRow
 */
private static void validateAttributesRow(String[] columns,
		AttributesRow attributesRow) {
	TestCase.assertEquals(columns.length, attributesRow.columnCount());

	for (int i = 0; i < attributesRow.columnCount(); i++) {
		AttributesColumn column = attributesRow.getTable().getColumns()
				.get(i);
		GeoPackageDataType dataType = column.getDataType();
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], attributesRow.getColumnName(i));
		TestCase.assertEquals(i, attributesRow.getColumnIndex(columns[i]));
		int rowType = attributesRow.getRowColumnType(i);
		Object value = attributesRow.getValue(i);

		switch (rowType) {

		case ResultUtils.FIELD_TYPE_INTEGER:
			TestUtils.validateIntegerValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_FLOAT:
			TestUtils.validateFloatValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_STRING:
			if (dataType == GeoPackageDataType.DATE
					|| dataType == GeoPackageDataType.DATETIME) {
				TestCase.assertTrue(value instanceof Date);
				Date date = (Date) value;
				DateConverter converter = DateConverter.converter(dataType);
				String dateString = converter.stringValue(date);
				TestCase.assertEquals(date.getTime(),
						converter.dateValue(dateString).getTime());
			} else {
				TestCase.assertTrue(value instanceof String);
			}
			break;

		case ResultUtils.FIELD_TYPE_BLOB:
			TestCase.assertTrue(value instanceof byte[]);
			break;

		case ResultUtils.FIELD_TYPE_NULL:
			TestCase.assertNull(value);
			break;

		}
	}

	TestCase.assertTrue(attributesRow.getId() >= 0);
}