@SuppressWarnings({ "unchecked", "rawtypes" }) private static Optional<Path<?>> getPathByName(PropertySet set, String propertyName) { if (set != null && propertyName != null) { return set.stream().filter(p -> Path.class.isAssignableFrom(p.getClass())) .filter(p -> propertyName.equals(((Path) p).getName())).findFirst(); } return Optional.empty(); }
@Override public Stream<Property> stream() { return getAndCheckPropertySet().stream(); }
@Override public Collection<Property<?>> getProperties() { return getPropertySet().stream().map(p -> (Property<?>) p).collect(Collectors.toList()); }
@Override public Collection<Property<?>> getProperties() { return getPropertySet().stream().map(p -> (Property<?>) p).collect(Collectors.toList()); }
/** * Try to obtain a {@link Path} which corresponds to given <code>propertyName</code>, using the provided property * set. * @param propertySet The property set to use * @param propertyName The property name to look for * @return Optional {@link Path} which corresponds to given <code>propertyName</code> */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static Optional<Path<?>> getPathByName(PropertySet propertySet, String propertyName) { if (propertySet != null && propertyName != null) { return propertySet.stream().filter(p -> Path.class.isAssignableFrom(p.getClass())) .filter(p -> propertyName.equals(((Path) p).getName())).findFirst(); } return Optional.empty(); }
/** * Get the {@link Property} in given <code>propertySet</code> which corresponds to given <code>name</code>. * @param propertySet Property set * @param name Property name * @return The {@link Property} in given <code>propertySet</code> which corresponds to given <code>name</code>, if * available */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static Optional<Property<?>> getPropertyByName(PropertySet propertySet, String name) { if (propertySet != null && name != null) { return propertySet.stream().filter(p -> p instanceof Path).filter(p -> name.equals(((Path<?>) p).getName())) .findFirst(); } return Optional.empty(); }
private static Optional<BsonProjection> resolveDocumentExpression(MongoDocumentContext<?> context, TypedExpression<?> expression) { // check property return context.getPropertySet().stream().filter(p -> p.equals(expression)).findFirst() .flatMap(p -> resolveExpression(context, p)); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("PropertyBox - PROPERTIES: "); sb.append(getPropertySet().stream().map( p -> "[\"" + p.getName() + "\":" + ((p.getType() != null) ? p.getType().getName() : "NOTYPE") + "]") .collect(Collectors.joining(","))); sb.append(" - VALUES: "); String values = propertyValues.entrySet().stream().filter(e -> e.getValue() != null) .map(e -> "(\"" + e.getKey().getName() + "\"=" + e.getValue() + ")").collect(Collectors.joining(",")); if (values == null || values.trim().equals("")) { sb.append("<EMPTY>"); } else { sb.append(values); } return sb.toString(); }
@Override public Stream<String> names() { return getPropertySet().stream().filter(p -> p.getName() != null).map(p -> p.getName()); }
/** * Build and bind {@link ViewComponent}s to the properties of the property set. */ @SuppressWarnings("unchecked") protected void build() { components.clear(); // render and bind components getPropertySet().stream().filter(property -> !isPropertyHidden(property)) .forEach(property -> renderAndBind(property)); }
/** * Build and bind {@link Input}s to the properties of the property set. */ @SuppressWarnings("unchecked") protected void build() { components.clear(); // render and bind components getPropertySet().stream().filter(property -> !configuration.get(property).isHidden()) .forEach(property -> renderAndBind(property)); }
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[] }
/** * Lookup for a property which can act as document identifier. * @param <S> PropertySet property type * @param <P> Path and Property type * @param propertySet Property set (not null) * @return The document identifier property, if available * @throws InvalidDocumentIdentifierException If more than one suitable property is found or if an identifier * property has invalid type */ @SuppressWarnings({ "rawtypes", "unchecked" }) private static <S extends Property, P extends Path & Property> P findDocumentIdProperty(PropertySet<S> propertySet) throws InvalidDocumentIdentifierException { // check identifiers for the default id path name P identifier = findDefaultDocumentIdPathProperty(propertySet, propertySet.identifiers()); if (identifier != null) { return identifier; } // check a suitable (unique) identifier property with a different path name if (propertySet.getIdentifiers().size() == 1) { S id = propertySet.getIdentifiers().iterator().next(); if (id != null && Path.class.isAssignableFrom(id.getClass())) { if (isValidDocumentIdPropertyType(id)) { return (P) id; } } } // check all properties for the default id path name return findDefaultDocumentIdPathProperty(propertySet, propertySet.stream()); }