Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jcouchdb.document;
 
 import java.util.List;
 import java.util.Map;
 
Merges the objects of a ViewAndDocumentsResult where they have a

Author(s):
shelmberger
public class ResultAssembler
    private AssemblingStrategy strategy;
    public ResultAssembler()
    {
        this(new PropertyPathAssemblingStrategy());
    }
    public ResultAssembler(AssemblingStrategy strategy)
    {
        this. = strategy;
    }
    
    
    public void setDocumentPropertyHandler(DocumentPropertyHandler documentPropertyHandler)
    {
        this. = documentPropertyHandler;
    }
    
    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)
                {                
                    .assemble(mainrow);
                }
            }
            return new ArrayList<D>( id2main.values());
        }
        catch (Exception e)
        {
            throw new CouchDBException(e);
        }
    }
    
    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 = .getId(document);
            if (row.getId().equalsid))
            {
                map.put(idrow.getDocument());
            }
        }
        
        return map ;
    }
    
New to GrepCode? Check out our FAQ X