Example usage for com.google.common.collect Iterators singletonIterator

List of usage examples for com.google.common.collect Iterators singletonIterator

Introduction

In this page you can find the example usage for com.google.common.collect Iterators singletonIterator.

Prototype

public static <T> UnmodifiableIterator<T> singletonIterator(@Nullable final T value) 

Source Link

Document

Returns an iterator containing only value .

Usage

From source file:org.sonar.pickbasic.tree.impl.statement.DoRepeatClauseTreeImpl.java

@Override
public Iterator<Tree> childrenIterator() {
    return Iterators.concat(Iterators.singletonIterator(doKeyword), statements.iterator(),
            Iterators.singletonIterator(repeatKeyword));
}

From source file:org.eclipse.viatra.query.runtime.localsearch.operations.extend.ExtendToEStructuralFeatureTarget.java

@SuppressWarnings("unchecked")
@Override/*from   w  w  w. java2  s.  c om*/
public void onInitialize(MatchingFrame frame, ISearchContext context) throws LocalSearchException {
    try {
        final EObject value = (EObject) frame.getValue(sourcePosition);
        if (!feature.getEContainingClass().isSuperTypeOf(value.eClass())) {
            // TODO planner should ensure the proper supertype relation
            it = Iterators.emptyIterator();
            return;
        }
        final Object featureValue = value.eGet(feature);
        if (feature.isMany()) {
            if (featureValue != null) {
                final Collection<Object> objectCollection = (Collection<Object>) featureValue;
                it = objectCollection.iterator();
            } else {
                it = Iterators.emptyIterator();
            }
        } else {
            if (featureValue != null) {
                it = Iterators.singletonIterator(featureValue);
            } else {
                it = Iterators.emptyIterator();
            }
        }
    } catch (ClassCastException e) {
        throw new LocalSearchException("Invalid feature source in parameter" + Integer.toString(sourcePosition),
                e);
    }
}

From source file:org.sonar.php.tree.impl.expression.ArrayInitializerFunctionTreeImpl.java

@Override
public Iterator<Tree> childrenIterator() {
    return Iterators.concat(Iterators.singletonIterator(arrayToken),
            Iterators.singletonIterator(openParenthesis), arrayPairs.elementsAndSeparators(),
            Iterators.singletonIterator(closeParenthesis));
}

From source file:com.google.devtools.build.lib.remote.Chunker.java

Chunker(Item input, int chunkSize) throws IOException {
    this(Iterators.singletonIterator(input), chunkSize, ImmutableSet.of(input.getDigest()));
}

From source file:nz.ac.massey.cs.guery.impl.BreadthFirstPathFinder.java

private Iterator<Path<V, E>> findDirectLinks(final GraphAdapter<V, E> g, V start, int minLength,
        boolean outgoing, Predicate<E> filter, boolean computeAll) {
    Iterator<Path<V, E>> nullIter = null;
    if (minLength == 0) {
        Path<V, E> path = new LREmptyPath(start);
        nullIter = (Iterator<Path<V, E>>) Iterators.singletonIterator(path);
    }// w w w  .  ja v  a 2 s .  c om
    Iterator<E> edges = outgoing ? g.getOutEdges(start, filter) : g.getInEdges(start, filter);
    Iterator<Path<V, E>> paths = Iterators.transform(edges, new Function<E, Path<V, E>>() {
        @Override
        public Path<V, E> apply(E e) {
            return new SingletonPath<V, E>(e, g);
        }
    });

    return nullIter == null ? paths : Iterators.concat(nullIter, paths);

}

From source file:com.wrmsr.wava.core.type.Signature.java

@Override
public Iterator<Type> iterator() {
    return Iterators.concat(Iterators.singletonIterator(result), arguments.iterator());
}

From source file:org.sonar.pickbasic.tree.impl.statement.EquStatementTreeImpl.java

@Override
public Iterator<Tree> childrenIterator() {
    return Iterators.concat(Iterators.forArray(equKeyword, expression), toClauses.iterator(),
            Iterators.singletonIterator(semicolonToken));
}

From source file:org.elasticsearch.search.aggregations.support.bytes.ScriptBytesValues.java

@Override
public int setDocument(int docId) {
    this.docId = docId;
    script.setNextDocId(docId);//from   ww w .ja  v a 2  s .  c  o m
    value = script.run();

    if (value == null) {
        iter = Iterators.emptyIterator();
        return 0;
    }

    if (value.getClass().isArray()) {
        final int length = Array.getLength(value);
        // don't use Arrays.asList because the array may be an array of primitives?
        iter = new Iterator<Object>() {

            int i = 0;

            @Override
            public boolean hasNext() {
                return i < length;
            }

            @Override
            public Object next() {
                return Array.get(value, i++);
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }

        };
        return length;
    }

    if (value instanceof Collection) {
        final Collection<?> coll = (Collection<?>) value;
        iter = coll.iterator();
        return coll.size();
    }

    iter = Iterators.singletonIterator(value);
    return 1;
}

From source file:org.sonar.javascript.tree.impl.declaration.ParameterListTreeImpl.java

@Override
public Iterator<Tree> childrenIterator() {
    return Iterators.concat(Iterators.singletonIterator(openParenthesis),
            parameters.elementsAndSeparators(Functions.<Tree>identity()),
            Iterators.singletonIterator(closeParenthesis));
}

From source file:org.sonar.pickbasic.tree.impl.statement.BeginCaseStatementTreeImpl.java

@Override
public Iterator<Tree> childrenIterator() {
    return Iterators.concat(Iterators.singletonIterator(beginCaseKeyword), beginCaseCases.iterator(),
            Iterators.forArray(endCaseKeyword, semicolonToken));
}