/** * Creates a new value update specifying an addition of a value to an array or a key to a weighted set (with default weight 1). * * @param value the value to add to the array, or key to add to the weighted set * @return a ValueUpdate specifying the addition * @throws IllegalArgumentException if the runtime type of newValue does not match the type required * @throws UnsupportedOperationException if the field type is not array or weighted set */ public static ValueUpdate createAdd(FieldValue value) { return new AddValueUpdate(value); }
@Override public void write(AddValueUpdate update, DataType superType) { update.getValue().serialize(this); }
AddValueUpdate(FieldValue value) { super(ValueUpdateClassID.ADD); setValue(value, 1); }
} else if (upd instanceof AddValueUpdate) { if (val instanceof Array) { lst.addAll(createAddValueUpdateForArray((Array)val, ((AddValueUpdate)upd).getWeight())); } else if (val instanceof WeightedSet) { lst.addAll(createAddValueUpdateForWset((WeightedSet)val));
((Array)val).add(upd.getValue()); } else if (val instanceof WeightedSet) { ((WeightedSet)val).put(upd.getValue(), ((AddValueUpdate)upd).getWeight());
/** * Creates a new value update specifying an addition of a key (with a specified weight) to a weighted set. If this * method is used on an array data type, the weight will be omitted. * * @param key the key to add * @param weight the weight to associate with the given key * @return a ValueUpdate specifying the addition * @throws IllegalArgumentException if the runtime type of key does not match the type required * @throws UnsupportedOperationException if the field type is not array or weighted set */ public static ValueUpdate createAdd(FieldValue key, Integer weight) { return new AddValueUpdate(key, weight); }
public AddValueUpdate(FieldValue key, int weight) { super(ValueUpdateClassID.ADD); setValue(key, weight); }
@SuppressWarnings({ "unchecked" }) private List<ValueUpdate> createAddValueUpdateForArray(Array arr, int weight) { List<ValueUpdate> ret = new ArrayList<>(arr.size()); for (Iterator<FieldValue> it = arr.fieldValueIterator(); it.hasNext(); ) { ret.add(new AddValueUpdate(it.next(), weight)); } return ret; }
@SuppressWarnings({ "unchecked" }) private List<ValueUpdate> createAddValueUpdateForWset(WeightedSet wset) { List<ValueUpdate> ret = new ArrayList<>(wset.size()); for (Iterator<FieldValue> it = wset.fieldValueIterator(); it.hasNext(); ) { FieldValue key = it.next(); ret.add(new AddValueUpdate(key, wset.get(key))); } return ret; }
fval.deserialize(this); int weight = getInt(null); return new AddValueUpdate(fval, weight);
fval.deserialize(this); int weight = getInt(null); return new AddValueUpdate(fval, weight);