/** * Get a {@link Stream} of the properties which represent the unique identifier of this property set. * @return The identifier properties stream, empty if no identifier is provided by this property set * @since 5.1.0 */ default Stream<P> identifiers() { return getIdentifiers().stream(); }
/** * Get the first property which acts as property set identifier, if available. * @return The first <em>identifier</em> property, or an empty Optional if no identifier is provided * @since 5.1.0 */ default Optional<P> getFirstIdentifier() { return getIdentifiers().stream().findFirst(); }
@Override public Set<Property> getIdentifiers() { return getAndCheckPropertySet().getIdentifiers(); }
@SuppressWarnings("unchecked") @Override public Set<Path<?>> getPathIdentifiers() { Set<Path<?>> pathIds = new HashSet<>(getPropertySet().getIdentifiers().size()); for (Property id : getPropertySet().getIdentifiers()) { Optional<Path<?>> path = getPathConverter().convert(id); if (!path.isPresent()) { return Collections.emptySet(); } pathIds.add(path.get()); } return pathIds; }
/** * 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()); }
public void propertySet3() { // tag::propertyset3[] final NumericProperty<Long> ID = NumericProperty.longType("id"); final StringProperty NAME = StringProperty.create("name"); PropertySet<Property<?>> SET = PropertySet.builder().add(ID).add(NAME).identifier(ID).build(); // <1> SET = PropertySet.builderOf(ID, NAME).identifier(ID).build(); // <2> Set<Property<?>> ids = SET.getIdentifiers(); // <3> Optional<Property<?>> id = SET.getFirstIdentifier(); // <4> SET.identifiers().forEach(p -> p.toString()); // <5> // end::propertyset3[] }