/** * Create a tuple builder that will place the supplied value in the slot referenced by this key. * @param value The value to add to the tuple. * @return The tuple builder. */ public TupleKeyValue of(T value) { if (value == null) throw new IllegalArgumentException("value must not be null"); return new TupleKeyValue(this, value); }
/** * Build a tuple using the supplied key/value pairs, first validating that the keys belong to this schema and are complete. * @param keyValues The TupleKeyValues to use to create the Tuple. * @return The created Tuple. */ public Tuple make(TupleKeyValue...keyValues) { if (keyValues == null) throw new IllegalArgumentException("keyValues must not be null"); if (!Stream.of(keyValues).allMatch(kv -> kv.belongsToSchema(this))) { throw new IllegalArgumentException(String.format( "Keys %s do not all belong to schema %s", getKeyNames(keyValues), this)); } if (Stream.of(keyValues).map(TupleKeyValue::getTupleKey).distinct().count() != slots.length) { throw new IllegalArgumentException(String.format( "Not all slots in %s filled by provided keys %s", this, getKeyNames(keyValues))); } Object[] values = new Object[slots.length]; Stream.of(keyValues).forEach(kv -> kv.build(values)); return new Tuple(this, values); }