solid.collectors.ToSolidList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of collections Show documentation
Show all versions of collections Show documentation
Solid is an Android library, which provides lightweight data streams and immutable+parcelable collections.
package solid.collectors;
import java.util.ArrayList;
import java.util.List;
import solid.collections.SolidList;
import solid.functions.Func1;
public class ToSolidList {
private static final Func1 TO_SOLID_LIST = toSolidList(0);
/**
* Returns a method that can be used with {@link solid.stream.Stream#collect(Func1)}
* to convert a stream into a {@link ArrayList}.
*
* @param a type of {@link ArrayList} items.
* @return a method that converts an iterable into {@link ArrayList}.
*/
public static Func1, SolidList> toSolidList() {
return TO_SOLID_LIST;
}
/**
* Returns a method that can be used with {@link solid.stream.Stream#collect(Func1)}
* to convert a stream into a {@link List}.
*
* Use this method instead of {@link #toSolidList()} for better performance on
* streams that can have more than 12 items.
*
* @param a type of {@link List} items.
* @param initialCapacity initial capacity of the list.
* @return a method that converts an iterable into {@link List}.
*/
public static Func1, SolidList> toSolidList(final int initialCapacity) {
return new Func1, SolidList>() {
@Override
public SolidList call(Iterable iterable) {
ArrayList list = new ArrayList<>(initialCapacity);
for (T value : iterable)
list.add(value);
return new SolidList<>(list);
}
};
}
}