@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; }
/** * Creates a new value update * specifying an addition of all key/weight pairs in a weighted set to a weighted set. If this method * is used on an array data type, the weights will be omitted. Note that this method is just a convenience method, * it simply iterates through the set and creates value updates by calling createAdd() for each element. * * @param set a WeightedSet containing the key/weight pairs to add * @return a ValueUpdate specifying the addition * @throws IllegalArgumentException if the runtime type of values does not match the type required * @throws UnsupportedOperationException if the field type is not weighted set or array * @see ValueUpdate#createAdd(FieldValue, Integer) */ public static List<ValueUpdate> createAddAll(WeightedSet<? extends FieldValue> set) { List<ValueUpdate> vupds = new ArrayList<>(); Iterator<? extends FieldValue> it = set.fieldValueIterator(); while (it.hasNext()) { FieldValue key = it.next(); vupds.add(ValueUpdate.createAdd(key, set.get(key))); } return vupds; }
@SuppressWarnings({ "unchecked" }) private List<ValueUpdate> createMapValueUpdatesForWset(WeightedSet wset, MapValueUpdate upd) { List<ValueUpdate> ret = new ArrayList<>(); for (Iterator<FieldValue> it = wset.fieldValueIterator(); it.hasNext();) { FieldValue childVal = it.next(); for (ValueUpdate childUpd : createValueUpdates(new IntegerFieldValue(wset.get(childVal)), upd.getUpdate())) { ret.add(new MapValueUpdate(childVal, childUpd)); } } return ret; } }
public static void printWeightedSetXml(WeightedSet ws, XmlStream xml) { Iterator<FieldValue> it = ws.fieldValueIterator(); while (it.hasNext()) { FieldValue val = it.next(); xml.beginTag("item"); xml.addAttribute("weight", ws.get(val)); val.printXml(xml); xml.endTag(); } }
lst.addAll(createRemoveValueUpdateForEachElement(((Array)val).fieldValueIterator())); } else if (val instanceof WeightedSet) { lst.addAll(createRemoveValueUpdateForEachElement(((WeightedSet)val).fieldValueIterator())); } else {
@SuppressWarnings({ "unchecked", "rawtypes" }) private FieldValue convertWset(WeightedSet val) { Map<FieldValue, Integer> next = new LinkedHashMap<FieldValue, Integer>(); DataType nextType = null; for (Iterator<FieldValue> it = val.fieldValueIterator(); it.hasNext();) { FieldValue prevKey = it.next(); Integer prevVal = val.get(prevKey); FieldValue nextKey = convert(prevKey); if (nextKey == null) { continue; } if (nextType == null) { nextType = nextKey.getDataType(); } else if (!nextType.isValueCompatible(nextKey)) { throw new IllegalArgumentException("Expected " + nextType.getName() + ", got " + nextKey.getDataType().getName() + "."); } next.put(nextKey, prevVal); } if (nextType == null) { return null; } WeightedSet ret = DataType.getWeightedSet(nextType, val.getDataType().createIfNonExistent(), val.getDataType().removeIfZero()).createFieldValue(); for (Map.Entry<FieldValue, Integer> entry : next.entrySet()) { ret.put(entry.getKey(), entry.getValue()); } return ret; }
if (value instanceof WeightedSet) { WeightedSet wset = (WeightedSet)value; for (Iterator<FieldValue> it = wset.fieldValueIterator(); it.hasNext();) { FieldValue wsetEntry = it.next(); List<FieldPathEntry> nextPath = new ArrayList<>(path);
/** * Write out the value of weighted set field * * @param field - field description (name and data type) * @param ws - field value */ public <T extends FieldValue> void write(FieldBase field, WeightedSet<T> ws) { WeightedSetDataType type = ws.getDataType(); putInt(null, type.getNestedType().getId()); putInt(null, ws.size()); Iterator<T> it = ws.fieldValueIterator(); while (it.hasNext()) { FieldValue key = it.next(); java.lang.Integer value = ws.get(key); int sizePos = buf.position(); putInt(null, 0); int startPos = buf.position(); key.serialize(this); putInt(null, value); int finalPos = buf.position(); int size = finalPos - startPos; buf.position(sizePos); putInt(null, size); buf.position(finalPos); } }
/** * Write out the value of weighted set field * * @param field - field description (name and data type) * @param ws - field value */ public <T extends FieldValue> void write(FieldBase field, WeightedSet<T> ws) { WeightedSetDataType type = ws.getDataType(); putInt(null, type.getNestedType().getId()); putInt(null, ws.size()); Iterator<T> it = ws.fieldValueIterator(); while (it.hasNext()) { FieldValue key = it.next(); java.lang.Integer value = ws.get(key); int sizePos = buf.position(); putInt(null, 0); int startPos = buf.position(); key.serialize(this); putInt(null, value); int finalPos = buf.position(); int size = finalPos - startPos; buf.position(sizePos); putInt(null, size); buf.position(finalPos); } }