Java Code Examples for software.amazon.awssdk.services.dynamodb.model.AttributeValue#bool()

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.AttributeValue#bool() . 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: BooleanAttributeConverter.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean transformTo(AttributeValue input) {
    if (input.bool() != null) {
        return EnhancedAttributeValue.fromBoolean(input.bool()).convert(VISITOR);
    }
    return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR);
}
 
Example 2
Source File: AtomicBooleanAttributeConverter.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public AtomicBoolean transformTo(AttributeValue input) {
    if (input.bool() != null) {
        return EnhancedAttributeValue.fromBoolean(input.bool()).convert(VISITOR);
    }

    return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR);
}
 
Example 3
Source File: EnhancedAttributeValue.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Create an {@link EnhancedAttributeValue} from a generated {@link AttributeValue}.
 *
 * <p>
 * This call will fail with a {@link RuntimeException} if the provided value is null ({@link AttributeValue#nul()} is okay).
 */
public static EnhancedAttributeValue fromAttributeValue(AttributeValue attributeValue) {
    Validate.notNull(attributeValue, "Generated attribute value must not contain null values. " +
                                     "Use AttributeValue#nul() instead.");
    if (attributeValue.s() != null) {
        return EnhancedAttributeValue.fromString(attributeValue.s());
    }
    if (attributeValue.n() != null) {
        return EnhancedAttributeValue.fromNumber(attributeValue.n());
    }
    if (attributeValue.bool() != null) {
        return EnhancedAttributeValue.fromBoolean(attributeValue.bool());
    }
    if (Boolean.TRUE.equals(attributeValue.nul())) {
        return EnhancedAttributeValue.nullValue();
    }
    if (attributeValue.b() != null) {
        return EnhancedAttributeValue.fromBytes(attributeValue.b());
    }
    if (attributeValue.hasM()) {
        return EnhancedAttributeValue.fromMap(attributeValue.m());
    }
    if (attributeValue.hasL()) {
        return EnhancedAttributeValue.fromListOfAttributeValues(attributeValue.l());
    }
    if (attributeValue.hasBs()) {
        return EnhancedAttributeValue.fromSetOfBytes(attributeValue.bs());
    }
    if (attributeValue.hasSs()) {
        return EnhancedAttributeValue.fromSetOfStrings(attributeValue.ss());
    }
    if (attributeValue.hasNs()) {
        return EnhancedAttributeValue.fromSetOfNumbers(attributeValue.ns());
    }

    throw new IllegalStateException("Unable to convert attribute value: " + attributeValue);
}
 
Example 4
Source File: AttributeValueCoder.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(AttributeValue value, OutputStream outStream) throws IOException {
  if (value.s() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.s.toString(), outStream);
    StringUtf8Coder.of().encode(value.s(), outStream);
  } else if (value.n() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.n.toString(), outStream);
    StringUtf8Coder.of().encode(value.n(), outStream);
  } else if (value.bool() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.bool.toString(), outStream);
    BooleanCoder.of().encode(value.bool(), outStream);
  } else if (value.b() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.b.toString(), outStream);
    ByteArrayCoder.of().encode(value.b().asByteArray(), outStream);
  } else if (value.ss() != null && value.ss().size() > 0) {
    StringUtf8Coder.of().encode(AttributeValueType.ss.toString(), outStream);
    LIST_STRING_CODER.encode(value.ss(), outStream);
  } else if (value.ns() != null && value.ns().size() > 0) {
    StringUtf8Coder.of().encode(AttributeValueType.ns.toString(), outStream);
    LIST_STRING_CODER.encode(value.ns(), outStream);
  } else if (value.bs() != null && value.bs().size() > 0) {
    StringUtf8Coder.of().encode(AttributeValueType.bs.toString(), outStream);
    LIST_BYTE_CODER.encode(convertToListByteArray(value.bs()), outStream);
  } else if (value.l() != null && value.l().size() > 0) {
    StringUtf8Coder.of().encode(AttributeValueType.l.toString(), outStream);
    LIST_ATTRIBUTE_CODER.encode(value.l(), outStream);
  } else if (value.m() != null && value.m().size() > 0) {
    StringUtf8Coder.of().encode(AttributeValueType.m.toString(), outStream);
    MAP_ATTRIBUTE_CODER.encode(value.m(), outStream);
  } else if (value.nul() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.nul.toString(), outStream);
    BooleanCoder.of().encode(value.nul(), outStream);
  } else {
    throw new CoderException("Unknown Type");
  }
}