Java Code Examples for com.google.common.collect.Iterators#singletonIterator()

The following examples show how to use com.google.common.collect.Iterators#singletonIterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FacetedFunction.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public Entry<Key,Value> apply(Entry<Key,Value> entry) {
    
    Entry<Key,Document> doc = deserializer.apply(entry);
    
    if (null == summarizer) {
        summarizer = new MergeSummarization(doc.getKey(), doc.getValue());
    }
    Iterator<Entry<Key,Document>> finalIter = Iterators.singletonIterator(summarizer.apply(doc));
    
    for (Function<Entry<Key,Document>,Entry<Key,Document>> func : transforms) {
        finalIter = Iterators.transform(finalIter, func);
    }
    
    return serializer.apply(finalIter.next());
    
}
 
Example 2
Source File: DynamicFacetIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
protected Iterator<Entry<Key,Document>> summarize(Iterator<Entry<Key,Document>> fieldIndexDocuments) {
    
    if (fieldIndexDocuments.hasNext()) {
        Entry<Key,Document> topEntry = fieldIndexDocuments.next();
        
        CardinalitySummation summarizer = new CardinalitySummation(topEntry.getKey(), topEntry.getValue(), merge);
        while (fieldIndexDocuments.hasNext()) {
            topEntry = fieldIndexDocuments.next();
            summarizer.apply(topEntry);
        }
        
        return Iterators.singletonIterator(summarizer.getTop());
    } else
        return fieldIndexDocuments;
}
 
Example 3
Source File: WhereOptimizer.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Iterator<Expression> visitEnter(ComparisonExpression node) {
    Expression rhs = node.getChildren().get(1);
    if (!rhs.isStateless() || node.getFilterOp() == CompareOp.NOT_EQUAL) {
        return Iterators.emptyIterator();
    }
    return Iterators.singletonIterator(node.getChildren().get(0));
}
 
Example 4
Source File: SimpleEdgesConnecting.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Iterator<E> iterator() {
  E connectingEdge = getConnectingEdge();
  return (connectingEdge == null)
      ? ImmutableSet.<E>of().iterator()
      : Iterators.singletonIterator(connectingEdge);
}
 
Example 5
Source File: RangeTombstoneList.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public Iterator<RangeTombstone> iterator(Composite from, Composite till)
{
    int startIdx = from.isEmpty() ? 0 : searchInternal(from, 0);
    final int start = startIdx < 0 ? -startIdx-1 : startIdx;

    if (start >= size)
        return Iterators.<RangeTombstone>emptyIterator();

    int finishIdx = till.isEmpty() ? size : searchInternal(till, start);
    // if stopIdx is the first range after 'till' we care only until the previous range
    final int finish = finishIdx < 0 ? -finishIdx-2 : finishIdx;

    // Note: the following is true because we know 'from' is before 'till' in sorted order.
    if (start > finish)
        return Iterators.<RangeTombstone>emptyIterator();
    else if (start == finish)
        return Iterators.<RangeTombstone>singletonIterator(rangeTombstone(start));

    return new AbstractIterator<RangeTombstone>()
    {
        private int idx = start;

        protected RangeTombstone computeNext()
        {
            if (idx >= size || idx > finish)
                return endOfData();

            return rangeTombstone(idx++);
        }
    };
}
 
Example 6
Source File: GamlResourceIndexer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @see msi.gama.lang.gaml.indexer.IModelIndexer#allImportsOf(org.eclipse.emf.common.util.URI)
 */
public static Iterator<URI> allImportsOf(final URI uri) {
	if (!indexes(uri)) {
		return Iterators.singletonIterator(uri);// .emptyIterator();
	}
	final Iterator<URI> result = new BreadthFirstIterator(index, GamlResourceServices.properlyEncodedURI(uri));
	result.next(); // to eliminate the uri
	return result;
}
 
Example 7
Source File: AbstractStageWholeFileToAvro.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public CloseableIterator<AvroWholeFile> toAvroObjects(final URL f) {
  try {
    // TODO: consider a streaming mechanism in case a single file is too
    // large
    return new CloseableIterator.Wrapper<>(
        Iterators.singletonIterator(
            new AvroWholeFile(ByteBuffer.wrap(IOUtils.toByteArray(f)), f.getPath())));
  } catch (final IOException e) {
    LOGGER.warn("Unable to read file", e);
  }
  return new CloseableIterator.Empty<>();
}
 
Example 8
Source File: CreateTableCompiler.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Expression> visitEnter(ComparisonExpression node) {
    if (node.getFilterOp() == CompareOp.EQUAL && node.getChildren().get(1).isStateless() 
    		&& node.getChildren().get(1).getDeterminism() == Determinism.ALWAYS ) {
        return Iterators.singletonIterator(node.getChildren().get(0));
    }
    return super.visitEnter(node);
}
 
Example 9
Source File: CalculatedTimeSeries.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Iterator<DoublePoint> iterator() {
    List<DoubleTimeSeries> timeSeriesList = loadData();
    NodeCalc resolvedNodeCalc = resolve(timeSeriesList);
    if (timeSeriesList.isEmpty()) {
        return Iterators.singletonIterator(evaluate(resolvedNodeCalc));
    } else {
        return Iterators.transform(DoubleTimeSeries.iterator(timeSeriesList), multiPoint -> evaluateMultiPoint(resolvedNodeCalc, multiPoint));
    }
}
 
