Example usage for com.google.common.collect UnmodifiableIterator hasNext

List of usage examples for com.google.common.collect UnmodifiableIterator hasNext

Introduction

In this page you can find the example usage for com.google.common.collect UnmodifiableIterator hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true if the iteration has more elements.

Usage

From source file:org.eclipse.ease.ui.metadata.MenuMetadataParser.java

public static List<String> getMenus(String toParse) {
    String[] separators = toParse.split(SEPARATOR);
    UnmodifiableIterator<String> ite = Iterators.forArray(separators);
    ArrayList<String> menu = new ArrayList<String>();
    while (ite.hasNext()) {
        String m = (String) ite.next();
        menu.add(m.trim());// ww w.  j av  a  2 s .  co m
    }
    return menu;
}

From source file:org.eclipse.ease.ui.metadata.AvailableFromMetadataParser.java

public static List<String> getTargets(String toParse) {
    String[] separators = toParse.split(SEPARATOR);
    UnmodifiableIterator<String> ite = Iterators.forArray(separators);
    ArrayList<String> menu = new ArrayList<String>();
    while (ite.hasNext()) {
        String m = (String) ite.next();
        menu.add(m.trim());//from  w  w  w . j  a v  a  2  s  .  c  om
    }
    return menu;
}

From source file:com.spectralogic.ds3client.helpers.RangeHelper.java

static void addRemainingRanges(final UnmodifiableIterator<Range> existingRangesIterator,
        final ImmutableList.Builder<Range> newRangesbuilder) {
    while (existingRangesIterator.hasNext()) {
        newRangesbuilder.add(existingRangesIterator.next());
    }/*from   w  w  w .j  a v a2 s  .  c o m*/
}

From source file:com.spectralogic.ds3client.helpers.strategy.transferstrategy.RangeHelper.java

private static void addRemainingRanges(final UnmodifiableIterator<Range> existingRangesIterator,
        final ImmutableList.Builder<Range> newRangesbuilder) {
    while (existingRangesIterator.hasNext()) {
        newRangesbuilder.add(existingRangesIterator.next());
    }//w w w .  j  av  a2 s.co m
}

From source file:broadwick.graph.writer.GraphMl.java

/**
 * Get the string representation of the network.
 * @param network  the network object to be written.
 * @param directed a boolean flag, true if the network is directed.
 * @return a string representing a document.
 *//*from  w w  w.j a  va 2  s .  c  om*/
public static String toString(final Graph<? extends Vertex, ? extends Edge<?>> network,
        final boolean directed) {
    // graphml document header
    final Element graphml = new Element("graphml", "http://graphml.graphdrawing.org/xmlns");
    final Document document = new Document(graphml);
    final Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    final Namespace schemLocation = Namespace.getNamespace("schemLocation",
            "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0rc/graphml.xsd");

    // add Namespace
    graphml.addNamespaceDeclaration(xsi);
    graphml.addNamespaceDeclaration(schemLocation);

    // keys for graphic representation
    for (VertexAttribute attr : network.getVertexAttributes()) {
        final Element element = new Element("key");
        element.setAttribute("id", attr.getName());
        element.setAttribute("for", "node");
        element.setAttribute("attr.name", attr.getName());
        element.setAttribute("attr.type", attr.getType().getName());
        if (attr.getDefaultValue() != null) {
            final Element defaultValueElement = new Element("default");
            defaultValueElement.addContent(attr.getDefaultValue().toString());
            element.addContent(defaultValueElement);
        }
        graphml.addContent(element);
    }

    for (EdgeAttribute attr : network.getEdgeAttributes()) {
        final Element element = new Element("key");
        element.setAttribute("id", attr.getName());
        element.setAttribute("for", "edge");
        element.setAttribute("attr.name", attr.getName());
        element.setAttribute("attr.type", attr.getType().getName());
        if (attr.getDefaultValue() != null) {
            final Element defaultValueElement = new Element("default");
            defaultValueElement.addContent(attr.getDefaultValue());
            element.addContent(defaultValueElement);
        }
        graphml.addContent(element);
    }

    final Element graph = new Element("graph");
    graph.setAttribute("id", "G");
    if (directed) {
        graph.setAttribute("edgedefault", "directed");
    } else {
        graph.setAttribute("edgedefault", "undirected");
    }
    graphml.addContent(graph);

    final ImmutableList<Vertex> vertices = ImmutableList.copyOf(network.getVertices());
    final Iterator<Vertex> vertexIterator = vertices.iterator();
    while (vertexIterator.hasNext()) {
        final Vertex vertex = vertexIterator.next();
        addNode(vertex, graph);
    }

    final ImmutableList<Edge<? extends Vertex>> edges;
    edges = (ImmutableList<Edge<? extends Vertex>>) ImmutableList.copyOf(network.getEdges());
    final UnmodifiableIterator<Edge<? extends Vertex>> edgeIterator = edges.iterator();
    while (edgeIterator.hasNext()) {
        addEdge(edgeIterator.next(), graph);
    }

    final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    return outputter.outputString(document).replaceAll("xmlns=\"\" ", "");
}

