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

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.AttributeValue#l() . 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: 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");
  }
}
 
Example 2
Source File: AttributeValueMarshallerTest.java    From aws-dynamodb-encryption-java with Apache License 2.0 5 votes vote down vote up
private void assertAttributesAreEqual(AttributeValue o1, AttributeValue o2) {
    assertEquals(o1.b(), o2.b());
    assertSetsEqual(o1.bs(), o2.bs());
    assertEquals(o1.n(), o2.n());
    assertSetsEqual(o1.ns(), o2.ns());
    assertEquals(o1.s(), o2.s());
    assertSetsEqual(o1.ss(), o2.ss());
    assertEquals(o1.bool(), o2.bool());
    assertEquals(o1.nul(), o2.nul());

    if (o1.l() != null) {
        assertNotNull(o2.l());
        final List<AttributeValue> l1 = o1.l();
        final List<AttributeValue> l2 = o2.l();
        assertEquals(l1.size(), l2.size());
        for (int x = 0; x < l1.size(); ++x) {
            assertAttributesAreEqual(l1.get(x), l2.get(x));
        }
    }

    if (o1.m() != null) {
        assertNotNull(o2.m());
        final Map<String, AttributeValue> m1 = o1.m();
        final Map<String, AttributeValue> m2 = o2.m();
        assertEquals(m1.size(), m2.size());
        for (Map.Entry<String, AttributeValue> entry : m1.entrySet()) {
            assertAttributesAreEqual(entry.getValue(), m2.get(entry.getKey()));
        }
    }
}
 
Example 3
Source File: AttrMatcher.java    From aws-dynamodb-encryption-java with Apache License 2.0 5 votes vote down vote up
public static boolean attrEquals(AttributeValue e, AttributeValue a) {
    if (!isEqual(e.b(), a.b()) ||
            !isEqual(e.bool(), a.bool()) ||
            !isSetEqual(e.bs(), a.bs()) ||
            !isEqual(e.n(), a.n()) ||
            !isSetEqual(e.ns(), a.ns()) ||
            !isEqual(e.nul(), a.nul()) ||
            !isEqual(e.s(), a.s()) ||
            !isSetEqual(e.ss(), a.ss())) {
        return false;
    }
    // Recursive types need special handling
    if (e.m() == null ^ a.m() == null) {
        return false;
    } else if (e.m() != null) {
        if (!e.m().keySet().equals(a.m().keySet())) {
            return false;
        }
        for (final String key : e.m().keySet()) {
            if (!attrEquals(e.m().get(key), a.m().get(key))) {
                return false;
            }
        }
    }
    if (e.l() == null ^ a.l() == null) {
        return false;
    } else if (e.l() != null) {
        if (e.l().size() != a.l().size()) {
            return false;
        }
        for (int x = 0; x < e.l().size(); x++) {
            if (!attrEquals(e.l().get(x), a.l().get(x))) {
                return false;
            }
        }
    }
    return true;
}