/** * Creates a new weighted set with a given initial capacity. * * @param initialCapacity the initial capacity to use for the encapsulated Map */ public WeightedSet(DataType type, int initialCapacity) { super((WeightedSetDataType) type); clearAndReserve(initialCapacity); }
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); } }