Example usage for android.util SparseArray SparseArray

List of usage examples for android.util SparseArray SparseArray

Introduction

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

Prototype

public SparseArray() 

Source Link

Document

Creates a new SparseArray containing no mappings.

Usage

From source file:Main.java

private static double getTheoreticalStudent(int n) {
    SparseArray<Double> theorStudent = new SparseArray<Double>();
    theorStudent.put(10, 2.2281389);/*from   www .j av a  2  s .  com*/
    theorStudent.put(20, 2.0859634);
    theorStudent.put(30, 2.0422725);
    theorStudent.put(40, 2.0210754);
    theorStudent.put(50, 2.0085591);
    theorStudent.put(60, 2.0002978);
    theorStudent.put(70, 1.9944371);
    if (n >= 70)
        return theorStudent.get(70);
    else if (n >= 60)
        return theorStudent.get(60);
    else if (n >= 50)
        return theorStudent.get(50);
    else if (n >= 40)
        return theorStudent.get(40);
    else if (n >= 30)
        return theorStudent.get(30);
    else if (n >= 20)
        return theorStudent.get(20);
    else if (n >= 10)
        return theorStudent.get(10);
    else
        return theorStudent.get(10);
}

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  ww w  .ja v a 2 s .c om*/
    return maxValues;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T extends View> T get(View view, int id) {
    SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
    if (viewHolder == null) {
        viewHolder = new SparseArray<View>();
        view.setTag(viewHolder);/*from  www . ja va2s.c o m*/
    }
    View childView = viewHolder.get(id);
    if (childView == null) {
        childView = view.findViewById(id);
        viewHolder.put(id, childView);
    }
    return (T) childView;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T extends View> T obtainView(View convertView, int id) {
    SparseArray<View> holder = (SparseArray<View>) convertView.getTag();
    if (holder == null) {
        holder = new SparseArray<View>();
        convertView.setTag(holder);//from   w  w  w  .  java  2s  .c  o  m
    }
    View childView = holder.get(id);
    if (childView == null) {
        childView = convertView.findViewById(id);
        holder.put(id, childView);
    }
    return (T) childView;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T extends View> T getViewByHolder(View view, int id) {
    SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
    if (viewHolder == null) {
        viewHolder = new SparseArray<View>();
        view.setTag(viewHolder);/* w w w. j a va  2  s.  com*/
    }
    View childView = viewHolder.get(id);
    if (childView == null) {
        childView = view.findViewById(id);
        viewHolder.put(id, childView);
    }
    return (T) childView;
}

From source file:Main.java

public static <T extends View> T hold(View view, int id) {
    SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();

    if (viewHolder == null) {
        viewHolder = new SparseArray<View>();
        view.setTag(viewHolder);//from  www .ja v a2 s .c o m
    }

    View childView = viewHolder.get(id);

    if (childView == null) {
        childView = view.findViewById(id);
        viewHolder.put(id, childView);
    }

    return (T) childView;
}

From source file:Main.java

public static <E> SparseArray<E> newSparseArray() {
    return new SparseArray<E>();
}

From source file:Main.java

public static <T> void addInArray(SparseArray<SparseArray<T>> array, int firstKey, int secondKey, T value) {
    if (array == null)
        return;/* w  ww . j a v  a 2  s  .  c  o  m*/

    SparseArray<T> ts = array.get(firstKey);
    if (ts == null) {
        ts = new SparseArray<T>();

        synchronized (array) {
            array.put(firstKey, ts);
        }
    }

    synchronized (array) {
        ts.put(secondKey, value);
    }
}

From source file:Main.java

/**
 * Compare two dumps and get a list of all indices where
 * they differ from each other./*from   ww  w  .  j a  v  a  2 s. com*/
 * @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

/**
 * @return theoretical fishers table// w ww  .  ja  v a2 s  .  com
 * table realized by SparseArray, in connection with better performance than HashMap
 */
private static Double getTheoreticalFisher(int n) {
    SparseArray<Double> theorFisher = new SparseArray<Double>();
    theorFisher.put(1, 12.706);
    theorFisher.put(2, 4.3027);
    theorFisher.put(3, 3.1825);
    theorFisher.put(4, 2.7764);
    theorFisher.put(5, 2.5706);
    theorFisher.put(6, 2.4469);
    theorFisher.put(7, 2.3646);
    theorFisher.put(8, 2.3060);
    theorFisher.put(9, 2.2622);
    theorFisher.put(10, 2.2281);
    theorFisher.put(11, 2.2010);
    theorFisher.put(12, 2.1788);
    theorFisher.put(13, 2.1604);
    theorFisher.put(14, 2.1448);
    theorFisher.put(15, 2.1315);
    theorFisher.put(16, 2.1199);
    theorFisher.put(17, 2.1098);
    theorFisher.put(18, 2.1009);
    theorFisher.put(19, 2.0930);
    theorFisher.put(20, 2.0860);
    theorFisher.put(30, 2.0423);
    theorFisher.put(40, 2.0211);
    theorFisher.put(60, 2.0003);
    if (n >= 60) {
        return theorFisher.get(60);
    } else if (n >= 40) {
        return theorFisher.get(40);
    } else if (n >= 30) {
        return theorFisher.get(30);
    } else if (n >= 20) {
        return theorFisher.get(20);
    } else {
        return theorFisher.get(n);
    }
}