/** * 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); }