Example usage for android.util SparseArray size

List of usage examples for android.util SparseArray size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of key-value mappings that this SparseArray currently stores.

Usage

From source file:Main.java

public static SparseArray<Float> compartmentsMaxValues(SparseArray<ArrayList<Float>> compartments) {
    SparseArray<Float> maxValues = new SparseArray<>();
    for (int i = 0; i < compartments.size(); i++) {
        maxValues.put(i, Collections.max(compartments.get(i)));
    }/*from w  ww . j  av  a 2  s. c  om*/
    return maxValues;
}

From source file:Main.java

/**
 * Converts the sparse array into {@link java.util.List}.
 *
 * @param array sparse array of some type
 * @param <T> type of object in sparse array
 * @return list of object of specific type
 *//*from  www .j a va 2s. com*/
public static <T> List<T> sparseArrayAsList(final SparseArray<T> array) {
    final List<T> values = new ArrayList<>();

    for (int i = 0; i < array.size(); i++) {
        final int key = array.keyAt(i);

        values.add(array.get(key));
    }

    return values;
}

From source file:Main.java

/**
 * Returns a string composed from a {@link SparseArray}.
 *//*from   w w  w .  j av  a  2  s. c  o  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

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

/**
 * Returns a string composed from a {@link SparseArray}.
 *///from w  w  w  .  ja  va 2s.  c  om
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:br.ufrgs.ufrgsmapas.network.ExtraInfoParser.java

public static void fillBuildings(SparseArray<BuildingVo> mTempBuilding) {

    if (mTempBuilding == null || mTempBuilding.size() == 0) {
        if (DebugUtils.DEBUG)
            Log.e(TAG, "No list to fillBuildings() populate");
        return;/*w w  w.j a v a  2s. c o  m*/
    }

    BuildingVo buildingVo;
    for (int i = 0; i < mTempBuilding.size(); i++) {
        buildingVo = mTempBuilding.valueAt(i);
        fillBuildingInformation(buildingVo);
    }
}

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  w w.j av  a  2 s .  c o m
    }
    return list.toArray(new String[list.size()]);
}

From source file:Main.java

public static String mergeUri(String uri, Object[] args, SparseArray<String> paramKeys,
        Map<String, String> methodStaticUri, Map<String, String> globalParamKeys) {

    if (paramKeys != null && paramKeys.size() > 0 && args != null && args.length > 0) {
        for (int i = 0, key = paramKeys.keyAt(i); i < paramKeys.size(); key = paramKeys.keyAt(++i)) {
            uri = uri.replaceFirst(":" + paramKeys.get(key), String.valueOf(args[key]));
        }/*www  . j a v  a2 s .  c o m*/
    }
    if (methodStaticUri != null && methodStaticUri.size() > 0) {
        for (Map.Entry<String, String> e : methodStaticUri.entrySet()) {
            uri = uri.replaceFirst(":" + e.getKey(), e.getValue());
        }
    }
    if (globalParamKeys != null && globalParamKeys.size() > 0) {
        for (Map.Entry<String, String> e : globalParamKeys.entrySet()) {
            uri = uri.replaceFirst(":" + e.getKey(), e.getValue());
        }
    }

    return uri;
}

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 .  java2  s  .  c  o m*/
    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;
}