com.ftlabs.fisa
Class DefaultCPIFactory

java.lang.Object
  extended by com.ftlabs.fisa.DefaultCPIFactory
All Implemented Interfaces:
CPIFactory, java.io.Serializable

public class DefaultCPIFactory
extends java.lang.Object
implements CPIFactory, java.io.Serializable

This is the default implementation of CPIFactory. For maximum efficiency, this implementation caches all provided values so that the getCPI() methods returns as quickly as possible.

See Also:
Serialized Form

Constructor Summary
DefaultCPIFactory()
          Creates a new instance of DefaultCPIFactory without any cpi values.
DefaultCPIFactory(java.io.InputStream inputStream)
          Creates a new instance of DefaultCPIFactory populated with dates and cpi values provided by an InputStream.
DefaultCPIFactory(java.io.InputStream inputStream, java.text.Format format, int earliestYear)
          Creates a new instance of DefaultCPIFactory populated with dates and cpi values provided by an InputStream.
DefaultCPIFactory(int earliestYear)
          Creates a new instance of DefaultCPIFactory without any cpi values.
DefaultCPIFactory(java.lang.String filePath)
          Creates a new instance of DefaultCPIFactory populated with data contained in the provided file setting 1900 to be the earliestYear.
DefaultCPIFactory(java.lang.String filePath, int earliestYear)
          Creates a new instance of DefaultCPIFactory populated with data contained in the provided file setting earliestYear as provided.
 
Method Summary
 void addCPIValue(java.util.Date date, double cpiValue)
          Add a CPI value for the provided date.
 void clear()
          Clear all CPI values.
 double getCPI(java.util.Date date)
          This method returns the CPI for the given Date.
 double getCPI(java.util.Date date, int monthOffset)
          This method returns the CPI for the given month offset from the given date.
 double getCPI(int year, int month)
          This method returns the CPI for the given year and month.
 double getCPI(int year, int month, int monthOffset)
          This method returns the CPI for the given month offset from year and month.
 double getIndexRatio(java.util.Date datedDate, java.util.Date settlementDate)
          Returns the index ratio for a given datedDate and settlementDate.
 void loadCPIValues(java.io.InputStream inputStream)
          Adds CPI data provided by an InputStream to this DefaultCPIFactory.
 void loadCPIValues(java.io.InputStream inputStream, java.text.Format format)
          Adds CPI data provided by an InputStream to this DefaultCPIFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCPIFactory

public DefaultCPIFactory()
Creates a new instance of DefaultCPIFactory without any cpi values. The earliestYear is set equal to 1900. The addCPI() method, or one of the loadCPIValues() methods must be called to populate the factory. Otherwise all calls to getCPI() will return 0.0.


DefaultCPIFactory

public DefaultCPIFactory(int earliestYear)
Creates a new instance of DefaultCPIFactory without any cpi values. The earliestYear is set to the provided parameter. The addCPI() method, or one of the loadCPIValues() methods must be called to populate the factory. Otherwise all calls to getCPI() will return 0.0.

Parameters:
earliestYear - The earliest year available from this CPIFactory.

DefaultCPIFactory

public DefaultCPIFactory(java.lang.String filePath)
                  throws java.io.IOException,
                         java.text.ParseException
Creates a new instance of DefaultCPIFactory populated with data contained in the provided file setting 1900 to be the earliestYear. The dates in the file must be parsable using a mask of "M/yyyy" to SimpleDateFormat. See loadCPIValues() for a full description of the required data format.

Parameters:
filePath - The path to a file that contains the holiday dates.
Throws:
java.io.IOException - Thrown when an IOException occurs.
java.text.ParseException - Thrown when the date is not parsable using a SimpleDateFormat object with a mask of "M/yyyy".
See Also:
loadCPIValues( InputStream inputStream, Format format )

DefaultCPIFactory

public DefaultCPIFactory(java.lang.String filePath,
                         int earliestYear)
                  throws java.io.IOException,
                         java.text.ParseException
Creates a new instance of DefaultCPIFactory populated with data contained in the provided file setting earliestYear as provided. The dates in the file must be parsable using a mask of "M/yyyy" to SimpleDateFormat. See loadCPIValues() for a full description of the required data format.

Parameters:
filePath - The path to a file that contains the holiday dates.
earliestYear - The earliest year available from this CPIFactory.
Throws:
java.io.IOException - Thrown when an IOException occurs.
java.text.ParseException - Thrown when the date is not parsable using a SimpleDateFormat object with a mask of "M/yyyy".
See Also:
loadCPIValues( InputStream inputStream, Format format )

DefaultCPIFactory

public DefaultCPIFactory(java.io.InputStream inputStream)
                  throws java.io.IOException,
                         java.text.ParseException
