/** * Set the paths to be used for operation values using a {@link PropertySet}. * <p> * Each property of the property set which corresponds to a {@link Path} will be used as operation path. * </p> * @param propertySet The property set to set (not null) */ public void setOperationPaths(PropertySet<?> propertySet) { ObjectUtils.argumentNotNull(propertySet, "Operation path property set must be not nulll"); setOperationPaths(PathPropertySetAdapter.create(propertySet).paths().collect(Collectors.toList()) .toArray(new Path<?>[0])); }
private static Optional<Path> getPathUsingDocumentContext(MongoResolutionContext context, String fieldName) { PathPropertySetAdapter adapter = MongoDocumentContext.isDocumentContext(context) .map(dc -> PathPropertySetAdapter.create(dc.getPropertySet())).orElse(null); if (adapter != null) { Optional<Path> path = adapter.getProperty(fieldName).flatMap(p -> adapter.getPath(p)).map(p -> (Path) p); if (path.isPresent()) { return path; } // check data path return adapter.propertyPaths() .filter(pp -> fieldName.equals(pp.getPath().relativeName(p -> p.getDataPath().orElse(p.getName())))) .map(pp -> (Path) pp.getPath()).findFirst(); } return Optional.empty(); }
@SuppressWarnings("unchecked") @Override @Deprecated public O add(Map<Path<?>, Object> values) { if (values != null && !values.isEmpty()) { final PropertySet<?> propertySet = getDefinition().getPropertySet().orElse(asPropertySet(values.keySet())); final PropertyBox propertyBox = PropertyBox.builder(propertySet).invalidAllowed(true).build(); final PathPropertySetAdapter adapter = PathPropertySetAdapter.create(propertySet); for (Entry<Path<?>, Object> entry : values.entrySet()) { adapter.getProperty(entry.getKey()).ifPresent(p -> { if (entry.getValue() != null) { propertyBox.setValue((Property<Object>) p, entry.getValue()); } }); } getDefinition().addValue(propertyBox); return getActualOperation(); } return getActualOperation(); }
final PathPropertySetAdapter adapter = PathPropertySetAdapter.create(propertySet); for (Property property : propertySet) { Optional<Path> propertyPath = adapter.getPath(property);
public void pathPropertySetAdapter2() { // tag::ppsa3[] final StringProperty STR = StringProperty.create("str"); final NumericProperty<Integer> ITG = NumericProperty.integerType("itg"); final PropertySet<?> SET = PropertySet.of(STR, ITG); PathPropertySetAdapter adapter = PathPropertySetAdapter.create(SET); // <1> boolean contains = adapter.contains("str"); // <2> Optional<Property<?>> property = adapter.getProperty("str"); // <3> Optional<Property<String>> typedProperty = adapter.getProperty("str", String.class); // <4> Stream<String> paths = adapter.names(); // <5> // end::ppsa3[] }
public void pathPropertySetAdapter1() { // tag::ppsa1[] final StringProperty STR = StringProperty.create("str"); final NumericProperty<Integer> ITG = NumericProperty.integerType("itg"); final PropertySet<?> SET = PropertySet.of(STR, ITG); final Path<String> PATH = Path.of("str", String.class); PathPropertySetAdapter adapter = PathPropertySetAdapter.create(SET); // <1> boolean contains = adapter.contains(PATH); // <2> Optional<Property<String>> property = adapter.getProperty(PATH); // <3> Optional<Path<String>> path = adapter.getPath(STR); // <4> Stream<Path<?>> paths = adapter.paths(); // <5> // end::ppsa1[] // tag::ppsa2[] PathPropertySetAdapter pathPropertySetAdapter = PathPropertySetAdapter.builder(SET) // <1> .pathConverter(new MyPathConverter()) // <2> .pathMatcher(new MyPathMatcher()) // <3> .build(); // end::ppsa2[] }