From source file:org.thiesen.ant.git.GitInfoExtractor.java

private static CustomTag getLastRevTag(final Repository r) throws IOException {

    // Iterate all tags, beginning with the joungest.
    // The first match that is reachable from HEAD is the one we are looking for
    final ImmutableSortedSet<CustomTag> sortedTags = getTagsSortedByCommitTime(r);
    final RevWalk walk = new RevWalk(r);
    walk.setRetainBody(false);/*from ww w . j  av a 2 s.c om*/

    final RevCommit head = getHead(r);

    CustomTag tag = null;
    boolean isReachable = false;
    UnmodifiableIterator<CustomTag> iterator = sortedTags.iterator();
    while (!isReachable && iterator.hasNext()) {
        tag = iterator.next();
        RevCommit tagCommit = walk.parseCommit(tag.getObjectId());
        isReachable = walk.isMergedInto(tagCommit, head) || head.compareTo(tagCommit) == 0;
        walk.reset();
    }
    walk.dispose();
    return isReachable ? tag : null;
}

From source file:com.spectralogic.ds3client.helpers.RangeHelper.java

static ImmutableCollection<Range> replaceRange(final ImmutableCollection<Range> existingRanges,
        final long numBytesTransferred, final long intendedNumBytesToTransfer) {
    Preconditions.checkState(numBytesTransferred >= 0, "numBytesTransferred must be >= 0.");
    Preconditions.checkState(intendedNumBytesToTransfer > 0, "intendedNumBytesToTransfer must be > 0.");
    Preconditions.checkState(intendedNumBytesToTransfer > numBytesTransferred,
            "intendedNumBytesToTransfer must be > numBytesTransferred");

    if (Guard.isNullOrEmpty(existingRanges)) {
        return ImmutableList
                .of(Range.byLength(numBytesTransferred, intendedNumBytesToTransfer - numBytesTransferred));
    }/*w  w w  .ja v  a2 s.  c  om*/

    final ImmutableList.Builder<Range> newRangesbuilder = ImmutableList.builder();

    final UnmodifiableIterator<Range> existingRangesIterator = existingRanges.iterator();

    long previousAccumulatedBytesInRanges = 0;
    long currentAccumulatedBytesInRanges = existingRanges.iterator().next().getLength();

    while (existingRangesIterator.hasNext()) {
        final Range existingRange = existingRangesIterator.next();

        if (numBytesTransferred < currentAccumulatedBytesInRanges) {
            final Range firstNewRange = Range.byPosition(
                    existingRange.getStart() - previousAccumulatedBytesInRanges + numBytesTransferred,
                    existingRange.getEnd());
            newRangesbuilder.add(firstNewRange);

            addRemainingRanges(existingRangesIterator, newRangesbuilder);
            break;
        }

        previousAccumulatedBytesInRanges += existingRange.getLength();
        currentAccumulatedBytesInRanges += existingRange.getLength();
    }

    return newRangesbuilder.build();
}