Example 10
Source File: RoutineBodyTreeImpl.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Tree> childrenIterator() {
	if (externalRoutineBody!=null){
		return Iterators.singletonIterator(externalRoutineBody);
	} else {
		return Iterators.singletonIterator(statement);
	}
}
 
Example 11
Source File: SingleRowBucket.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Iterator<Row> iterator() {
    return Iterators.singletonIterator(row);
}
 
Example 12
Source File: CreateTableCompiler.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Iterator<Expression> visitEnter(ComparisonExpression node) {
    return node.getFilterOp() == CompareOp.EQUAL && node.getChildren().get(1).isStateless() && node.getChildren().get(1).isDeterministic() ? Iterators.singletonIterator(node.getChildren().get(0)) : super.visitEnter(node);
}
 
Example 13
Source File: TreeIterator.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
public TreeIterator(DirectoryFetcher directoryFetcher, Digest rootDigest, String pageToken) {
  this.directoryFetcher = directoryFetcher;
  parentPath = new ArrayDeque<Digest>();
  pointers = new Stack<Iterator<Digest>>();

  Iterator<Digest> iter = Iterators.singletonIterator(rootDigest);

  // initial page token is empty
  if (!pageToken.isEmpty()) {
    TreeIteratorToken token = parseToken(BaseEncoding.base64().decode(pageToken));

    for (Digest digest : token.getDirectoriesList()) {
      boolean found = false;
      while (!found && iter.hasNext()) {
        if (iter.next().equals(digest)) {
          found = true;
        }
      }
      if (!found) {
        throw new IllegalArgumentException();
      }
      parentPath.addLast(digest);
      pointers.push(iter);
      Directory directory = getDirectory(digest);
      if (directory == null) {
        // some directory data has disappeared, current iter
        // is correct and will be next directory fetched
        break;
      }
      iter =
          Iterators.transform(
              directory.getDirectoriesList().iterator(),
              directoryNode -> {
                return directoryNode.getDigest();
              });
    }
  }
  pointers.push(iter);
  path = parentPath.clone();
  advanceIterator();
}
 
Example 14
Source File: CompositeQuery.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Iterator<ResolutionState> innerStateIterator(AnswerPropagatorState parent, Set<ReasonerAtomicQuery> subGoals) {
    return Iterators.singletonIterator(getConjunctiveQuery().resolutionState(getSubstitution(), parent.getUnifier(), parent, subGoals));
}
 
Example 15
Source File: PseudoSelectorTreeImpl.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Iterator<Tree> childrenIterator() {
  return Iterators.singletonIterator(element);
}
 
Example 16
Source File: NamespaceTreeImpl.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Iterator<Tree> childrenIterator() {
	return Iterators.singletonIterator(identifier);
}
 
Example 17
Source File: Sequence.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public Iterator<LogicalOperator> iterator() {
    return Iterators.singletonIterator(stream.get(stream.size() - 1));
}
 
Example 18
Source File: QueryToKeyMatcher.java    From fdb-record-layer with Apache License 2.0 4 votes vote down vote up
@Nonnull
private Match matches(@Nonnull AndComponent query, @Nonnull KeyExpression key, @Nonnull MatchingMode matchingMode,
                      @Nullable FilterSatisfiedMask filterMask) {
    final List<QueryComponent> listOfQueries = query.getChildren();
    final Iterator<KeyExpression> keyChildIterator;
    final int keyChildSize = key.getColumnSize();
    if (key instanceof ThenKeyExpression) {
        List<KeyExpression> children = ((ThenKeyExpression)key).getChildren();
        keyChildIterator = children.iterator();
    } else {
        keyChildIterator = Iterators.singletonIterator(key);
    }

    // Keep a local mask so that if we can only partially fulfill queries we don't pollute the main
    // one with our state
    FilterSatisfiedMask localMask = FilterSatisfiedMask.of(query);
    localMask.setExpression(key);
    List<Comparison> comparisons = new ArrayList<>(keyChildSize);
    while (keyChildIterator.hasNext()) {
        KeyExpression exp = keyChildIterator.next();

        // Look for a query segment that matches this expression
        boolean found = false;
        boolean foundInequality = false;
        final Iterator<FilterSatisfiedMask> childMaskIterator = localMask.getChildren().iterator();
        for (QueryComponent querySegment : listOfQueries) {
            Match match = matches(querySegment, exp, matchingMode, childMaskIterator.next());
            if (match.getType() != MatchType.NO_MATCH) {
                found = true;
                comparisons.addAll(match.getComparisons());
                if (match.getType() == MatchType.INEQUALITY) {
                    foundInequality = true;
                }
                break;
            }
        }

        if (!found) {
            return Match.none();
        }

        // Only the last comparison in the list can be inequality.
        if (localMask.allSatisfied() || foundInequality) {
            break;
        }
    }

    if (matchingMode.equals(MatchingMode.SATISFY_QUERY) && !localMask.allSatisfied()
            || matchingMode.equals(MatchingMode.COVER_KEY) && comparisons.size() < keyChildSize) {
        // Either we do not have enough comparisons to have covered the full key, or there are some
        // filters that have not yet been satisfied.
        return Match.none();
    }

    if (filterMask != null) {
        filterMask.mergeWith(localMask);
    }
    return new Match(comparisons);
}
 
Example 19
Source File: WhereOptimizer.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public Iterator<Expression> visitEnter(IsNullExpression node) {
    return Iterators.singletonIterator(node.getChildren().get(0));
}
 
Example 20
Source File: ScssParentSelectorTreeImpl.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Iterator<Tree> childrenIterator() {
  return Iterators.singletonIterator(parentSelector);
}