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.trimou.engine.interpolation.BracketDotKeySplitter.java

@Override
public Iterator<String> split(final String key) {

    if (key.equals(Strings.DOT)) {
        return Iterators.singletonIterator(Strings.DOT);
    }//  w  w  w  .  java 2 s.  c  om
    if (key.equals(Strings.THIS)) {
        return Iterators.singletonIterator(Strings.THIS);
    }

    boolean stringLiteral = false;
    boolean separator = false;
    List<String> parts = new ArrayList<String>();
    StringBuilder buffer = new StringBuilder();

    for (int i = 0; i < key.length(); i++) {
        if (isSeparator(key.charAt(i))) {
            // Only process the first separator - adjacent separators are
            // ignored
            if (!separator) {
                if (!stringLiteral) {
                    if (buffer.length() > 0) {
                        parts.add(buffer.toString());
                        buffer = new StringBuilder();
                    }
                    separator = true;
                } else {
                    buffer.append(key.charAt(i));
                }
            }
        } else {
            // Non-separator char
            if (Strings.isStringLiteralSeparator(key.charAt(i))) {
                stringLiteral = !stringLiteral;
            } else {
                buffer.append(key.charAt(i));
            }
            separator = false;
        }
    }

    if (buffer.length() > 0) {
        parts.add(buffer.toString());
    }
    return parts.iterator();
}

From source file:com.google.devtools.build.lib.collect.nestedset.SingleDirectNestedSet.java

@Override
public Iterator<E> iterator() {
    return Iterators.singletonIterator(e);
}

From source file:jhc.redsniff.internal.core.Item.java

@Override
public Iterator<E> iterator() {
    return Iterators.singletonIterator(item);
}

From source file:org.sonar.gherkin.tree.impl.AbstractPrefixTreeImpl.java

@Override
public Iterator<Tree> childrenIterator() {
    return Iterators.singletonIterator(keyword);
}

From source file:org.eclipse.xtext.common.types.access.impl.InnerClassNameVariants.java

public Iterator<String> variantsFor(final String base) {
    //if (1==1) return Lists.newArrayList(base).iterator();
    // System.out.println("xxxxxx yyyy " + base);
    int[] positionsOfDollar = getPositionsOfDollar(base);
    if (positionsOfDollar.length == 0) {
        return Iterators.singletonIterator(base);
    }/*from ww  w . j  av a  2 s .  c  o m*/

    int numberPositionsOfDollar = positionsOfDollar.length;
    int numberOfCombinations = (int) Math.pow(2, numberPositionsOfDollar);
    /*
     * turns the given value to a int[] binary representation
     * 
     * 0 -> [0,0,0] 1 -> [1,0,0 7 -> [1,1,1]
     */
    IntFunction<int[]> shouldElementAtPositionBeReplaced = new IntFunction<int[]>() {

        @Override
        public int[] apply(final int value) {
            int[] shouldElementBeReplaced = new int[numberPositionsOfDollar];
            int valueCopy = value;

            for (int c = 0; c < shouldElementBeReplaced.length; c++) {
                if (valueCopy % 2 == 1) {
                    shouldElementBeReplaced[c] = 1;
                }
                valueCopy = valueCopy / 2;
            }
            return shouldElementBeReplaced;
        }
    };
    /*
     * takes the given positon array to decide if a positon shall be
     * replaced or not [0,1,0] => replace the second occurrence of '$' only
     */
    Function<int[], String> replaceAtPositions = new Function<int[], String>() {

        @Override
        public String apply(int[] shouldElementBeReplaced) {
            StringBuilder baseAsBuilder = new StringBuilder(base);

            for (int position = 0; position < shouldElementBeReplaced.length; position++) {
                int p = shouldElementBeReplaced[position];
                if (p > 0) {
                    baseAsBuilder.setCharAt(positionsOfDollar[position], '.');
                }
            }

            return baseAsBuilder.toString();
        }
    };

    Stream<String> resultStream = IntStream.range(0, numberOfCombinations)
            .mapToObj(shouldElementAtPositionBeReplaced).map(replaceAtPositions);
    return resultStream.iterator();
}

From source file:com.synflow.models.util.dom.SimpleNamespaceContext.java

@Override
public Iterator<?> getPrefixes(String namespaceURI) {
    return Iterators.singletonIterator(getPrefix(namespaceURI));
}

From source file:org.sonar.json.tree.impl.LiteralTreeImpl.java

@Override
public Iterator<Tree> childrenIterator() {
    return Iterators.singletonIterator(value);
}

From source file:ninja.leaping.permissionsex.util.glob.UnitNode.java

@Override
public Iterator<String> iterator() {
    return Iterators.singletonIterator(value);
}

From source file:io.crate.core.collections.SingleRowBucket.java

@Override
public Iterator<Row> iterator() {
    return Iterators.singletonIterator(row);
}

From source file:org.eclipse.incquery.runtime.localsearch.operations.extend.ExtendConstant.java

@Override
public void onInitialize(MatchingFrame frame, ISearchContext context) throws LocalSearchException {
    it = Iterators.singletonIterator(value);
}