/** * Make a tuple of the supplied values, first validating that they conform to this schema. * @param values The values to put in the Tuple. * @return The created Tuple. */ public Tuple makeWith(Object...values) { return make(values); }
/** * Build a tuple using a map of tuple values constructed by the supplied builders. * @param builders The builders to use to build up a map of tuple values. * @return The created tuple. */ public Tuple make(NamedValue...builders) { Map<String, Object> values = new HashMap<>(); Stream.of(builders).forEach(builder -> builder.accept(values)); return make(values); }
private Tuple makeTupleFromArgs(Object[] args) { return tupleSchema.make(IntStream.range(0, tupleKeys.length) .mapToObj(getValueFrom(args)) .toArray(TupleKeyValue[]::new)); }
private Tuple makeTupleFromArgs(Object[] args) { return tupleSchema.make(IntStream.range(0, tupleKeys.length) .mapToObj(getValueFrom(args)) .toArray(TupleKeyValue[]::new)); }
/** * Create a tuple from a map of name/value pairs. * @param values The values to put in the tuple. * @return The created tuple. */ public Tuple make(Map<String, Object> values) { if (values == null) throw new IllegalArgumentException("values must not be null"); checkMatchingKeys(values); Object[] valueArray = new Object[slots.length]; getIndices().forEach(i -> valueArray[i] = values.get(slots[i].getName())); return make(valueArray); }
/** * Create a tuple using the supplied deserialiser, out of a map of serialised values. * @param deserialiser The deserialiser to use to deserialise values from the map. * @param values A map of serialised tuple values. * @param <V> The type to which tuple value have been serialised, e.g. String. * @return The created tuple. */ public <V> Tuple deserialise(BiFunction<V, Type, Object> deserialiser, Map<String, V> values) { if (deserialiser == null) throw new IllegalArgumentException("deserialiser must not be null"); if (values == null) throw new IllegalArgumentException("values must not be null"); checkMatchingKeys(values); Object[] valueArray = new Object[slots.length]; getIndices().forEach(i -> valueArray[i] = slots[i].deserialise(deserialiser, values)); return make(valueArray); }