List of usage examples for android.util SparseArray size
public int size()
From source file:Main.java
public static <T> void deleteInArray(SparseArray<SparseArray<T>> array, int firstKey, int secondKey) { if (array == null) return;/*from www.ja va 2s.c om*/ SparseArray<T> ts = array.get(firstKey); if (ts == null) return; synchronized (array) { ts.delete(secondKey); if (ts.size() == 0) { array.delete(firstKey); } } }
From source file:net.sf.sprockets.util.SparseArrays.java
/** * Get the values of the SparseArray./* ww w .ja va 2s.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:net.sf.sprockets.util.SparseArrays.java
/** * Get the keys of the SparseArray.//from w w w . j a va 2s. c o m */ public static int[] keys(SparseArray<?> array) { int[] keys = new int[array.size()]; for (int i = 0; i < keys.length; i++) { keys[i] = array.keyAt(i); } return keys; }
From source file:Main.java
/** * Check whether two {@link SparseArray} equal. */// ww w .j av a2 s. c o m static boolean equals(SparseArray<byte[]> array, SparseArray<byte[]> otherArray) { if (array == otherArray) { return true; } if (array == null || otherArray == null) { return false; } if (array.size() != otherArray.size()) { return false; } // Keys are guaranteed in ascending order when indices are in ascending order. for (int i = 0; i < array.size(); ++i) { if (array.keyAt(i) != otherArray.keyAt(i) || !Arrays.equals(array.valueAt(i), otherArray.valueAt(i))) { return false; } } return true; }
From source file:android.support.v7.content.res.AppCompatResources.java
@Nullable private static ColorStateList getCachedColorStateList(@NonNull Context context, @ColorRes int resId) { synchronized (sColorStateCacheLock) { final SparseArray<ColorStateListCacheEntry> entries = sColorStateCaches.get(context); if (entries != null && entries.size() > 0) { final ColorStateListCacheEntry entry = entries.get(resId); if (entry != null) { if (entry.configuration.equals(context.getResources().getConfiguration())) { // If the current configuration matches the entry's, we can use it return entry.value; } else { // Otherwise we'll remove the entry entries.remove(resId); }//from www.ja v a 2 s. co m } } } return null; }
From source file:Main.java
/** * Check whether two {@link SparseArray} equal. *///from ww w.j av a 2s . c om public static boolean equals(SparseArray<byte[]> array, SparseArray<byte[]> otherArray) { if (array == otherArray) { return true; } if (array == null || otherArray == null) { return false; } if (array.size() != otherArray.size()) { return false; } // Keys are guaranteed in ascending order when indices are in ascending order. for (int i = 0; i < array.size(); ++i) { if (array.keyAt(i) != otherArray.keyAt(i) || !Arrays.equals(array.valueAt(i), otherArray.valueAt(i))) { return false; } } return true; }
From source file:edu.umich.eecs.rtcl.lp_doctor.utilities.MathTools.java
private static double getPValue(SparseArray<Double> mobility, SparseArray<Integer> appHistogram, int currentPlace) { double[] expected = new double[mobility.size()]; long[] observed = new long[mobility.size()]; long[] toBeObserved = new long[mobility.size()]; //nothing there, for bootstrapping if (mobility.size() < 2) { return 1; }/*w ww. j av a 2s . c o m*/ for (int index = 0; index < mobility.size(); index++) { int placeID = mobility.keyAt(index); double probability = mobility.get(placeID); int numVisits = appHistogram.get(placeID, 0);// no visits if place not in histogram expected[index] = probability; observed[index] = numVisits; toBeObserved[index] = numVisits; if (placeID == currentPlace) { toBeObserved[index]++; //to be observed? } Util.Log(Util.SESSION_TAG, "place:\t" + placeID + "\texp:\t" + probability + "\tobs:\t" + numVisits); } double pValueOld = new ChiSquareTest().chiSquareTest(expected, observed); double pValueNew = new ChiSquareTest().chiSquareTest(expected, toBeObserved); //automatic normalization Util.Log(Util.SESSION_TAG, pValueOld + "\t" + Arrays.toString(expected) + "\t" + Arrays.toString(observed)); Util.Log(Util.SESSION_TAG, pValueNew + "\t" + Arrays.toString(expected) + "\t" + Arrays.toString(observed)); return pValueNew; }
From source file:Main.java
/** * Compare two dumps and get a list of all indices where * they differ from each other./*from w w w . j ava2 s . 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:edu.umich.eecs.rtcl.lp_doctor.utilities.MathTools.java
public static boolean isDistanceIncreased(SparseArray<Double> mobility, SparseArray<Integer> appHistogram, int currentPlace) { double[] expected = new double[mobility.size()]; long[] observed = new long[mobility.size()]; long[] toBeObserved = new long[mobility.size()]; //we need the total number of visits int totalVisits = 0; for (int index = 0; index < mobility.size(); index++) { int placeID = mobility.keyAt(index); double probability = mobility.get(placeID); int numVisits = appHistogram.get(placeID, 0);// no visits if place not in histogram expected[index] = probability;/* w w w .j a v a 2s . com*/ observed[index] = numVisits; toBeObserved[index] = numVisits; if (placeID == currentPlace) { toBeObserved[index]++; //to be observed? } totalVisits += numVisits; // num visits is per place Id in mobility pattern } if (totalVisits == 0) { //no location access recorded, information leak is inevitable from location leak return false; } double KLValueOld = 0; double KLValueNew = 0; //what happens if totalVisits is 0? //also, what happens id the obsPr is 0? for (int i = 0; i < expected.length; i++) { double expPr = expected[i]; //larger than 0 by definition double obsPr = totalVisits > 0 ? observed[i] * 1.0 / totalVisits : 0; double obsPrNew = toBeObserved[i] * 1.0 / (totalVisits + 1); KLValueOld += obsPr <= 1e-6 ? 0 : obsPr * Math.log(obsPr / expPr); KLValueNew += obsPrNew <= 1e-6 ? 0 : obsPrNew * Math.log(obsPrNew / expPr); Util.Log(Util.SESSION_TAG, "exp:\t" + expPr + "\tobs:\t" + obsPr + "temp:\t" + (obsPr <= 1e-6 ? 0 : obsPr * Math.log(obsPr / expPr))); } //Util.Log(Util.SESSION_TAG,KLValueOld+"\t"+expected+"\t"+observed); //Util.Log(Util.SESSION_TAG,KLValueNew+"\t"+expected+"\t"+toBeObserved); return KLValueNew > KLValueOld; }
From source file:com.appsimobile.appsii.AbstractSidebarPagerAdapter.java
static <T> int keyOf(SparseArray<T> array, T object) { int length = array.size(); for (int i = 0; i < length; i++) { T value = array.valueAt(i);//w w w .j a v a2s . c o m if (value == object) return array.keyAt(i); } return -1; }