From source file:com.spectralogic.ds3client.helpers.strategy.transferstrategy.RangeHelper.java

protected static ImmutableCollection<Range> replaceRange(final ImmutableCollection<Range> existingRanges,
        final long numBytesTransferred, final long intendedNumBytesToTransfer) {
    Preconditions.checkState(numBytesTransferred >= 0, "numBytesTransferred must be >= 0.");
    Preconditions.checkState(intendedNumBytesToTransfer > 0, "intendedNumBytesToTransfer must be > 0.");
    Preconditions.checkState(intendedNumBytesToTransfer > numBytesTransferred,
            "intendedNumBytesToTransfer must be > numBytesTransferred");

    if (Guard.isNullOrEmpty(existingRanges)) {
        return ImmutableList
                .of(Range.byLength(numBytesTransferred, intendedNumBytesToTransfer - numBytesTransferred));
    }/* w ww .  jav  a 2 s. c o m*/

    final ImmutableList.Builder<Range> newRangesbuilder = ImmutableList.builder();

    final UnmodifiableIterator<Range> existingRangesIterator = existingRanges.iterator();

    long previousAccumulatedBytesInRanges = 0;
    long currentAccumulatedBytesInRanges = existingRanges.iterator().next().getLength();

    while (existingRangesIterator.hasNext()) {
        final Range existingRange = existingRangesIterator.next();

        if (numBytesTransferred < currentAccumulatedBytesInRanges) {
            final Range firstNewRange = Range.byPosition(
                    existingRange.getStart() - previousAccumulatedBytesInRanges + numBytesTransferred,
                    existingRange.getEnd());
            newRangesbuilder.add(firstNewRange);

            addRemainingRanges(existingRangesIterator, newRangesbuilder);
            break;
        }

        previousAccumulatedBytesInRanges += existingRange.getLength();
        currentAccumulatedBytesInRanges += existingRange.getLength();
    }

    return newRangesbuilder.build();
}

From source file:org.elasticsearch.node.internal.InternalSettingsPreparer.java

static Settings replacePromptPlaceholders(Settings settings, Terminal terminal) {
    UnmodifiableIterator<Map.Entry<String, String>> iter = settings.getAsMap().entrySet().iterator();
    Settings.Builder builder = Settings.builder();

    while (iter.hasNext()) {
        Map.Entry<String, String> entry = iter.next();
        String value = entry.getValue();
        String key = entry.getKey();
        switch (value) {
        case SECRET_PROMPT_VALUE:
            String secretValue = promptForValue(key, terminal, true);
            if (Strings.hasLength(secretValue)) {
                builder.put(key, secretValue);
            }/* w w w  .j ava  2  s  . co m*/
            break;
        case TEXT_PROMPT_VALUE:
            String textValue = promptForValue(key, terminal, false);
            if (Strings.hasLength(textValue)) {
                builder.put(key, textValue);
            }
            break;
        default:
            builder.put(key, value);
            break;
        }
    }

    return builder.build();
}

From source file:com.lothrazar.cyclicmagic.util.UtilHarvester.java

private static PropertyBool getBoolProperty(IBlockState blockState, String property) {
    UnmodifiableIterator<Entry<IProperty<?>, Comparable<?>>> unmodifiableiterator = blockState.getProperties()
            .entrySet().iterator();//from  w  w  w . j a v  a  2s  .c o  m
    while (unmodifiableiterator.hasNext()) {
        //      Entry<IProperty<?>, Comparable<?>> entry = unmodifiableiterator.next();
        IProperty<?> iproperty = unmodifiableiterator.next().getKey();
        if (iproperty instanceof PropertyBool && iproperty.getName().equals(property)) {
            return (PropertyBool) iproperty;
        }
    }
    return null;
}