/** * Obtain a {@link EncodableValue} given {@code value}. * * @param value the value to encode, may be {@literal null}. * @return the {@link EncodableValue} for {@code value}. */ @SuppressWarnings("unchecked") public static EncodableValue create(@Nullable Object value) { if (value instanceof byte[]) { return new BinaryValue((byte[]) value); } if (value instanceof UUID) { return new UuidValue((UUID) value); } if (value instanceof Collection) { Collection<?> collection = (Collection<?>) value; Class<?> commonElement = CollectionUtils.findCommonElementType(collection); if (commonElement != null) { if (UUID.class.isAssignableFrom(commonElement)) { return new UuidCollection((Collection<UUID>) value); } if (byte[].class.isAssignableFrom(commonElement)) { return new BinaryCollectionValue((Collection<byte[]>) value); } } } return new ObjectValue(value); }
/** * Obtain a {@link EncodableValue} given {@code value}. * * @param value the value to encode, may be {@literal null}. * @return the {@link EncodableValue} for {@code value}. */ @SuppressWarnings("unchecked") public static EncodableValue create(@Nullable Object value) { if (value instanceof byte[]) { return new BinaryValue((byte[]) value); } if (value instanceof UUID) { return new UuidValue((UUID) value); } if (value instanceof Collection) { Collection<?> collection = (Collection<?>) value; Class<?> commonElement = CollectionUtils.findCommonElementType(collection); if (commonElement != null) { if (UUID.class.isAssignableFrom(commonElement)) { return new UuidCollection((Collection<UUID>) value); } if (byte[].class.isAssignableFrom(commonElement)) { return new BinaryCollectionValue((Collection<byte[]>) value); } } } return new ObjectValue(value); }