Example usage for android.util SparseArray valueAt

List of usage examples for android.util SparseArray valueAt

Introduction

In this page you can find the example usage for android.util SparseArray valueAt.

Prototype

@SuppressWarnings("unchecked")
public E valueAt(int index) 

Source Link

Document

Given an index in the range 0...size()-1, returns the value from the indexth key-value mapping that this SparseArray stores.

Usage

From source file:Main.java

private static void print(SparseArray<String> strs) {
    for (int i = 0; i < strs.size(); i++) {
        Log.i("XJ", "key = " + strs.keyAt(i) + ",value = " + strs.valueAt(i));
    }/* ww w.ja va 2 s. co  m*/
}

From source file:Main.java

public static <C> List<C> asList(SparseArray<C> sparseArray) {
    if (sparseArray == null)
        return null;
    List<C> arrayList = new ArrayList<C>(sparseArray.size());
    for (int i = 0; i < sparseArray.size(); i++)
        arrayList.add(sparseArray.valueAt(i));
    return arrayList;
}

From source file:Main.java

public static <C> ArrayList<C> asArrayList(SparseArray<C> sparseArray) {
    if (sparseArray == null)
        return new ArrayList<C>();

    ArrayList<C> arrayList = new ArrayList<C>(sparseArray.size());
    for (int i = 0; i < sparseArray.size(); i++)
        arrayList.add(sparseArray.valueAt(i));
    return arrayList;
}

From source file:Main.java

public static <C> List<C> asArrayList(SparseArray<C> sparseArray) {
    if (sparseArray == null)
        return new ArrayList<C>();

    ArrayList<C> arrayList = new ArrayList<C>(sparseArray.size());
    for (int i = 0; i < sparseArray.size(); i++)
        arrayList.add(sparseArray.valueAt(i));
    return arrayList;
}

From source file:Main.java

public static <E> SparseArray<E> putAll(SparseArray<E> source, SparseArray<E> dest) {
    if (dest == null)
        dest = source;//w  w  w  .j a va  2  s . c  om
    else if (source != null)
        for (int i = 0; i < source.size(); i++) {
            int key = source.keyAt(i);
            E value = source.valueAt(i);
            dest.put(key, value);
        }
    return dest;
}

From source file:net.eledge.android.toolkit.StringArrayUtils.java

public static String[] toArray(SparseArray<List<String>> sparseArray) {
    List<String> list = new ArrayList<>();
    if ((sparseArray != null) && (sparseArray.size() > 0)) {
        for (int i = 0; i < sparseArray.size(); i++) {
            list.addAll(sparseArray.valueAt(i));
        }/* w  ww  .ja  v a2  s. c  om*/
    }
    return list.toArray(new String[list.size()]);
}

From source file:net.sf.sprockets.util.SparseArrays.java

/**
 * Get the values of the SparseArray.//from  w w  w. j av  a2s  . c o m
 */
public static <E> List<E> values(SparseArray<E> array) {
    int size = array.size();
    List<E> vals = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        vals.add(array.valueAt(i));
    }
    return vals;
}

From source file:Main.java

/**
 * Compare two dumps and get a list of all indices where
 * they differ from each other./* w  ww . ja  v a2s.  c  om*/
 * @param dump1 The first dump. The sector number is key and the
 * string array represents the blocks.
 * @param dump2 The second dump. The sector number is key and the
 * string array represents the blocks.
 * @return Indices where the two dumps differ. The key represents
 * the sector number. The first dimension of the value represents the
 * block number and the second is a list of indices where dump2 is
 * different from dump1. If the value is Integer[0][0] then the sector
 * exists only in dump1. If the value is Integer[1][0] then the sector
 * exists only in dump2.
 */
public static SparseArray<Integer[][]> diffIndices(SparseArray<String[]> dump1, SparseArray<String[]> dump2) {
    SparseArray<Integer[][]> ret = new SparseArray<Integer[][]>();
    // Walk through all sectors of dump1.
    for (int i = 0; i < dump1.size(); i++) {
        String[] sector1 = dump1.valueAt(i);
        int sectorNr = dump1.keyAt(i);
        String[] sector2 = dump2.get(sectorNr);

        // Check if dump2 has the current sector of dump1.
        if (sector2 == null) {
            ret.put(sectorNr, new Integer[0][0]);
            continue;
        }

        // Check the blocks.
        Integer[][] diffSector = new Integer[sector1.length][];
        // Walk through all blocks.
        for (int j = 0; j < sector1.length; j++) {
            ArrayList<Integer> diffIndices = new ArrayList<Integer>();
            // Walk through all symbols.
            for (int k = 0; k < sector1[j].length(); k++) {
                if (sector1[j].charAt(k) != sector2[j].charAt(k)) {
                    // Found different symbol at index k.
                    diffIndices.add(k);
                }
            }
            if (diffIndices.size() == 0) {
                // Block was identical.
                diffSector[j] = new Integer[0];
            } else {
                diffSector[j] = diffIndices.toArray(new Integer[diffIndices.size()]);
            }
        }
        ret.put(sectorNr, diffSector);
    }

    // Are there sectors that occur only in dump2?
    for (int i = 0; i < dump2.size(); i++) {
        int sectorNr = dump2.keyAt(i);
        if (dump1.get(sectorNr) == null) {
            // Sector only exists in dump2.
            ret.put(sectorNr, new Integer[1][0]);
        }
    }

    return ret;
}

From source file:Main.java

/**
 * Returns a string composed from a {@link SparseArray}.
 *///from   w  w w . j  a va 2  s .  co m
public static String toString(SparseArray<byte[]> array) {
    if (array == null) {
        return "null";
    }
    if (array.size() == 0) {
        return "{}";
    }
    StringBuilder buffer = new StringBuilder();
    buffer.append('{');
    for (int i = 0; i < array.size(); ++i) {
        buffer.append(array.keyAt(i)).append("=").append(Arrays.toString(array.valueAt(i)));
    }
    buffer.append('}');
    return buffer.toString();
}

From source file:Main.java

/**
 * Returns a string composed from a {@link SparseArray}.
 *///from  w w  w . j a  v  a 2 s .  c o  m
static String toString(SparseArray<byte[]> array) {
    if (array == null) {
        return "null";
    }
    if (array.size() == 0) {
        return "{}";
    }
    StringBuilder buffer = new StringBuilder();
    buffer.append('{');
    for (int i = 0; i < array.size(); ++i) {
        buffer.append(array.keyAt(i)).append("=").append(Arrays.toString(array.valueAt(i)));
    }
    buffer.append('}');
    return buffer.toString();
}