All Downloads are FREE. Search and download functionalities are using the official Maven repository.

solid.converters.ToSparseArray Maven / Gradle / Ivy

Go to download

Solid is an Android library, which provides lightweight data streams and immutable+parcelable collections.

There is a newer version: 1.0.14
Show newest version
package solid.converters;

import android.util.SparseArray;

import solid.functions.SolidFunc1;

public class ToSparseArray implements SolidFunc1, SparseArray> {

    public static  ToSparseArray toSparseArray(SolidFunc1 itemToKey, int initialCapacity) {
        return new ToSparseArray<>(itemToKey, initialCapacity);
    }

    public static  ToSparseArray toSparseArray(SolidFunc1 itemToKey) {
        return new ToSparseArray<>(itemToKey);
    }

    private SolidFunc1 getItemKey;
    private int initialCapacity;

    public ToSparseArray(SolidFunc1 itemToKey) {
        this(itemToKey, 10);
    }

    public ToSparseArray(SolidFunc1 itemToKey, int initialCapacity) {
        this.getItemKey = itemToKey;
        this.initialCapacity = initialCapacity;
    }

    @Override
    public SparseArray call(Iterable iterable) {
        SparseArray array = new SparseArray<>(initialCapacity);
        for (T value : iterable)
            array.put(getItemKey.call(value), value);
        return array;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy