Example usage for com.google.common.collect AbstractIterable AbstractIterable

List of usage examples for com.google.common.collect AbstractIterable AbstractIterable

Introduction

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

Prototype

AbstractIterable

Source Link

Usage

From source file:com.proxiad.emfcustomizer.ecss.util.Iterables2.java

/**
 * Take a generic Iterable<T> and sort out all duplicates from this
 * Iterable<T>//from w ww.  j av a  2 s  . co m
 * 
 * @param <T>
 * @param input
 * @return un Iterable<T> gnrique en retirant les doublons
 */
public static <T> Iterable<T> unique(final Iterable<T> input) {

    Iterable<T> unique = new AbstractIterable<T>() {
        public Iterator<T> iterator() {
            final Set<T> set = new HashSet<T>();

            return Iterators.filter(input.iterator(), new Predicate<T>() {
                public boolean apply(T input) {
                    return set.add(input);
                }
            });
        }
    };
    return unique;
}