private static void checkType( Type fieldType, com.google.protobuf.Value proto, KindCase expected) { if (proto.getKindCase() != expected) { throw newSpannerException( ErrorCode.INTERNAL, "Invalid value for column type " + fieldType + " expected " + expected + " but was " + proto.getKindCase()); } }
@Override public Boolean apply(com.google.protobuf.Value input) { return input.getKindCase() == KindCase.NULL_VALUE ? null : input.getBoolValue(); } });
@Override public String apply(com.google.protobuf.Value input) { return input.getKindCase() == KindCase.NULL_VALUE ? null : input.getStringValue(); } });
private static double valueProtoToFloat64(com.google.protobuf.Value proto) { if (proto.getKindCase() == KindCase.STRING_VALUE) { switch (proto.getStringValue()) { case "-Infinity": return Double.NEGATIVE_INFINITY; case "Infinity": return Double.POSITIVE_INFINITY; case "NaN": return Double.NaN; default: // Fall-through to handling below to produce an error. } } if (proto.getKindCase() != KindCase.NUMBER_VALUE) { throw newSpannerException( ErrorCode.INTERNAL, "Invalid value for column type " + Type.float64() + " expected NUMBER_VALUE or STRING_VALUE with value one of" + " \"Infinity\", \"-Infinity\", or \"NaN\" but was " + proto.getKindCase() + (proto.getKindCase() == KindCase.STRING_VALUE ? " with value \"" + proto.getStringValue() + "\"" : "")); } return proto.getNumberValue(); }
PrimitiveArray(ListValue protoList) { this.size = protoList.getValuesCount(); A data = newArray(size); BitSet nulls = new BitSet(size); for (int i = 0; i < protoList.getValuesCount(); ++i) { if (protoList.getValues(i).getKindCase() == KindCase.NULL_VALUE) { nulls.set(i); } else { setProto(data, i, protoList.getValues(i)); } } this.data = data; this.nulls = nulls; }
com.google.protobuf.Value last = a.get(a.size() - 1); com.google.protobuf.Value first = b.get(0); KindCase lastKind = last.getKindCase(); KindCase firstKind = first.getKindCase(); if (isMergeable(lastKind) && lastKind == firstKind) { com.google.protobuf.Value merged = null;
switch (any.getKindCase()) { case NULL_VALUE: return null;
private static Object valueToObject(Value value) { switch (value.getKindCase()) { case NULL_VALUE: return null; case NUMBER_VALUE: return value.getNumberValue(); case STRING_VALUE: return value.getStringValue(); case BOOL_VALUE: return value.getBoolValue(); case STRUCT_VALUE: return new StructMap(value.getStructValue()); case LIST_VALUE: return Lists.transform(value.getListValue().getValuesList(), VALUE_TO_OBJECT); default: throw new IllegalArgumentException(String.format("Unsupported protobuf value %s", value)); } }
for (com.google.protobuf.Value value : listValue.getValuesList()) { list.add( value.getKindCase() == KindCase.NULL_VALUE ? null : ByteArray.fromBase64(value.getStringValue())); for (com.google.protobuf.Value value : listValue.getValuesList()) { list.add( value.getKindCase() == KindCase.NULL_VALUE ? null : Timestamp.parseTimestamp(value.getStringValue())); for (com.google.protobuf.Value value : listValue.getValuesList()) { list.add( value.getKindCase() == KindCase.NULL_VALUE ? null : Date.parseDate(value.getStringValue())); if (value.getKindCase() == KindCase.NULL_VALUE) { list.add(null); } else {
result = result && getKindCase().equals( other.getKindCase()); if (!result) return false; switch (kindCase_) {
KindCase kind = value.getKindCase(); if (newValue.getKindCase() != kind) { throw newSpannerException( ErrorCode.INTERNAL, + kind + " but got: " + newValue.getKindCase());
private static Object decodeValue(Type fieldType, com.google.protobuf.Value proto) { if (proto.getKindCase() == KindCase.NULL_VALUE) { return null;
public Builder mergeFrom(com.google.protobuf.Value other) { if (other == com.google.protobuf.Value.getDefaultInstance()) return this; switch (other.getKindCase()) { case NULL_VALUE: { setNullValueValue(other.getNullValueValue());
public KindCase getKindCase() { return instance.getKindCase(); }
private static void checkType( Type fieldType, com.google.protobuf.Value proto, KindCase expected) { if (proto.getKindCase() != expected) { throw newSpannerException( ErrorCode.INTERNAL, "Invalid value for column type " + fieldType + " expected " + expected + " but was " + proto.getKindCase()); } }
@Override public String apply(com.google.protobuf.Value input) { return input.getKindCase() == KindCase.NULL_VALUE ? null : input.getStringValue(); } });
@Override public Boolean apply(com.google.protobuf.Value input) { return input.getKindCase() == KindCase.NULL_VALUE ? null : input.getBoolValue(); } });
private static Object parseObject(String key, Value in, VCFHeaderLineType type) { // Case on type switch (in.getKindCase()) { case NULL_VALUE: throw new IllegalStateException(String.format("field %s contained " + "a null value", key)); case NUMBER_VALUE: return getNumberValue(in.getNumberValue(), type); case STRING_VALUE: return in.getStringValue(); case BOOL_VALUE: return (Boolean) in.getBoolValue(); default: throw new IllegalStateException(String.format("field %s contained a %s type, which" + " is not supported by VariantToVcf", key, getKind(in.getKindCase()))); } }
@Test public void itReadsNullValue() throws IOException { String json = "{\"value\":null}"; HasValue valueWrapper = camelCase().readValue(json, HasValue.class); assertThat(valueWrapper.hasValue()).isTrue(); Value value = valueWrapper.getValue(); switch (value.getKindCase()) { case NULL_VALUE: assertThat(value.getNullValue()).isEqualTo(NullValue.NULL_VALUE); break; default: fail("Unexpected value kind: " + value.getKindCase()); } }
@Test public void itReadsStringValue() throws IOException { String json = "{\"value\":\"test\"}"; HasValue valueWrapper = camelCase().readValue(json, HasValue.class); assertThat(valueWrapper.hasValue()).isTrue(); Value value = valueWrapper.getValue(); switch (value.getKindCase()) { case STRING_VALUE: assertThat(value.getStringValue()).isEqualTo("test"); break; default: fail("Unexpected value kind: " + value.getKindCase()); } }