示例#1
0
  private <D> Map<String, D> findMainObjects(ViewAndDocumentsResult<? extends Object, D> result) {
    Map<String, D> map = new TreeMap<String, D>();

    for (ValueAndDocumentRow<? extends Object, D> row : result.getRows()) {
      D document = row.getDocument();
      String id = documentPropertyHandler.getId(document);
      if (row.getId().equals(id)) {
        map.put(id, row.getDocument());
      }
    }

    return map;
  }
示例#2
0
  public <D> List<D> assemble(ViewAndDocumentsResult<? extends Object, D> result) {
    try {
      Map<String, D> id2main = findMainObjects(result);

      for (ValueAndDocumentRow<? extends Object, D> row : result.getRows()) {
        D main = id2main.get(row.getId());
        D rowDoc = row.getDocument();
        if (rowDoc != main) {
          strategy.assemble(main, row);
        }
      }

      return new ArrayList<D>(id2main.values());
    } catch (Exception e) {
      throw new CouchDBException(e);
    }
  }