/** * Add a key with an associated weight to this set. If the key is already present in this set, the previous * association is replaced. Checks to validate that all keys are of the same type. * * @param key the key to add * @param weight the weight to associate with this key * @return the weight that was previously associated with this key, or null (if there was no previous key) */ public Integer put(K key, Integer weight) { verifyElementCompatibility(key); IntegerFieldValue ifv = putUnChecked(key, new IntegerFieldValue(weight)); return ifv != null ? ifv.getInteger() : null; }
public <T extends FieldValue> void read(FieldBase field, WeightedSet<T> ws) { WeightedSetDataType type = ws.getDataType(); getInt(null); // Have no need for type int numElements = getInt(null); if (numElements < 0) { throw new DeserializationException("Bad number of weighted set elements, " + numElements); } ws.clearAndReserve(numElements * 2); // Avoid resizing for (int i = 0; i < numElements; i++) { int size = getInt(null); FieldValue value = type.getNestedType().createFieldValue(); value.deserialize(null, this); IntegerFieldValue weight = new IntegerFieldValue(getInt(null)); ws.putUnChecked((T) value, weight); } }
public <T extends FieldValue> void read(FieldBase field, WeightedSet<T> ws) { WeightedSetDataType type = ws.getDataType(); getInt(null); // Have no need for type int numElements = getInt(null); if (numElements < 0) { throw new DeserializationException("Bad number of weighted set elements, " + numElements); } ws.clearAndReserve(numElements * 2); // Avoid resizing for (int i = 0; i < numElements; i++) { int size = getInt(null); FieldValue value = type.getNestedType().createFieldValue(); value.deserialize(null, this); IntegerFieldValue weight = new IntegerFieldValue(getInt(null)); ws.putUnChecked((T) value, weight); } }