Пример #1
0
 /**
  * gets the requested values from the Has step. If it's a single value, wrap it in an array,
  * otherwise return the array
  */
 private Optional<Pair<String, Iterator<Object>>> getValuePair(HasContainer c) {
   Iterator<Object> values;
   if (c.getPredicate().getBiPredicate() == Contains.within)
     values = ((Iterable<Object>) c.getValue()).iterator();
   else values = IteratorUtils.of(c.getValue());
   return Optional.of(new Pair<>(c.getKey(), values));
 }
  private Predicates getPredicates(Step step, Traversal.Admin traversal) {
    Predicates predicates = new Predicates();
    Step<?, ?> nextStep = step.getNextStep();

    while (true) {
      if (nextStep instanceof HasContainerHolder) {
        HasContainerHolder hasContainerHolder = (HasContainerHolder) nextStep;
        boolean skip = false;
        for (HasContainer has : hasContainerHolder.getHasContainers())
          if (has.getPredicate().getTraversals().size() > 0) skip = true;

        if (!skip) {
          hasContainerHolder.getHasContainers().forEach((has) -> predicates.hasContainers.add(has));
          nextStep.getLabels().forEach(label -> predicates.labels.add(label.toString()));
          traversal.removeStep(nextStep);
        }
      } else if (nextStep instanceof RangeGlobalStep) {
        RangeGlobalStep rangeGlobalStep = (RangeGlobalStep) nextStep;
        predicates.limitLow = rangeGlobalStep.getLowRange();
        predicates.limitHigh = rangeGlobalStep.getHighRange();
        traversal.removeStep(nextStep);
      } else return predicates;

      nextStep = nextStep.getNextStep();
    }
  }
Пример #3
0
 private <X extends Element> Iterator<X> iteratorList(final Iterator<X> iterator) {
   final List<X> list = new ArrayList<>();
   while (iterator.hasNext()) {
     final X e = iterator.next();
     if (HasContainer.testAll(e, this.hasContainers)) list.add(e);
   }
   return list.iterator();
 }
Пример #4
0
  /**
   * Gets an iterator over those vertices/edges that have the specific IDs wanted, or those that
   * have indexed properties with the wanted values, or failing that by just getting all of the
   * vertices or edges.
   *
   * @param getElementsByIds Function that will return an iterator over all the vertices/edges in
   *     the graph that have the specific IDs
   * @param getElementsByIndex Function that returns a stream of all the vertices/edges in the graph
   *     that have an indexed property with a specific value
   * @param getAllElements Function that returns an iterator of all the vertices or all the edges
   *     (i.e. full scan)
   * @return An iterator for all the vertices/edges for this step
   */
  private <ElementType extends Element> Iterator<? extends ElementType> elements(
      BiFunction<OrientGraph, Object[], Iterator<ElementType>> getElementsByIds,
      TriFunction<OrientGraph, OIndex<Object>, Iterator<Object>, Stream<? extends ElementType>>
          getElementsByIndex,
      Function<OrientGraph, Iterator<ElementType>> getAllElements) {
    final OrientGraph graph = getGraph();

    if (this.ids != null && this.ids.length > 0) {
      /** Got some element IDs, so just get the elements using those */
      return this.iteratorList(getElementsByIds.apply(graph, this.ids));
    } else {
      /** Have no element IDs. See if there's an indexed property to use */
      Set<OrientIndexQuery> indexQueryOptions = findIndex();

      if (!indexQueryOptions.isEmpty()) {
        List<ElementType> elements = new ArrayList<>();

        indexQueryOptions.forEach(
            indexQuery -> {
              OLogManager.instance().debug(this, "using " + indexQuery);
              Stream<? extends ElementType> indexedElements =
                  getElementsByIndex.apply(graph, indexQuery.index, indexQuery.values);
              elements.addAll(
                  indexedElements
                      .filter(element -> HasContainer.testAll(element, this.hasContainers))
                      .collect(Collectors.<ElementType>toList()));
            });

        return elements.iterator();
      } else {
        OLogManager.instance()
            .warn(
                this,
                "scanning through all elements without using an index for Traversal "
                    + getTraversal());
        return this.iteratorList(getAllElements.apply(graph));
      }
    }
  }