
com.opencredo.concourse.data.tuples.Tuple Maven / Gradle / Ivy
The newest version!
package com.opencredo.concourse.data.tuples;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An immutable tuple of named and typed values, conforming to a TupleSchema.
*/
public final class Tuple {
private final TupleSchema schema;
private final Object[] values;
Tuple(TupleSchema schema, Object[] values) {
this.schema = schema;
this.values = values;
}
/**
* Get the value contained in the slot with the supplied name.
* @param name The name of the slot to get the value from.
* @return The value stored in that slot.
*/
public Object get(String name) {
checkNotNull(name, "name must not be null");
return schema.get(name, values);
}
/**
* Get the value contained in the slot referenced by the supplied key.
* @param key The key to use to find the slot.
* @param The type of the value stored in the slot.
* @return The value stored in the slot.
*/
public T get(TupleKey key) {
checkNotNull(key, "key must not be null");
checkArgument(key.belongsToSchema(schema),
"key %s does not belong to schema %s", key, schema);
return key.get(values);
}
/**
* Serialise the tuple using the supplied serialiser.
* @param serialiser The serialiser to use to serialise each value in the tuple.
* @param The type to serialise each value to, e.g. String.
* @return A map of serialised values.
*/
public Map serialise(Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy