private String generatePropertyName(Property<?> property) { String propertyName = property.getName(); if (propertyName == null) { propertyName = "property"; } // check duplicates Integer count = generatedPropertyIds.get(propertyName); if (count != null && count > 0) { int sequence = count.intValue() + 1; generatedPropertyIds.put(propertyName, sequence); return propertyName + sequence; } else { generatedPropertyIds.put(propertyName, 1); return propertyName; } }
@Override protected String generateColumnKey(Property<?> property) { if (Path.class.isAssignableFrom(property.getClass())) { return ((Path<?>) property).fullName(); } String name = property.getName(); if (name != null) { return name; } return String.valueOf(property.hashCode()); }
@SuppressWarnings("rawtypes") public void identity() { // tag::identity[] Property.Builder<String, Property<String>, ?> builder = getPropertyBuilder(); builder.hashCodeProvider(property -> Optional.of(property.getName().hashCode())) // <1> .equalsHandler((property, other) -> { // <2> if (other instanceof Property) return property.getName().equals(((Property) other).getName()); return false; }); // end::identity[] }
/** * Get the property serialization name, if the property serialization names hierarchy is not empty. * @param property Property * @return Optional property serialization name */ private static Optional<String> getSerializationPropertyName(Property<?> property) { List<String> names = (Path.class.isAssignableFrom(property.getClass())) ? getPathNameHierarchy((Path<?>) property) : Collections.singletonList(property.getName()); if (!names.isEmpty()) { return Optional.ofNullable(names.get(names.size() - 1)); } return Optional.empty(); }
/** * Get the property serialization names hierarchy, only if the property must be included in serialization according * to current validator. * @param property The property for which to obtain the serialization hierarchy * @return the property serialization names hierarchy */ private List<String> getPropertySerializationHierarchy(Property<?> property) { if (!validator.test(property)) { return Collections.emptyList(); } if (Path.class.isAssignableFrom(property.getClass())) { return getPathNameHierarchy((Path<?>) property); } if (property.getName() != null) { return Collections.singletonList(property.getName()); } return Collections.emptyList(); }
/** * Check if given expression represents the default document id attribute. * @param expression The expression to check * @return Whether the given expression represents the default document id attribute */ public static boolean isDocumentIdPropertyPath(TypedExpression<?> expression) { if (Path.class.isAssignableFrom(expression.getClass())) { return MongoDocumentContext.ID_FIELD_NAME.equals(((Path<?>) expression).relativeName()); } if (Property.class.isAssignableFrom(expression.getClass())) { return MongoDocumentContext.ID_FIELD_NAME.equals(((Property<?>) expression).getName()); } return false; }
@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 Optional<Property<?>> getProperty(String name) { ObjectUtils.argumentNotNull(name, "Property name must be not null"); return Optional.ofNullable(getNamePropertyCache().computeIfAbsent(name, pn -> { for (Property property : getPropertySet()) { if (pn.equals(property.getName())) { return property; } } return null; })); }
@Override protected Optional<Localizable> getDefaultColumnHeader(Property<?> property) { if (property.getMessage() != null || property.getMessageCode() != null) { return Optional.of(Localizable.builder() .message((property.getMessage() != null) ? property.getMessage() : property.getName()) .messageCode(property.getMessageCode()).build()); } if (Path.class.isAssignableFrom(property.getClass()) && property.getName() != null) { return Optional.of(Localizable.of(property.getName())); } return Optional.empty(); }
/** * Configure given component using given property. * @param property Property to which the component refers * @param component Component to configure */ protected void configurePropertyComponent(Property<?> property, E component) { if (component != null) { component.hasLabel().ifPresent(hasLabel -> { if (hiddenPropertyCaptions.contains(property)) { hasLabel.setLabel(null); } else { if (propertyCaptions.containsKey(property)) { LocalizationProvider.localize(propertyCaptions.get(property)) .ifPresent(message -> hasLabel.setLabel(message)); } else { if (hasLabel.getLabel() == null) { // default behaviour hasLabel.setLabel( LocalizationProvider.localize(property).orElseGet(() -> property.getName())); } } } }); } }