コード例 #1
0
  private List<User> updateInterpretationUsers(
      List<Interpretation> interpretations, List<InterpretationComment> comments) {
    Map<String, User> users = new HashMap<>();
    UserAccount currentUserAccount = mUserAccountService.getCurrentUserAccount();
    User currentUser = mUserStore.queryByUid(currentUserAccount.getUId());
    if (currentUser == null) {
      currentUser = mUserAccountService.toUser(currentUserAccount);
    }

    users.put(currentUser.getUId(), currentUser);

    if (interpretations != null && !interpretations.isEmpty()) {
      for (Interpretation interpretation : interpretations) {
        User user = interpretation.getUser();
        if (users.containsKey(user.getUId())) {
          user = users.get(user.getUId());
          interpretation.setUser(user);
        } else {
          users.put(user.getUId(), user);
        }
      }
    }

    if (comments != null && !comments.isEmpty()) {
      for (InterpretationComment comment : comments) {
        User user = comment.getUser();
        if (users.containsKey(user.getUId())) {
          user = users.get(user.getUId());
          comment.setUser(user);
        } else {
          users.put(user.getUId(), user);
        }
      }
    }

    return new ArrayList<>(users.values());
  }