maia/.svn/pristine/1f/1ffef52e57692307a42f8ef454e...

77 lines
1.8 KiB
Plaintext
Executable File

package com.fp.persistence.commondb.helper;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.fp.common.helper.CalculationBase;
/**
* Enumeracion que almacena las distintas frecuencias de calculo de la aplicacion.
* @author Jorge Vaca.
* @version 2.1
*
*/
public enum Frequency {
DAYLY(1,1), WEEKLY(2,7), BIWEEKLY(3,15), MONTHLY(4,-1), BIMONTHLY(5,-2), TRIMONTHLY(6,-3),
SEMESTRAL(7,-6), ANNUAL(8,-12);
private int numDays;
private Integer code;
/**
* Crea una nueva frecuencia. El valor negativo -1 indica 1 mes, -2 indica 2 meses... Etc.
* @param pCode Código de frecuencia.
* @param pDays Días de la frecuencia.
*/
private Frequency(int pCode, int pDays) {
this.numDays = pDays;
this.code = pCode;
}
/**
* Entrega el Valor de numDays.
* @return numDays.
*/
public int getNumDays(Date pDate,SimpleDateFormat sdf) throws Exception {
int data = numDays;
if (data < 0) {
data = data * -1;
APPDates d = new APPDates(pDate,CalculationBase.B365365,sdf);
d.addField(Calendar.MONTH, data);
APPDates a = new APPDates(pDate,CalculationBase.B365365,sdf);
data = d.substract(a);
}
return data;
}
/**
* Entraga un objeto Frecuency dado el codigo de frecuencia.
* @param pCode Código de frecuencia.
* @return Frequency
* @throws Exception
*/
public static Frequency getFrecuency(Integer pCode) throws Exception{
Frequency [] bt = null;
bt = Frequency.values();
Frequency btype = null;
for(Frequency obj : bt){
if(obj.code.compareTo(pCode) == 0){
btype = obj;
}
}
return btype;
}
/**
* Entrega el valor de: code
* @return Integer
*/
public Integer getCode() {
return code;
}
}