private <ElementType extends OrientElement> Stream<ElementType> getIndexedElements(OIndex<Object> index, Iterator<Object> valuesIter, BiFunction<OrientGraph, OIdentifiable, ElementType> newElement) { return executeWithConnectionCheck(() -> { makeActive(); if (index == null) { return Collections.<ElementType>emptyList().stream(); } else { if (!valuesIter.hasNext()) { return index.cursor().toValues().stream().map(id -> newElement.apply(this, id)); } else { Stream<Object> convertedValues = StreamUtils.asStream(valuesIter).map(value -> convertValue(index, value)); Stream<OIdentifiable> ids = convertedValues.flatMap(v -> lookupInIndex(index, v)).filter(r -> r != null); Stream<ORecord> records = ids.map(id -> id.getRecord()); return records.map(r -> newElement.apply(this, getRawDocument(r))); } } }); }
/** * {@inheritDoc} */ @Override public Set<OIdentifiable> toValues() { if (source.isRebuilding()) throwRebuildException(); final Set<OIdentifiable> values = delegate.toValues(); if (source.getRebuildVersion() != indexRebuildVersion) throwRebuildException(); return values; }