/** * Returns an {@code Exception} supplier for when no attribute could be * found on a specified key in a specified document. * * @param document the document * @param key the key * @return the {@code Exception} supplier */ public static Supplier<NoSuchElementException> newNoSuchElementExceptionFor( Document document, String key) { return () -> new NoSuchElementException( "An attribute with the key '" + key + "' could not be found in " + document + " with name (" + Optional.ofNullable(document) .flatMap(doc -> doc.getAsString("name")) .orElse("null") + ")" ); }
/** * Generates a new default name for the specified child by appending an * unique number to the {@link HasMainInterface#mainInterface()} of that * document. * <p> * This method will only suggest a new name for the specified child, not set * it. * * @param <C> the child type * @param childDocument the child to name * @return the suggested name for that child */ default <C extends Document & HasName & HasMainInterface> String defaultNameFor(C childDocument) { int counter = 1; String nameCandidate; do { nameCandidate = childDocument.mainInterface().getSimpleName() + counter++; } while ( children() .map(child -> child.getAsString(NAME)) .anyMatch(nameCandidate::equals) ); return nameCandidate; } }
final String id = doc.getAsString("id").orElseGet(() -> doc.getAsString("name").orElseThrow(() -> new RuntimeException("No id in document."))); if (coll.removeIf(d -> d.get("id").equals(id))) { edits.increment();