private boolean checkIf(Document doc, String param, String value) { final Pattern pattern = Pattern.compile(value); return doc.get(param) .map(Object::toString) .filter(pattern.asPredicate()) .isPresent(); }
/** * Returns the children on the specified key, instantiated using the * specified constructor. This instance will be used as parent to the * constructor. * * @param <P> the parent type * @param <T> the child type * @param key the key * @param constructor the child constructor to use * @return a stream of constructed children * * @see #children() */ default <P extends Document, T extends Document> Stream<T> children( String key, BiFunction<P, Map<String, Object>, T> constructor) { final List<Map<String, Object>> list = get(key) .map(DocumentUtil::castToDocumentList) .orElse(null); if (list == null) { return Stream.empty(); } else { @SuppressWarnings("unchecked") final P thizz = (P)this; return list.stream().map(map -> constructor.apply(thizz, map)); } }
/** * Creates and returns a new raw map on a specified key in the specified * document. This might involve creating a new list if no such existed * already. If children already existed on that key, the new one is simply * added to the end of the list. * * @param parent the parent to create it in * @param key the key to create it under * @return the newly creating raw child map */ public static Map<String, Object> newDocument(Document parent, String key) { requireNonNull(parent); requireNonNull(key); final List<Map<String, Object>> children = parent.get(key) .map(DocumentUtil::castToDocumentList) .orElseGet(() -> { final List<Map<String, Object>> list = new CopyOnWriteArrayList<>(); parent.put(key, list); return list; }); final Map<String, Object> child = new ConcurrentSkipListMap<>(); children.add(child); return child; }
private Object parse(Document doc, String param, String value) { final Optional<Object> current = doc.get(param); final Object newValue; if (current.isPresent()) {