/** * Join given {@link PropertySet}s and return a new PropertySet containing all the properties of given sets. * @param <P> Actual property type * @param propertySets PropertySet to join (not null and not empty) * @return New PropertySet containing all the properties of given sets * @deprecated Using this method causes the loss of any property set configuration and/or identifier property * declaration. Use the default PropertySet builder to compose a new PropertySet from different property * sources. */ @SuppressWarnings("unchecked") @Deprecated @SafeVarargs static <P extends Property> PropertySet<P> join(PropertySet<? extends P>... propertySets) { if (propertySets == null || propertySets.length == 0) { throw new IllegalArgumentException("No PropertySet to join"); } Builder builder = builder(); for (PropertySet<? extends P> ps : propertySets) { ps.forEach(p -> builder.add(p)); } return builder.build(); }
public void propertySet2() { // tag::propertyset2[] final PathProperty<String> NAME = PathProperty.create("name", String.class); final PathProperty<String> SURNAME = PathProperty.create("surname", String.class); final PropertySet<Property<?>> SET = PropertySet.of(NAME, SURNAME); // <1> boolean contains = SET.contains(NAME); // <2> SET.forEach(p -> p.toString()); // <3> String captions = SET.stream().map(p -> p.getMessage()).collect(Collectors.joining()); // <4> List<Property<?>> list = SET.asList(); // <5> // end::propertyset2[] }
@SuppressWarnings("unchecked") @Override public Optional<BsonProjection> resolve(PropertySetProjection expression, MongoResolutionContext<?> context) throws InvalidExpressionException { // validate expression.validate(); // document context final MongoDocumentContext<?> documentContext = context.documentContext(expression.getPropertySet()); final BsonProjection.Builder builder = BsonProjection.builder(PropertyBox.class); documentContext.getPropertySet().forEach(property -> { documentContext.resolve(property, BsonProjection.class).ifPresent(projection -> { final BsonProjection<?> p = projection; // add field projections p.getFields().forEach((name, bson) -> { builder.field(name, bson); }); }); }); // converter builder.converter(DocumentConverter.propertyBox(expression.getPropertySet())); return Optional.of(builder.build()); }
/** * Clone this PropertyBox using given <code>propertySet</code>, i.e. create a new PropertyBox and copy all given set * property values from this box to the newly created box. * @param <P> Actual property type * @param propertySet Property set of the cloned PropertyBox (not null) * @return A new, cloned, PropertyBox instance with given property set */ @SuppressWarnings("unchecked") default <P extends Property> PropertyBox cloneBox(PropertySet<P> propertySet) { ObjectUtils.argumentNotNull(propertySet, "Property set must be not null"); Builder builder = builder(propertySet).invalidAllowed(true); propertySet.forEach(p -> { if (!p.isReadOnly()) { this.getValueIfPresent(p).ifPresent(v -> builder.set(p, v)); } }); return builder.invalidAllowed(this.isInvalidAllowed()).build(); }
ObjectUtils.argumentNotNull(propertySet, "Source property set must be not null"); final Builder builder = builder(); propertySet.forEach(p -> builder.add(p));