@Override public void typeCheck(AttributeValue value, Method setter) { if ( value.getL() == null ) { throw new DynamoDBMappingException("Expected L in value " + value + " when invoking " + setter); } }
@Override public Object unmarshall(AttributeValue value) throws ParseException { List<AttributeValue> values = value.getL(); List<Object> objects = new ArrayList<Object>(values.size()); for (AttributeValue v : values) { memberUnmarshaller.typeCheck(v, null); objects.add(memberUnmarshaller.unmarshall(v)); } return objects; } }
@Override public Object unmarshall(AttributeValue value) throws ParseException { List<AttributeValue> values = value.getL(); // As in the LinkedHashSet(Collection) constructor. int size = Math.max(values.size() * 2, 11); Set<Object> objects = new LinkedHashSet<Object>(size); for (AttributeValue v : values) { memberUnmarshaller.typeCheck(v, null); Object o = memberUnmarshaller.unmarshall(v); if (!objects.add(o)) { throw new DynamoDBMappingException( "Duplicate value (" + o + ") found in " + values); } } return objects; } }
@Override public void typeCheck(AttributeValue value, Method setter) { if (value.getNS() == null && value.getL() == null) { throw new DynamoDBMappingException( "Expected either L or NS in value " + value + " when invoking " + setter); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getS() == null) ? 0 : getS().hashCode()); hashCode = prime * hashCode + ((getN() == null) ? 0 : getN().hashCode()); hashCode = prime * hashCode + ((getB() == null) ? 0 : getB().hashCode()); hashCode = prime * hashCode + ((getSS() == null) ? 0 : getSS().hashCode()); hashCode = prime * hashCode + ((getNS() == null) ? 0 : getNS().hashCode()); hashCode = prime * hashCode + ((getBS() == null) ? 0 : getBS().hashCode()); hashCode = prime * hashCode + ((getM() == null) ? 0 : getM().hashCode()); hashCode = prime * hashCode + ((getL() == null) ? 0 : getL().hashCode()); hashCode = prime * hashCode + ((getNULL() == null) ? 0 : getNULL().hashCode()); hashCode = prime * hashCode + ((getBOOL() == null) ? 0 : getBOOL().hashCode()); return hashCode; }
.withSS(entry.getValue().getSS()) .withM(entry.getValue().getM()) .withL(entry.getValue().getL()) .withNULL(entry.getValue().getNULL()) .withBOOL(entry.getValue().getBOOL());
/** * Marshall the given parameter object. */ public void marshall(AttributeValue attributeValue, ProtocolMarshaller protocolMarshaller) { if (attributeValue == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(attributeValue.getS(), S_BINDING); protocolMarshaller.marshall(attributeValue.getN(), N_BINDING); protocolMarshaller.marshall(attributeValue.getB(), B_BINDING); protocolMarshaller.marshall(attributeValue.getSS(), SS_BINDING); protocolMarshaller.marshall(attributeValue.getNS(), NS_BINDING); protocolMarshaller.marshall(attributeValue.getBS(), BS_BINDING); protocolMarshaller.marshall(attributeValue.getM(), M_BINDING); protocolMarshaller.marshall(attributeValue.getL(), L_BINDING); protocolMarshaller.marshall(attributeValue.getNULL(), NULL_BINDING); protocolMarshaller.marshall(attributeValue.getBOOL(), BOOL_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
@Override public void typeCheck(AttributeValue value, Method setter) { if (value.getL() == null) { throw new DynamoDBMappingException("Expected L in value " + value + " when invoking " + setter); } }
@Override public Object unmarshall(AttributeValue value) throws ParseException { final List<AttributeValue> values = value.getL(); final List<Object> objects = new ArrayList<Object>(values.size()); for (final AttributeValue v : values) { memberUnmarshaller.typeCheck(v, null); objects.add(memberUnmarshaller.unmarshall(v)); } return objects; } }
private static DynamoDBList toDynamoDBList(final AttributeValue attributeValue) { DynamoDBList list = null; if (attributeValue.getL() != null) { list = new DynamoDBList(); final List<AttributeValue> listAttributes = attributeValue.getL(); for (final AttributeValue av : listAttributes) { final DynamoDBEntry entry = attributeValueToDynamoDBEntry(av); list.add(entry); } } return list; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getS() == null) ? 0 : getS().hashCode()); hashCode = prime * hashCode + ((getN() == null) ? 0 : getN().hashCode()); hashCode = prime * hashCode + ((getB() == null) ? 0 : getB().hashCode()); hashCode = prime * hashCode + ((getSS() == null) ? 0 : getSS().hashCode()); hashCode = prime * hashCode + ((getNS() == null) ? 0 : getNS().hashCode()); hashCode = prime * hashCode + ((getBS() == null) ? 0 : getBS().hashCode()); hashCode = prime * hashCode + ((getM() == null) ? 0 : getM().hashCode()); hashCode = prime * hashCode + ((getL() == null) ? 0 : getL().hashCode()); hashCode = prime * hashCode + ((getNULL() == null) ? 0 : getNULL().hashCode()); hashCode = prime * hashCode + ((getBOOL() == null) ? 0 : getBOOL().hashCode()); return hashCode; }
private FieldType getType(AttributeValue value) { if (value.isBOOL()) { return FieldType.BOOLEAN; } else if (value.getS() != null) { return STRING; } else if (value.getN() != null) { return FieldType.DOUBLE; } else if (value.getL() != null) { return FieldType.ARRAY_STRING; } else if (value.getM() != null) { return FieldType.MAP_STRING; } else { if (!value.isNULL()) { throw new IllegalStateException(); } else { return STRING; } } }
@Test public void testSetList() { assertEquals( Arrays.asList(new AttributeValue().withSS("a")), convert("getSetList", Arrays.asList( Collections.<String> singleton("a"))).getL()); final List<Set<String>> list = new ArrayList<Set<String>>(); list.add(null); assertEquals( Arrays.asList(new AttributeValue().withNULL(true)), convert("getSetList", list).getL()); }
@Test public void testList() { assertEquals(Arrays.asList( new AttributeValue("a"), new AttributeValue("b"), new AttributeValue("c")), convert("getList", Arrays.asList("a", "b", "c")).getL()); assertEquals(Arrays.asList(new AttributeValue().withNULL(true)), convert("getList", Collections.<String> singletonList(null)).getL()); }
@Test public void testList() { assertEquals(Arrays.asList( new AttributeValue("a"), new AttributeValue("b"), new AttributeValue("c")), convert("getList", Arrays.asList("a", "b", "c")).getL()); assertEquals(Arrays.asList(new AttributeValue().withNULL(true)), convert("getList", Collections.<String> singletonList(null)).getL()); }
@Test public void testSetList() { assertEquals(Arrays.asList( new AttributeValue().withSS("a"), new AttributeValue().withSS("b"), new AttributeValue().withSS("c")), convert("getSetList", Arrays.asList( Collections.singleton("a"), Collections.singleton("b"), Collections.singleton("c"))).getL()); }