public void parameterSet() { // tag::params[] final ConfigProperty<String> property = ConfigProperty.create("test", String.class); ParameterSet set = ParameterSet.builder().withParameter("testParameter", 1L) // <1> .withParameter(property, "testValue") // <2> .build(); boolean present = set.hasParameter("testParameter"); // <3> present = set.hasNotNullParameter("testParameter"); // <4> Optional<String> value = set.getParameter("testParameter", String.class); // <5> String val = set.getParameter("testParameter", String.class, "default"); // <6> Optional<String> configPropertyValue = set.getParameter(property); // <7> String configPropertyVal = set.getParameter(property, "default"); // <8> boolean matches = set.hasParameterValue("testParameter", "myValue"); // <9> matches = set.hasParameterValue(property, "myValue"); // <10> // end::params[] }
@Override public Builder<S> withParameters(ParameterSet parameters) { if (parameters != null) { parameters.forEachParameter((n, v) -> instance.addParameter(n, v)); } return builder(); }
/** * Get the {@link PropertyBoxSerializationMode} to use. Check {@link PropertyBox} configuration attributes using * {@link JsonConfigProperties#PROPERTYBOX_SERIALIZATION_MODE}. If not available, the construction time value is * used. * @param propertyBox The PropertBox to serialize * @return The {@link PropertyBoxSerializationMode} to use */ private PropertyBoxSerializationMode getPropertyBoxSerializationMode(PropertyBox propertyBox) { // check config parameter if (propertyBox.getConfiguration().hasParameter(JsonConfigProperties.PROPERTYBOX_SERIALIZATION_MODE)) { return propertyBox.getConfiguration().getParameter(JsonConfigProperties.PROPERTYBOX_SERIALIZATION_MODE, PropertyBoxSerializationMode.getDefault()); } return propertyBoxSerializationMode; }
/** * Get typed parameter value with default-fallback support. An unchecked cast to required type will be performed. If * parameter value was not found, <code>defaultValue</code> is returned. * @param <T> Parameter value type * @param name Parameter name (not null) * @param type Expected value type * @param defaultValue Default value to return when parameter was not found * @return Parameter value, or <code>defaultValue</code> if parameter is not present * @throws TypeMismatchException If the actual parameter value type is not compatible with the expected type */ default <T> T getParameter(String name, Class<T> type, T defaultValue) { return getParameter(name, type).orElse(defaultValue); }
parameters.getParameter(TEMPORAL_TYPE, TemporalType.DATE)); parameters.getParameterIf(DISABLE_GROUPING, v -> v) .ifPresent(v -> features.add(NumberFormatFeature.DISABLE_GROUPING)); parameters.getParameterIf(HIDE_DECIMALS_WHEN_ALL_ZERO, v -> v) .ifPresent(v -> features.add(NumberFormatFeature.HIDE_DECIMALS_WHEN_ALL_ZERO)); parameters.getParameterIf(PERCENT_STYLE, v -> v) .ifPresent(v -> features.add(NumberFormatFeature.PERCENT_STYLE)); return convertNumber((Number) value, parameters.getParameter(DECIMAL_POSITIONS, -1), features.toArray(new NumberFormatFeature[0]));
if (propertySet.getConfiguration().hasParameters()) { propertySet.getConfiguration().forEachParameter((n, v) -> builder.configuration(n, v));
@Override public ParameterSet getQueryParameters() { final ParameterSet.Builder<?> builder = ParameterSet.builder().withParameters(queryParameters); // externally provided getQueryConfigurationProviders().forEach(p -> { ParameterSet parameters = p.getQueryParameters(); if (parameters != null) { builder.withParameters(parameters); } }); return queryParameters; }
final ParameterSet presentationParameters = (parameters != null) ? parameters : ParameterSet.builder().build(); return stringValue.map(v -> presentationParameters.getParameterIf(MAX_LENGTH, ml -> ml > 0) .map(ml -> FormatUtils.limit(v, ml, true)).orElse(v)).orElse(null);
/** * Check if a parameter is present using given {@link ConfigProperty} property key. <code>null</code> parameter * values are allowed, so if a parameter is present it doesn't means that it has a value. * @param <T> Parameter value type * @param property ConfigProperty to check (not null) * @return <code>true</code> if parameter is present, <code>false</code> otherwise */ default <T> boolean hasParameter(ConfigProperty<T> property) { ObjectUtils.argumentNotNull(property, "ConfigProperty must be not null"); return hasParameter(property.getKey()); }
/** * Just like {@link #hasParameter(ConfigProperty)}, check if parameter with given key is present, but returns * <code>true</code> only if parameter has a not <code>null</code> value. * @param <T> Parameter value type * @param property ConfigProperty to check (not null) * @return <code>true</code> if parameter is present and its value is not null, <code>false</code> otherwise */ default <T> boolean hasNotNullParameter(ConfigProperty<T> property) { ObjectUtils.argumentNotNull(property, "ConfigProperty must be not null"); return hasNotNullParameter(property.getKey()); }
/** * Checks if a parameter named with given <code>property</code> key is present and its value is equal to given * <code>value</code>. * @param <T> Parameter value type * @param property Configuration property (not null) * @param value Parameter value to check (may be null) * @return <code>true</code> if the property is present and its value is equal to given <code>value</code>, * <code>false</code> if the property is not present or if its value it's not equal to the expected value */ default <T> boolean hasParameterValue(ConfigProperty<T> property, T value) { ObjectUtils.argumentNotNull(property, "ConfigProperty must be not null"); return hasParameterValue(property.getKey(), value); }
/** * Get the data model path name to which this bean property set is mapped. * <p> * If the {@link DataMappable#PATH} configuration property is present, the property value is returned. Otherwise, * the simple bean class name is returned. * </p> * <p> * The {@link DataPath} annotation can be used on bean class to declare the data path at bean introspection time. * </p> * @return The data model path name */ @Override default Optional<String> getDataPath() { return getConfiguration().getParameter(DataMappable.PATH); }
@Override public String present(Property<T> property, T value) { ObjectUtils.argumentNotNull(property, "Property must be not null"); // check TemporalType ParameterSet.Builder<?> builder = ParameterSet.builder().withParameters(property.getConfiguration()); property.getConfiguration().getTemporalType() .ifPresent(t -> builder.withParameter(StringValuePresenter.TEMPORAL_TYPE, t)); final ParameterSet parameters = builder.build(); // check collection property if (value != null && CollectionProperty.class.isAssignableFrom(property.getClass()) && Collection.class.isAssignableFrom(value.getClass())) { final Class<?> elementType = ((CollectionProperty<?, ?>) property).getElementType(); return ((Collection<?>) value).stream().map(v -> presentValue(elementType, v, parameters)) .collect(Collectors.joining(",")); } // default presentation return presentValue(property.getType(), value, parameters); }
/** * Convert an array of values * @param values Values to convert * @param parameters Presentation parameters * @return String converted value */ private static String convertArray(Object[] values, ParameterSet parameters) { if (values.length == 0) { return null; } String separator = parameters.getParameter(MULTIPLE_VALUES_SEPARATOR, DEFAULT_MULTIPLE_VALUES_SEPARATOR); StringBuilder sb = new StringBuilder(); for (Object v : values) { if (v != null) { String rv = convertValue(v, v.getClass(), parameters); if (rv != null) { if (sb.length() > 0) { sb.append(separator); } sb.append(rv); } } } return sb.toString(); }
ParameterSet parameters = p.getQueryParameters(); if (parameters != null) { parameters.forEachParameter((n, v) -> q.parameter(n, v));
public void present() { String presented = StringValuePresenter.getDefault().present("stringValue"); // <1> presented = StringValuePresenter.getDefault().present("stringValue", ParameterSet.builder().withParameter(StringValuePresenter.MAX_LENGTH, 6).build()); // <2> presented = StringValuePresenter.getDefault().present(MyEnum.VALUE1); // <3> presented = StringValuePresenter.getDefault().present(new MyEnum[] { MyEnum.VALUE1, MyEnum.VALUE2 }); // <4> }
/** * Configure a read operation, setting the {@link ReadConcern} and the {@link ReadPreference} if available from * write options or context. * @param <T> Collection type * @param collection Mongo collection * @param context Mongo context * @param operationParameters Operation configuration parameters * @return The configured collection */ public static <T> MongoCollection<T> configureRead(MongoCollection<T> collection, MongoContext<?> context, ParameterSet operationParameters) { if (operationParameters == null) { return collection; } // check read concern Optional<ReadConcern> rc = operationParameters.getParameter(ReadOperationConfiguration.READ_CONCERN); if (!rc.isPresent()) { // use default if available rc = context.getDefaultReadConcern(); } MongoCollection<T> c = rc.map(rdc -> collection.withReadConcern(rdc)).orElse(collection); // check read preference Optional<ReadPreference> rp = operationParameters.getParameter(ReadOperationConfiguration.READ_PREFERENCE); if (!rp.isPresent()) { // use default if available rp = context.getDefaultReadPreference(); } return rp.map(rdp -> c.withReadPreference(rdp)).orElse(c); }
ParameterSet parameters = p.getQueryParameters(); if (parameters != null) { parameters.forEachParameter((n, v) -> q.parameter(n, v));
/** * Configure a read operation, setting the {@link ReadConcern} and the {@link ReadPreference} if available from * write options or context. * @param <T> Collection type * @param collection Mongo collection * @param context Mongo context * @param operationParameters Operation configuration parameters * @return The configured collection */ public static <T> MongoCollection<T> configureRead(MongoCollection<T> collection, MongoContext<?> context, ParameterSet operationParameters) { if (operationParameters == null) { return collection; } // check read concern Optional<ReadConcern> rc = operationParameters.getParameter(ReadOperationConfiguration.READ_CONCERN); if (!rc.isPresent()) { // use default if available rc = context.getDefaultReadConcern(); } MongoCollection<T> c = rc.map(rdc -> collection.withReadConcern(rdc)).orElse(collection); // check read preference Optional<ReadPreference> rp = operationParameters.getParameter(ReadOperationConfiguration.READ_PREFERENCE); if (!rp.isPresent()) { // use default if available rp = context.getDefaultReadPreference(); } return rp.map(rdp -> c.withReadPreference(rdp)).orElse(c); }
parameters.forEachParameter((n, v) -> query.parameter(n, v)); p.getQueryParameters().forEachParameter((n, v) -> query.parameter(n, v));