Example usage for java.lang Iterable iterator

List of usage examples for java.lang Iterable iterator

Introduction

In this page you can find the example usage for java.lang Iterable iterator.

Prototype

Iterator<T> iterator();

Source Link

Document

Returns an iterator over elements of type T .

Usage

From source file:com.oltpbenchmark.util.CollectionUtil.java

/**
 * Put all of the values of an Iterable into a new Set
 * @param <T>//from   w  w  w.jav  a2 s  .  com
 * @param it
 * @return
 */
public static <T> Set<T> set(Iterable<T> it) {
    return (set(it.iterator()));
}

From source file:com.oltpbenchmark.util.CollectionUtil.java

/**
 * Put all of the values of an Iterable into a new List
 * @param <T>/*  ww w .  jav a  2 s .c  o m*/
 * @param it
 * @return
 */
public static <T> List<T> list(Iterable<T> it) {
    return (list(it.iterator()));
}

From source file:li.l1t.common.util.CommandHelper.java

/**
 * Comma separates a Collection's children's String representations.
 *
 * @param input      An Iterable to separate
 * @param defaultVal value to be returned if {@code col} is empty.
 * @return Element1, Element2, Element3 OR {@code defaultVal}
 * @deprecated This method's name does not respect Java naming conventions, and what it does can be achieved in a
 * cleaner way using Streams and {@link Collectors#joining()}.
 *///from w  w w . j  a  va2 s.c  om
public static String CSCollection(Iterable<?> input, String defaultVal) {
    if (input == null) {
        return "~~~null~~~";
    }

    Iterator<?> i = input.iterator();
    if (!i.hasNext()) {
        return defaultVal;
    }
    final StringBuilder rtrnBuilder = new StringBuilder(String.valueOf(i.next()));
    while (i.hasNext()) {
        rtrnBuilder.append(", ").append(i.next());
    }
    return rtrnBuilder.toString();
}

From source file:edu.byu.nlp.util.Iterables2.java

/**
 * @param labeled//  ww w. j av a 2s  . co m
 * @param unlabeled
 * @return
 */
public static <F, S> Iterable<Pair<F, S>> pairUp(final Iterable<? extends F> first,
        final Iterable<? extends S> second) {
    return new Iterable<Pair<F, S>>() {
        @Override
        public Iterator<Pair<F, S>> iterator() {
            return new Iterator<Pair<F, S>>() {

                private final Iterator<? extends F> firstIt = first.iterator();
                private final Iterator<? extends S> secondIt = second.iterator();

                @Override
                public boolean hasNext() {
                    return firstIt.hasNext() && secondIt.hasNext();
                }

                @Override
                public Pair<F, S> next() {
                    return Pair.<F, S>of(firstIt.next(), secondIt.next());
                }

                @Override
                public void remove() {
                    firstIt.remove();
                    secondIt.remove();
                }
            };
        }
    };
}

From source file:com.cloud.utils.StringUtils.java

public static String join(final Iterable<? extends Object> iterable, final String delim) {
    final StringBuilder sb = new StringBuilder();
    if (iterable != null) {
        final Iterator<? extends Object> iter = iterable.iterator();
        if (iter.hasNext()) {
            final Object next = iter.next();
            sb.append(next.toString());/*w w w. ja va 2 s.  c  o m*/
        }
        while (iter.hasNext()) {
            final Object next = iter.next();
            sb.append(delim + next.toString());
        }
    }
    return sb.toString();
}

From source file:com.siemens.sw360.datahandler.common.CommonUtils.java

public static <T> T getFirst(Iterable<T> iterable) {
    final Iterator<T> iterator = iterable.iterator();
    if (iterator.hasNext()) {
        return iterator.next();
    } else {//from   w w w  . j  a va2 s .c o m
        throw new NoSuchElementException();
    }
}

From source file:com.oltpbenchmark.util.CollectionUtil.java

/**
 * Add all of the items from the Iterable into the given collection
 * @param <T>// w  ww  . ja v a2  s. co m
 * @param data
 * @param items
 */
public static <T> Collection<T> addAll(Collection<T> data, Iterable<T> items) {
    return (CollectionUtil.addAll(data, items.iterator()));
}

From source file:com.wrmsr.wava.analyze.ValueTypeAnalysis.java

private static ImMap<Name, Set<Type>> mergeBreakValueTypes(Iterable<ImMap<Name, Set<Type>>> items) {
    return mergeBreakValueTypes(items.iterator());
}

From source file:fresto.datastore.titan.TitanEventWriter.java

public static void linkToGUUID(TitanGraph g, Vertex v, String uuid) {

    Iterable<Vertex> vertices = g.getVertices("guuid", uuid);
    Vertex guuidVertex = null;//from   w w w . j  a  v  a2  s  .co m
    if (vertices.iterator().hasNext()) {
        guuidVertex = vertices.iterator().next();
    } else {
        guuidVertex = g.addVertex(null);
        guuidVertex.setProperty("guuid", uuid);
        //LOGGER.info("GUUID[" + uuid + "] created.");
    }
    guuidVertex.addEdge("flow", v).setProperty("event", v.getProperty("event"));
}

From source file:de.ifgi.fmt.utils.Utils.java

/**
 * /*from  w  ww  .  ja  v  a2 s  .  com*/
 * @param s
 * @param sep
 * @param col
 * @return
 */
public static String join(Stringifier s, String sep, Iterable<? extends Object> col) {
    Iterator<? extends Object> i;
    if (col == null || (!(i = col.iterator()).hasNext()))
        return "";
    if (s == null)
        s = DEFAULT_STRINGIFIER;
    StringBuilder sb = new StringBuilder(s.toString(i.next()));
    while (i.hasNext())
        sb.append(sep).append(s.toString(i.next()));
    return sb.toString();
}