boolean belongsToSchema(TupleSchema schema) { return tupleKey.belongsToSchema(schema); }
@SuppressWarnings("unchecked") private IntFunction<TupleKeyValue> getValueFrom(Object[] args) { return i -> tupleKeys[i].of(args[i + 2]); }
void build(Object[] values) { tupleKey.set(values, value); }
/** * Get the value contained in the slot referenced by the supplied key. * @param key The key to use to find the slot. * @param <T> The type of the value stored in the slot. * @return The value stored in the slot. */ public <T> T get(TupleKey<T> key) { if (key == null) throw new IllegalArgumentException("key must not be null"); if (!key.belongsToSchema(schema)) throw new IllegalArgumentException( String.format("key %s does not belong to schema %s", key, schema)); return key.get(values); }
/** * Get a key which can be used to retrieve a value from a tuple in a type-safe way, without having to do an index lookup. * @param name The name of the slot to get a key for. * @param type The type of the value to retrieve with the key. * @param <T> The type of the value to retrieve with the key. * @return The created key. */ public <T> TupleKey<T> getKey(String name, Type type) { if (name == null) throw new IllegalArgumentException("name must not be null"); if (type == null) throw new IllegalArgumentException("type must not be null"); Integer valueIndex = slotLookup.get(name); if (valueIndex == null) throw new IllegalArgumentException(name); TupleSlot slot = slots[valueIndex]; if (!slot.acceptsType(type)) throw new IllegalArgumentException("Slot " + name + " does not accept type " + type); return new TupleKey<>(this, name, valueIndex); } }
@SuppressWarnings("unchecked") private IntFunction<TupleKeyValue> getValueFrom(Object[] args) { return i -> tupleKeys[i].of(args[i + 2]); } }