Package instance

Source Code of instance.DocumentProcessor

package instance;

import java.util.List;
import java.util.concurrent.*;

import list.ComparisonTable;
import list.Document;

public class DocumentProcessor implements Callable< String >
{
   private String filename;
  
   public static void process( List< String > filenames )
   {
      int documentCount = Options.getDocuments( ).size( );
     
      Executor pool = Executors.newFixedThreadPool( documentCount < Options.getMaxThreads( )
                                                      ?
                                                    documentCount : Options.getMaxThreads( ) );
     
      CompletionService< String > completion = new ExecutorCompletionService< String >( pool );
     
      for( String filename : Options.getDocuments( ) )
      {
         completion.submit( new DocumentProcessor( filename ) );
      }
     
      for( int i = 0; i < documentCount; ++i )
      {
         try
         {
            System.out.println( "\n\n" + completion.take( ).get( ) );
         }
         catch( Exception e ) { }
      }
     
      ( (ThreadPoolExecutor)pool ).shutdown( );
   }
  
   public DocumentProcessor( String filename )
   {
      this.filename = filename;
   }

   @Override
   public String call( )
   {
      Document doc = new Document( filename );
     
      return ( "Results for document \"" + filename + "\":\n\n"
               + ComparisonTable.getTable( doc.getExistingList( ),
                                           doc.getNewList( ) )
               + "\n"
               + doc.toString( ) );
   }
}
TOP

Related Classes of instance.DocumentProcessor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.