net.sf.staccatocommons.collections.iterable.internal.IterablesInternal Maven / Gradle / Ivy
/**
* Copyright (c) 2011, The Staccato-Commons Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
package net.sf.staccatocommons.collections.iterable.internal;
import java.util.Collection;
import java.util.Iterator;
import net.sf.staccatocommons.defs.Applicable;
import net.sf.staccatocommons.defs.Evaluable;
/**
* This class is not part of of the public API of collections-extra.
*
* @author fbulgarelli
*/
public class IterablesInternal {
/***/
public static final String ITERABLE = "iterable";
/***/
public static void addAllInternal(Collection collection, Iterable extends T> iterable) {
for (T element : iterable)
collection.add(element);
}
/***/
public static > C takeInternal(Iterable iterable, int amountOfElements,
C outputCollection) {
Iterator iter = iterable.iterator();
for (int i = 0; i < amountOfElements && iter.hasNext(); i++)
outputCollection.add(iter.next());
return outputCollection;
}
/***/
public static > C filterInternal(Iterable iterable, Evaluable super T> predicate,
C collection) {
for (T element : iterable)
if (predicate.eval(element))
collection.add(element);
return collection;
}
/***/
public static > C collectInternal(Iterable iterable,
Applicable super I, ? extends O> function, C outputCollection) {
for (I element : iterable)
outputCollection.add(function.apply(element));
return outputCollection;
}
/***/
public static boolean containsInternal(Iterable iterable, T element) {
for (T each : iterable)
if (each.equals(element))
return true;
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy