001    package calhoun.analysis.crf.io;
002    
003    import java.io.IOException;
004    import java.util.List;
005    
006    /** an output handler that allows multiple output handlers to be configured.  Each result is handed to each 
007     * output handler in the list.
008     */
009    public class OutputHandlerComposite implements OutputHandler {
010            private static final long serialVersionUID = 7923868199821973396L;
011    
012            List<OutputHandler> handlers;
013            
014            public void setOutputLocation(String location) {
015                    for(OutputHandler handler : handlers) {
016                            handler.setOutputLocation(location);
017                    }
018            }
019            
020            public void writeOutput(InputSequence<?> sequence, int[] hiddenStates) throws IOException {
021                    for(OutputHandler handler : handlers) {
022                            handler.writeOutput(sequence, hiddenStates);
023                    }
024            }
025    
026            public void writeTestOutput(InputSequence<?> sequence, int[] truePath, int[] hiddenStates) throws IOException {
027                    for(OutputHandler handler : handlers) {
028                            handler.writeTestOutput(sequence, truePath, hiddenStates);
029                    }
030            }
031    
032            public void outputComplete() throws IOException {
033                    for(OutputHandler handler : handlers) {
034                            handler.outputComplete();
035                    }
036            }
037    
038            /** retursn the configured list of output handler.
039             * @return returns the output handlers
040             */
041            public List<OutputHandler> getHandlers() {
042                    return handlers;
043            }
044    
045            /** sets the list of output handlers 
046             * @param handlers a list of output handlers.  The output handlers will be called in order for each prediction or test result.
047             */
048            public void setHandlers(List<OutputHandler> handlers) {
049                    this.handlers = handlers;
050            }
051    }