private <T> List<T> select(Collection<T> items, Predicate<T> predicate) {
   ArrayList<T> selectedItems = new ArrayList<T>();
   for (T item : items) {
     if (predicate.apply(item)) {
       selectedItems.add(item);
     }
   }
   return selectedItems;
 }
Esempio n. 2
0
 private static View findChild(View root, Predicate<View> predicate) {
   if (predicate.apply(root)) {
     return root;
   }
   if (root instanceof ViewGroup) {
     ViewGroup viewGroup = (ViewGroup) root;
     for (int i = 0; i < viewGroup.getChildCount(); i++) {
       View child = viewGroup.getChildAt(i);
       View result = findChild(child, predicate);
       if (result != null) {
         return result;
       }
     }
   }
   return null;
 }
Esempio n. 3
0
  public List<SMSMessage> readSMS(Predicate<SMSMessage> filter, long since) {
    Cursor cursor = getSMSInboxCursor();

    List<SMSMessage> smsList = new ArrayList<>();

    if (cursor.moveToFirst()) { // must check the result to prevent exception
      do {
        if (cursor.getLong(cursor.getColumnIndex("date")) < since) break;
        // String msgData = "";
        SMSMessage message = mapCursor(cursor);

        if (filter.apply(message)) smsList.add(message);

      } while (cursor.moveToNext());
    } else {
      // empty box, no SMS
    }
    return smsList;
  }
Esempio n. 4
0
    @Override
    protected List<PrimaryBankService.BankDetail> doInBackground(Long... params) {
      Cursor cursor = provider.getSMSInboxCursor();
      Long since = params[0];
      int maxCount = cursor.getCount();
      List<PrimaryBankService.BankDetail> bankDetailList = new ArrayList<>();
      Map<String, Integer> bankCount = new HashMap<>();
      if (cursor.moveToFirst()) { // must check the result to prevent exception
        int index = 1;
        do {
          publishProgress(
              String.format(
                  "Processing inbox %d/%d. Found %d.", index, maxCount, bankDetailList.size()));

          if (cursor.getLong(cursor.getColumnIndex("date")) < since) break;
          // String msgData = "";
          SMSMessage message = provider.mapCursor(cursor);

          if (filter.apply(message)) {
            PrimaryBankService.BankDetail bankDetail = new PrimaryBankService.BankDetail();
            bankDetail.setAccountNumber(provider.getAccountNumber(message));
            bankDetail.setBankName(provider.getBankName(message));
            if (!bankDetailList.contains(bankDetail)) bankDetailList.add(bankDetail);
            if (!bankCount.containsKey(bankDetail.getAccountNumberLast4Digits()))
              bankCount.put(bankDetail.getAccountNumberLast4Digits(), 0);
            int newCount = bankCount.get(bankDetail.getAccountNumberLast4Digits()) + 1;
            bankCount.put(bankDetail.getAccountNumberLast4Digits(), newCount);
          }

          index++;

        } while (cursor.moveToNext());
      } else {
        publishProgress(String.format("Inbox Empty"));
      }
      return bankDetailList;
    }