Example usage for java.lang Iterable Iterable

List of usage examples for java.lang Iterable Iterable

Introduction

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

Prototype

Iterable

Source Link

Usage

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

/**
 * @param labeled/*www.  j  a  v a 2  s .com*/
 * @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.github.tomakehurst.wiremock.http.HttpHeadersJsonDeserializer.java

public static <T> Iterable<T> all(final Iterator<T> underlyingIterator) {
    return new Iterable<T>() {
        public Iterator<T> iterator() {
            return underlyingIterator;
        }//from ww w .j  a v  a2s. com
    };
}

From source file:org.nuxeo.connect.tools.report.viewer.ThreadDumpPrinter.java

public Iterable<ThreadInfo> iterableOf() {
    return new Iterable<ThreadInfo>() {

        @Override/* w w w  .  ja  v a2 s.  co m*/
        public Iterator<ThreadInfo> iterator() {
            try {
                return iteratorOf();
            } catch (IOException cause) {
                throw new AssertionError("Cannot parse thread dump", cause);
            }
        }

    };
}

From source file:com.thoughtworks.studios.journey.utils.IterableUtils.java

public static <T> Iterable<T> uniqueBy(final Function<T, Object> function, final Iterable<T> iterable) {
    return new Iterable<T>() {
        @Override/*from  w  w  w .  j  a  va2s  .  co  m*/
        public Iterator<T> iterator() {
            final Iterator<T> iterator = iterable.iterator();

            return new Iterator<T>() {
                Set<Object> keys = new HashSet<>();
                T nextItem;

                @Override
                public boolean hasNext() {
                    while (iterator.hasNext()) {
                        nextItem = iterator.next();
                        if (keys.add(function.apply(nextItem))) {
                            return true;
                        }
                    }

                    return false;
                }

                @Override
                public T next() {
                    if (nextItem == null && !hasNext()) {
                        throw new NoSuchElementException();
                    }

                    return nextItem;
                }

                @Override
                public void remove() {
                }
            };
        }
    };
}

From source file:com.texeltek.accumulocloudbaseshim.FormatterShim.java

@Override
@SuppressWarnings("unchecked")
public void initialize(final Iterable<Map.Entry<Key, Value>> scanner, boolean printTimestamps) {
    impl.initialize(new Iterable<Map.Entry<cloudbase.core.data.Key, cloudbase.core.data.Value>>() {
        @Override//w  ww .  j av a2  s. c  o m
        public Iterator<Map.Entry<cloudbase.core.data.Key, cloudbase.core.data.Value>> iterator() {
            return IteratorUtils.transformedIterator(scanner.iterator(), new Transformer() {
                @Override
                public Map.Entry<cloudbase.core.data.Key, cloudbase.core.data.Value> transform(Object input) {
                    Map.Entry<Key, Value> entry = (Map.Entry<Key, Value>) input;
                    return new AbstractMap.SimpleEntry<cloudbase.core.data.Key, cloudbase.core.data.Value>(
                            entry.getKey().impl, entry.getValue().impl);
                }
            });
        }
    }, printTimestamps);
}

From source file:com.bitranger.parknshop.common.recommend.vectors.similarity.Vectors.java

public static Iterable<Pair<VectorEntry, VectorEntry>> fastIntersect(final List<Long> v1, final List<Long> v2) {
    return new Iterable<Pair<VectorEntry, VectorEntry>>() {
        @Override/*  ww  w .j av  a 2  s . c  om*/
        public Iterator<Pair<VectorEntry, VectorEntry>> iterator() {
            return new FastIntersectIterImpl(v1, v2);
        }
    };
}

From source file:com.iorga.iraj.security.HttpServletRequestToSign.java

@Override
public Iterable<String> getHeaderNames() {
    return new Iterable<String>() {
        @SuppressWarnings("unchecked")
        @Override//www .  j  a v a 2  s  .  co m
        public Iterator<String> iterator() {
            return new EnumerationIterator(httpServletRequest.getHeaderNames());
        }
    };
}

From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.common.PropertiesSetListingQueryFullTableScan.java

public Iterable<GenericEntityPropertyRecord> getEntityPropertyGenericValues(final LongSet entityIDs) {
    return new Iterable<GenericEntityPropertyRecord>() {
        public Iterator<GenericEntityPropertyRecord> iterator() {
            return new FilterIterator<GenericEntityPropertyRecord>(query.getEntityPropertyGenericValues(),
                    new Predicate<BaseEntityPropertyRecord>() {
                        public boolean evaluate(BaseEntityPropertyRecord baseSample) {
                            return entityIDs.contains(baseSample.entity_id);
                        }//from w  w  w . j  av  a 2  s  . c o m
                    });
        }
    };
}

From source file:org.omnaest.utils.structure.iterator.IterableUtils.java

/**
 * Returns a new {@link Iterable} instance which uses an {@link Iterator} adapter based on the resolved
 * {@link Iterable#iterator()} instance. <br>
 * <br>//from w ww .  j ava 2  s  .c  om
 * The elements will be converted at traversal time not in advance.
 * 
 * @param iterable
 *          {@link Iterable}
 * @param elementConverter
 *          {@link ElementConverter}
 * @return new instance
 */
public static <FROM, TO> Iterable<TO> adapter(final Iterable<? extends FROM> iterable,
        final ElementConverter<FROM, TO> elementConverter) {
    return new Iterable<TO>() {
        @Override
        public Iterator<TO> iterator() {
            return IteratorUtils.adapter(iterable.iterator(), elementConverter);
        }
    };
}

From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.SampleSetListingQueryFullTableScan.java

public Iterable<SampleRecord> getSamples(final LongSet sampleIds) {
    return new Iterable<SampleRecord>() {
        public Iterator<SampleRecord> iterator() {
            return new FilterIterator<SampleRecord>(query.getSamples(databaseInstanceId),
                    new Predicate<SampleRecord>() {
                        public boolean evaluate(SampleRecord sample) {
                            return sampleIds.contains(sample.id);
                        }/*from   w w w.  j  a va 2  s . co  m*/
                    });
        }
    };
}