public TupleKey[] getTupleKeys(TupleSchema schema) { return Stream.of(names).map(name -> schema.getKey(name, typesByName.get(name))).toArray(TupleKey[]::new); } }
/** * Get a key which can be used to retrieve a list of 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 elementType The element class of the values to retrieve with the key. * @param <T> The element type of the values to retrieve with the key. * @return The created key. */ public <T> TupleKey<List<T>> getListKey(String name, Class<T> elementType) { return getKey(name, Types.listOf(elementType)); }
/** * Get a key which can be used to retrieve a map of values 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 keyType The key class of the map to retrieve with the key. * @param valueType The value class of the map to retrieve with the key. * @param <K> The key type of the value to retrieve with the key. * @param <V> The value type of the value to retrieve with the key. * @return The created key. */ public <K, V> TupleKey<Map<K, V>> getMapKey(String name, Class<K> keyType, Class<V> valueType) { return getKey(name, Types.mapOf(keyType, valueType)); }
private static Map<Method, TupleKey> getTupleMapUncached(Class pojoClass, TupleSchema mappedSchema) { return Stream.of(safeGetBeanInfo(pojoClass).getPropertyDescriptors()) .collect(Collectors.toMap( PropertyDescriptor::getReadMethod, pd -> mappedSchema.getKey(pd.getName(), pd.getReadMethod().getGenericReturnType()) )); }
/** * Get a key which can be used to retrieve an Optional 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 valueType The class of the Optional value to retrieve with the key. * @param <T> The type of the Optinoal value to retrieve with the key. * @return The created key. */ public <T> TupleKey<Optional<T>> getOptionalKey(String name, Class<T> valueType) { return getKey(name, Types.optionalOf(valueType)); }