@SuppressWarnings({ "unchecked" }) @Override public ModificationStatus doModify(FieldValue fv) { for (Object newValue : newValues.getValues()) { ((CollectionFieldValue)fv).add((FieldValue) newValue); } return ModificationStatus.MODIFIED; }
@Override public FieldValue applyTo(FieldValue val) { if (val instanceof WeightedSet) { WeightedSet wset = (WeightedSet) val; wset.put(value, weight); } else if (val instanceof CollectionFieldValue) { CollectionFieldValue fval = (CollectionFieldValue) val; fval.add(value); } else { throw new IllegalStateException("Cannot add "+value+" to field of type " + val.getClass().getName()); } return val; }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void fillArray(TokenBuffer buffer, CollectionFieldValue parent, DataType valueType) { int initNesting = buffer.nesting(); expectArrayStart(buffer.currentToken()); buffer.next(); while (buffer.nesting() >= initNesting) { Preconditions.checkArgument(buffer.currentToken() != JsonToken.VALUE_NULL, "Illegal null value for array entry"); parent.add(readSingleValue(buffer, valueType)); buffer.next(); } } }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static ValueUpdate createMapUpdate(TokenBuffer buffer, DataType currentLevel, FieldValue keyParent, FieldValue topLevelKey) { TokenBuffer.Token element = buffer.prefetchScalar(UPDATE_ELEMENT); if (UPDATE_ELEMENT.equals(buffer.currentName())) { buffer.next(); } FieldValue key = keyTypeForMapUpdate(element, currentLevel); if (keyParent != null) { ((CollectionFieldValue) keyParent).add(key); } // structure is: [(match + element)*, (element + action)] // match will always have element, and either match or action if (!UPDATE_MATCH.equals(buffer.currentName())) { // we have reached an action... if (topLevelKey == null) { return ValueUpdate.createMap(key, readSingleUpdate(buffer, valueTypeForMapUpdate(currentLevel), buffer.currentName())); } else { return ValueUpdate.createMap(topLevelKey, readSingleUpdate(buffer, valueTypeForMapUpdate(currentLevel), buffer.currentName())); } } else { // next level of matching if (topLevelKey == null) { return createMapUpdate(buffer, valueTypeForMapUpdate(currentLevel), key, key); } else { return createMapUpdate(buffer, valueTypeForMapUpdate(currentLevel), key, topLevelKey); } } }