/** * Verifies that a ColumnValue has only a scalar or array value, not both and not neither. * * @param column The protobuf ColumnValue object * @throws IllegalArgumentException When the above condition is not met */ static void validateColumnValue(Common.ColumnValue column) { final boolean hasScalar = column.hasField(SCALAR_VALUE_DESCRIPTOR); final boolean hasArrayValue = column.getHasArrayValue(); // These should always be different if (hasScalar == hasArrayValue) { throw new IllegalArgumentException("A column must have a scalar or array value, not " + (hasScalar ? "both" : "neither")); } }
/** * Verifies that a ColumnValue has only a scalar or array value, not both and not neither. * * @param column The protobuf ColumnValue object * @throws IllegalArgumentException When the above condition is not met */ static void validateColumnValue(Common.ColumnValue column) { final boolean hasScalar = column.hasField(SCALAR_VALUE_DESCRIPTOR); final boolean hasArrayValue = column.getHasArrayValue(); // These should always be different if (hasScalar == hasArrayValue) { throw new IllegalArgumentException("A column must have a scalar or array value, not " + (hasScalar ? "both" : "neither")); } }
/** * Parses the value for a ColumnValue using the separated array and scalar attributes. * * @param column The protobuf ColumnValue object * @return The parse value for this column */ static Object parseColumn(Common.ColumnValue column) { // Verify that we have one or the other (scalar or array) validateColumnValue(column); if (!column.hasField(SCALAR_VALUE_DESCRIPTOR)) { // The column in this row is an Array (has multiple values) List<Object> array = new ArrayList<>(column.getArrayValueCount()); for (Common.TypedValue arrayValue : column.getArrayValueList()) { // Duplicative because of the ColumnValue/TypedValue difference. if (Common.Rep.ARRAY == arrayValue.getType()) { // Each element in this Array is an Array. array.add(parseArray(arrayValue)); } else { // The array element is a scalar. array.add(deserializeScalarValue(arrayValue)); } } return array; } else { // Scalar return deserializeScalarValue(column.getScalarValue()); } }
Common.ColumnValue column = iter.next(); assertTrue("The Column should have contained a scalar: " + column, column.hasField(ColumnValue.getDescriptor() .findFieldByNumber(ColumnValue.SCALAR_VALUE_FIELD_NUMBER))); column = iter.next(); assertTrue("The Column should have contained a scalar: " + column, column.hasField(ColumnValue.getDescriptor() .findFieldByNumber(ColumnValue.SCALAR_VALUE_FIELD_NUMBER))); value = column.getScalarValue();
Common.ColumnValue column = iter.next(); assertTrue("The Column should have contained a scalar: " + column, column.hasField(ColumnValue.getDescriptor() .findFieldByNumber(ColumnValue.SCALAR_VALUE_FIELD_NUMBER))); column = iter.next(); assertTrue("The Column should have contained a scalar: " + column, column.hasField(ColumnValue.getDescriptor() .findFieldByNumber(ColumnValue.SCALAR_VALUE_FIELD_NUMBER))); value = column.getScalarValue();
/** * Parses the value for a ColumnValue using the separated array and scalar attributes. * * @param column The protobuf ColumnValue object * @return The parse value for this column */ static Object parseColumn(Common.ColumnValue column) { // Verify that we have one or the other (scalar or array) validateColumnValue(column); if (!column.hasField(SCALAR_VALUE_DESCRIPTOR)) { // The column in this row is an Array (has multiple values) List<Object> array = new ArrayList<>(column.getArrayValueCount()); for (Common.TypedValue arrayValue : column.getArrayValueList()) { // Duplicative because of the ColumnValue/TypedValue difference. if (Common.Rep.ARRAY == arrayValue.getType()) { // Each element in this Array is an Array. array.add(parseArray(arrayValue)); } else { // The array element is a scalar. array.add(deserializeScalarValue(arrayValue)); } } return array; } else { // Scalar return deserializeScalarValue(column.getScalarValue()); } }
/** * Determines whether this message contains the new attributes in the * message. We can't directly test for the negative because our * {@code hasField} trick does not work on repeated fields. * * @param column The protobuf column object * @return True if the message is the new style, false otherwise. */ static boolean isNewStyleColumn(Common.ColumnValue column) { return column.hasField(HAS_ARRAY_VALUE_DESCRIPTOR) || column.hasField(SCALAR_VALUE_DESCRIPTOR); }
/** * Determines whether this message contains the new attributes in the * message. We can't directly test for the negative because our * {@code hasField} trick does not work on repeated fields. * * @param column The protobuf column object * @return True if the message is the new style, false otherwise. */ static boolean isNewStyleColumn(Common.ColumnValue column) { return column.hasField(HAS_ARRAY_VALUE_DESCRIPTOR) || column.hasField(SCALAR_VALUE_DESCRIPTOR); }