Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. public static List<User> getPayers(String bid) {
  2. List<User> users = new ArrayList<>();
  3.  
  4. //asynchronously retrieve all documents
  5. ApiFuture<QuerySnapshot> future = db.collection("debts").document(bid).collection("payees").get();
  6. // future.get() blocks on response
  7. List<QueryDocumentSnapshot> documents = null;
  8. try {
  9. documents = future.get().getDocuments();
  10. } catch (InterruptedException e) {
  11. e.printStackTrace();
  12. } catch (ExecutionException e) {
  13. e.printStackTrace();
  14. }
  15. for (QueryDocumentSnapshot document : documents) {
  16. System.out.println(document.getId() + "\n");
  17. User u = new User(document.getId(), document.get("name").toString());
  18. users.add(u);
  19. }
  20.  
  21. return users;
  22. }
  23.  
  24. public static int getNumPayers(String bid) {
  25. return getPayers(bid).size();
  26. }
  27.  
  28. public static List<String> getAllBids(String myUid) {
  29. List<String> bids = new ArrayList<>();
  30.  
  31. //asynchronously retrieve all documents
  32. ApiFuture<QuerySnapshot> future = db.collection("debts").get();
  33. // future.get() blocks on response
  34. List<QueryDocumentSnapshot> documents = null;
  35. try {
  36. documents = future.get().getDocuments();
  37. } catch (InterruptedException e) {
  38. e.printStackTrace();
  39. } catch (ExecutionException e) {
  40. e.printStackTrace();
  41. }
  42.  
  43. for (QueryDocumentSnapshot document : documents) {
  44. if (document.get("uid").toString().equals(myUid)) {
  45. System.out.println(document.getId() + "\n");
  46. bids.add(document.getId());
  47. }
  48. }
  49.  
  50. return bids;
  51. }
  52.  
  53. public static List<User> getAllPayers(String myUid) {
  54. List<String> bids = getAllBids(myUid);
  55. List<User> users = new ArrayList<>();
  56. for (String s: bids) {
  57. users.addAll(getPayers(s));
  58. }
  59.  
  60. return users;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement