• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.res.android;
2 
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.Comparator;
6 import java.util.List;
7 
8 // roughly transliterated from system/core/libutils/include/utils/SortedVector.h and
9 // system/core/libutils/VectorImpl.cpp
10 public class SortedVector<T extends Comparable<T>> {
11 
12   // internal storage for the data. Re-sorted on insertion
13   private List<T> mStorage;
14 
SortedVector(int itemSize)15   SortedVector(int itemSize) {
16     mStorage = new ArrayList<>(itemSize);
17   }
18 
SortedVector()19   SortedVector() {
20     mStorage = new ArrayList<>();
21   }
22 
add(T info)23   public void add(T info) {
24     mStorage.add(info);
25     Collections.sort(mStorage, new Comparator<T>() {
26       @Override
27       public int compare(T t, T t1) {
28         return t.compareTo(t1);
29       }
30     });
31   }
32 
size()33   public int size() {
34     return mStorage.size();
35 
36   }
37 
itemAt(int contIdx)38   public T itemAt(int contIdx) {
39     return mStorage.get(contIdx);
40   }
41 
indexOf(T tmpInfo)42   public int indexOf(T tmpInfo) {
43     return mStorage.indexOf(tmpInfo);
44   }
45 
removeAt(int matchIdx)46   public void removeAt(int matchIdx) {
47     mStorage.remove(matchIdx);
48   }
49 }
50