001    /**
002     * CombineQueryAndCasesMethod.java
003     * jCOLIBRI2 framework. 
004     * @author Juan A. Recio-García.
005     * GAIA - Group for Artificial Intelligence Applications
006     * http://gaia.fdi.ucm.es
007     * 05/01/2007
008     */
009    package jcolibri.method.reuse;
010    
011    
012    import java.util.*;
013    import jcolibri.cbrcore.*;
014    import static jcolibri.util.CopyUtils.*;
015    /**
016     * Method to combine the description of a query with the other components of a case: solution, result and justification of solution.
017     * @author Juan A. Recio-Garcia
018     * @version 2.0
019     */
020    public class CombineQueryAndCasesMethod {
021    
022            /**
023             * Combienes some cases with a query. 
024             * This method creates a new copy for each case and overwrites their description with the description of the query.
025             */
026            public static Collection<CBRCase> combine(CBRQuery query, Collection<CBRCase> cases)
027            {
028                    ArrayList<CBRCase> res = new ArrayList<CBRCase>();
029                    
030                    for(CBRCase orig: cases)
031                    {
032                            try {
033                                    CBRCase copy = orig.getClass().newInstance();
034                                    
035                                    copy.setDescription(copyCaseComponent(query.getDescription()));
036                                    copy.setSolution(copyCaseComponent(orig.getSolution()));
037                                    copy.setJustificationOfSolution(copyCaseComponent(orig.getJustificationOfSolution()));
038                                    copy.setResult(copyCaseComponent(orig.getResult()));
039                                    
040                                    res.add(copy);
041                                    
042                                    
043                            } catch (Exception e) {
044                                    org.apache.commons.logging.LogFactory.getLog(CombineQueryAndCasesMethod.class).error("Error combining cases and query", e);
045                            } 
046                    }       
047                    return res;
048            }
049    }