Java Code Examples for mil.nga.geopackage.user.custom.UserCustomColumn#getMax()

The following examples show how to use mil.nga.geopackage.user.custom.UserCustomColumn#getMax() . 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: RelatedTablesUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Populate the user row additional column values
 *
 * @param userTable   user custom table
 * @param userRow     user custom row
 * @param skipColumns columns to skip populating
 */
public static void populateUserRow(UserCustomTable userTable,
                                   UserCustomRow userRow, List<String> skipColumns) {

    Set<String> skipColumnsSet = new HashSet<>(skipColumns);

    for (UserCustomColumn column : userTable.getColumns()) {
        if (!skipColumnsSet.contains(column.getName())) {

            // Leave nullable columns null 20% of the time
            if (!column.isNotNull()
                    && DublinCoreType.fromName(column.getName()) == null) {
                if (Math.random() < 0.2) {
                    continue;
                }
            }

            Object value = null;

            switch (column.getDataType()) {

                case TEXT:
                    String text = UUID.randomUUID().toString();
                    if (column.getMax() != null
                            && text.length() > column.getMax()) {
                        text = text.substring(0, column.getMax().intValue());
                    }
                    value = text;
                    break;
                case REAL:
                case DOUBLE:
                    value = Math.random() * 5000.0;
                    break;
                case BOOLEAN:
                    value = Math.random() < .5 ? false : true;
                    break;
                case INTEGER:
                case INT:
                    value = (int) (Math.random() * 500);
                    break;
                case BLOB:
                    byte[] blob = UUID.randomUUID().toString().getBytes();
                    if (column.getMax() != null
                            && blob.length > column.getMax()) {
                        byte[] blobLimited = new byte[column.getMax()
                                .intValue()];
                        ByteBuffer.wrap(blob, 0, column.getMax().intValue())
                                .get(blobLimited);
                        blob = blobLimited;
                    }
                    value = blob;
                    break;
                case DATE:
                case DATETIME:
                    DateConverter converter = DateConverter.converter(column
                            .getDataType());
                    Date date = new Date();
                    if (Math.random() < .5) {
                        value = date;
                    } else {
                        value = converter.stringValue(date);
                    }
                    break;
                default:
                    throw new UnsupportedOperationException(
                            "Not implemented for data type: "
                                    + column.getDataType());
            }

            userRow.setValue(column.getName(), value);

        }
    }
}
 
Example 2
Source File: RelatedTablesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Populate the user row additional column values
 * 
 * @param userTable
 *            user custom table
 * @param userRow
 *            user custom row
 * @param skipColumns
 *            columns to skip populating
 */
public static void populateUserRow(UserCustomTable userTable,
		UserCustomRow userRow, List<String> skipColumns) {

	Set<String> skipColumnsSet = new HashSet<>(skipColumns);

	for (UserCustomColumn column : userTable.getColumns()) {
		if (!skipColumnsSet.contains(column.getName())) {

			// Leave nullable columns null 20% of the time
			if (!column.isNotNull()
					&& DublinCoreType.fromName(column.getName()) == null) {
				if (Math.random() < 0.2) {
					continue;
				}
			}

			Object value = null;

			switch (column.getDataType()) {

			case TEXT:
				String text = UUID.randomUUID().toString();
				if (column.getMax() != null
						&& text.length() > column.getMax()) {
					text = text.substring(0, column.getMax().intValue());
				}
				value = text;
				break;
			case REAL:
			case DOUBLE:
				value = Math.random() * 5000.0;
				break;
			case BOOLEAN:
				value = Math.random() < .5 ? false : true;
				break;
			case INTEGER:
			case INT:
				value = (int) (Math.random() * 500);
				break;
			case BLOB:
				byte[] blob = UUID.randomUUID().toString().getBytes();
				if (column.getMax() != null
						&& blob.length > column.getMax()) {
					byte[] blobLimited = new byte[column.getMax()
							.intValue()];
					ByteBuffer.wrap(blob, 0, column.getMax().intValue())
							.get(blobLimited);
					blob = blobLimited;
				}
				value = blob;
				break;
			case DATE:
			case DATETIME:
				DateConverter converter = DateConverter.converter(column
						.getDataType());
				Date date = new Date();
				if (Math.random() < .5) {
					value = date;
				} else {
					value = converter.stringValue(date);
				}
				break;
			default:
				throw new UnsupportedOperationException(
						"Not implemented for data type: "
								+ column.getDataType());
			}

			userRow.setValue(column.getName(), value);

		}
	}
}