edu.wpi.prc.example.java.science
Class ScienceDataProcessor

java.lang.Object
  extended by edu.wpi.prc.example.java.science.ScienceDataProcessor

public class ScienceDataProcessor
extends java.lang.Object

The ScienceDataProcessor contains all of the project-specific methods required to compute the results for work units. This class is used by the ComputeThread.

Author:
James Baldassari

Field Summary
private static int CHECKPOINT_INTERVAL
           
private  byte[] workUnitData
           
 
Constructor Summary
ScienceDataProcessor(byte[] workUnitData)
          Constructor that takes a byte array representing the work unit data to be processed.
 
Method Summary
 byte[] computeResult()
          This method checks for previously saved checkpoints, then runs the science algorithm, findPrimes().
private  java.util.ArrayList<java.lang.Integer> findPrimes(int start, int end)
          This method is the science algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHECKPOINT_INTERVAL

private static final int CHECKPOINT_INTERVAL
See Also:
Constant Field Values

workUnitData

private byte[] workUnitData
Constructor Detail

ScienceDataProcessor

public ScienceDataProcessor(byte[] workUnitData)
Constructor that takes a byte array representing the work unit data to be processed.

Parameters:
workUnitData - The work unit data.
Method Detail

computeResult

public byte[] computeResult()
This method checks for previously saved checkpoints, then runs the science algorithm, findPrimes(). It then collects all of the primes that were found and produces a byte array representing them, which is the result that will be returned to the server.

Returns:
Returns a byte array representing the computed result.

findPrimes

private java.util.ArrayList<java.lang.Integer> findPrimes(int start,
                                                          int end)
This method is the science algorithm. It finds all prime numbers in the given interval.

Parameters:
start - The start of the interval (inclusive) in which to search.
end - The end of the interval (inclusive) in which to search.
Returns:
Returns an array of all primes that were found, or an array of length zero if no primes were found.