Creates a new instance of DefaultCPIFactory populated with dates and cpi values provided by an InputStream. The dates in the stream must be parsable using "M/yyyy" as a mask to SimpleDateFormat. earliestYear will be set to 1900. See loadCPIValues() for a full description of the required data format.

Parameters:
inputStream - An InputStream that contains the holiday dates.
Throws:
java.io.IOException - Thrown when an IOException occurs.
java.text.ParseException - Thrown when the date is not parsable using a SimpleDateFormat object with a mask of "M/yyyy".
See Also:
loadCPIValues( InputStream inputStream, Format format )

DefaultCPIFactory

public DefaultCPIFactory(java.io.InputStream inputStream,
                         java.text.Format format,
                         int earliestYear)
                  throws java.io.IOException,
                         java.text.ParseException
Creates a new instance of DefaultCPIFactory populated with dates and cpi values provided by an InputStream. The provided Format will be used to parse the date. See loadCPIValues() for a full description of the required data format.

Parameters:
inputStream - An InputStream that contains the CPI data.
format - A Format object used to parse the cpi dates contained within the provided InputStream.
earliestYear - The earliest year available from this CPIFactory.
Throws:
java.io.IOException - Thrown when an IOException occurs.
java.text.ParseException - Thrown when the date is not parsable using the given Format object.
See Also:
loadCPIValues( InputStream inputStream, Format format )
Method Detail

clear

public void clear()
Clear all CPI values.


loadCPIValues

public void loadCPIValues(java.io.InputStream inputStream)
                   throws java.io.IOException,
                          java.text.ParseException
Adds CPI data provided by an InputStream to this DefaultCPIFactory. This method calls the overloaded loadCPIValues method passing a new SimpleDateFormat( "M/yyyy" ) as the date format object. See loadCPIValues( InputStream inputStream, Format format ) for a complete description of the data format.

Parameters:
inputStream - An InputStream that contains the holiday dates.
Throws:
java.io.IOException - Thrown when an IOException occurs.
java.text.ParseException - Thrown when the date is not parsable using a SimpleDateFormat object with a mask of "M/yyyy".
java.lang.NumberFormatException - Thrown if a CPI value is not parsable as a double.
See Also:
loadCPIValues( InputStream inputStream, Format format )

loadCPIValues

public void loadCPIValues(java.io.InputStream inputStream,
                          java.text.Format format)
                   throws java.io.IOException,
                          java.text.ParseException
Adds CPI data provided by an InputStream to this DefaultCPIFactory.

The dates in the stream must be parsable using the provided Format object. The CPI values must be parsable as a double. Each date and value should be separated with either a tab or an equal sign with the date being the key. Each date/value pair should be delimited with a carriage return and/or a linefeed. The order of the date/value pairs doesn't matter, however if there is a duplicate date, the CPI value of the last occurrance will be the value returned for that date.

Example :

 03/2005 = 120.5
 04/2005 = 121.0
 05/2005 = 121.5
 

Parameters:
inputStream - An InputStream that contains the CPI data.
format - A Format object used to parse the CPI dates contained within the provided InputStream.
Throws:
java.io.IOException - Thrown when an IOException occurs.
java.text.ParseException - Thrown when the date is not parsable using the given Format object.
java.lang.NumberFormatException - Thrown if a CPI value is not parsable as a double.

addCPIValue

public void addCPIValue(java.util.Date date,
                        double cpiValue)
Add a CPI value for the provided date.

Parameters:
date - The CPI date.
cpiValue - The CPI value.

getCPI

public double getCPI(java.util.Date date)
This method returns the CPI for the given Date.

Specified by:
getCPI in interface CPIFactory
Parameters:
date - A Date
Returns:
CPI for the given Date.

getCPI

public double getCPI(java.util.Date date,
                     int monthOffset)
This method returns the CPI for the given month offset from the given date.

Specified by:
getCPI in interface CPIFactory
Parameters:
date - A date
monthOffset - number of months from the given month.
Returns:
CPI for the given offset from the given date.

getCPI

public double getCPI(int year,
                     int month)
This method returns the CPI for the given year and month.

Specified by:
getCPI in interface CPIFactory
Parameters:
year - The year
month - The month
Returns:
CPI for the given year and month.

getCPI

public double getCPI(int year,
                     int month,
                     int monthOffset)
This method returns the CPI for the given month offset from year and month.

Specified by:
getCPI in interface CPIFactory
Parameters:
year - The year
month - The month
monthOffset - Months from the given month.
Returns:
CPI for the given offset from year and month.

getIndexRatio

public double getIndexRatio(java.util.Date datedDate,
                            java.util.Date settlementDate)
Returns the index ratio for a given datedDate and settlementDate.

Specified by:
getIndexRatio in interface CPIFactory
Parameters:
datedDate - The datedDate of the Security.
settlementDate - The settlementDate for a given transaction.
Returns:
The index ratio for the given datedDate and settlementDate.