@SuppressWarnings({"unchecked", "rawtypes"}) private static void populatePrimitiveCollectionCodecs() { for (Map.Entry<DataType.Name, TypeCodec<?>> entry : primitiveCodecs.entrySet()) { DataType.Name type = entry.getKey(); TypeCodec<?> codec = entry.getValue(); primitiveListsCodecs.put(type, new ListCodec(codec)); primitiveSetsCodecs.put(type, new SetCodec(codec)); Map<DataType.Name, TypeCodec<Map<?, ?>>> valueMap = new EnumMap<DataType.Name, TypeCodec<Map<?, ?>>>(DataType.Name.class); for (Map.Entry<DataType.Name, TypeCodec<?>> valueEntry : primitiveCodecs.entrySet()) valueMap.put(valueEntry.getKey(), new MapCodec(codec, valueEntry.getValue())); primitiveMapsCodecs.put(type, valueMap); } }
@SuppressWarnings("unchecked") static <K, V> TypeCodec<Map<K, V>> mapOf(DataType keys, DataType values) { Map<DataType.Name, TypeCodec<Map<?, ?>>> valueCodecs = primitiveMapsCodecs.get(keys.getName()); TypeCodec<Map<?, ?>> codec = valueCodecs == null ? null : valueCodecs.get(values.getName()); return codec != null ? (TypeCodec)codec : new MapCodec<K, V>(TypeCodec.<K>createFor(keys.getName()), TypeCodec.<V>createFor(values.getName())); }
/** * Return a newly-created codec for the CQL type {@code map} whose key type * and value type are determined by the given codecs. * The returned codec maps the CQL type {@code map} into the Java type {@link Map}. * This method does not cache returned instances and returns a newly-allocated object * at each invocation. * * @param keyCodec the codec that will handle keys of this map. * @param valueCodec the codec that will handle values of this map. * @return A newly-created codec for CQL type {@code map}. */ public static <K, V> TypeCodec<Map<K, V>> map(TypeCodec<K> keyCodec, TypeCodec<V> valueCodec) { return new MapCodec<K, V>(keyCodec, valueCodec); }
/** * Return a newly-created codec for the CQL type {@code map} whose key type * and value type are determined by the given codecs. * The returned codec maps the CQL type {@code map} into the Java type {@link Map}. * This method does not cache returned instances and returns a newly-allocated object * at each invocation. * * @param keyCodec the codec that will handle keys of this map. * @param valueCodec the codec that will handle values of this map. * @return A newly-created codec for CQL type {@code map}. */ public static <K, V> TypeCodec<Map<K, V>> map(TypeCodec<K> keyCodec, TypeCodec<V> valueCodec) { return new MapCodec<K, V>(keyCodec, valueCodec); }
/** * Return a newly-created codec for the CQL type {@code map} whose key type * and value type are determined by the given codecs. * The returned codec maps the CQL type {@code map} into the Java type {@link Map}. * This method does not cache returned instances and returns a newly-allocated object * at each invocation. * * @param keyCodec the codec that will handle keys of this map. * @param valueCodec the codec that will handle values of this map. * @return A newly-created codec for CQL type {@code map}. */ public static <K, V> TypeCodec<Map<K, V>> map(TypeCodec<K> keyCodec, TypeCodec<V> valueCodec) { return new MapCodec<K, V>(keyCodec, valueCodec); }
/** * Return a newly-created codec for the CQL type {@code map} whose key type and value type are * determined by the given codecs. The returned codec maps the CQL type {@code map} into the Java * type {@link Map}. This method does not cache returned instances and returns a newly-allocated * object at each invocation. * * @param keyCodec the codec that will handle keys of this map. * @param valueCodec the codec that will handle values of this map. * @return A newly-created codec for CQL type {@code map}. */ public static <K, V> TypeCodec<Map<K, V>> map(TypeCodec<K> keyCodec, TypeCodec<V> valueCodec) { return new MapCodec<K, V>(keyCodec, valueCodec); }