Example usage for org.joda.time ReadablePeriod getValue

List of usage examples for org.joda.time ReadablePeriod getValue

Introduction

In this page you can find the example usage for org.joda.time ReadablePeriod getValue.

Prototype

int getValue(int index);

Source Link

Document

Gets the value at the specified index.

Usage

From source file:com.mbc.jfin.schedule.impl.AbstractBaseScheduleGenerator.java

License:Open Source License

protected ReadablePeriod multiplyPeriod(ReadablePeriod frequency, int periodCount) throws ScheduleException {

    if (frequency instanceof Months) {
        return Months.months(frequency.getValue(0) * periodCount);
    } else if (frequency instanceof Days) {
        return Days.days(frequency.getValue(0) * periodCount);
    } else if (frequency instanceof Weeks) {
        return Weeks.weeks(frequency.getValue(0) * periodCount);
    } else if (frequency instanceof Years) {
        return Years.years(frequency.getValue(0) * periodCount);
    } else {//  w  ww  .j  av a  2s. c  o  m
        throw new ScheduleException("Unknown frequency type: " + frequency);
    }
}

From source file:net.sourceforge.fenixedu.util.HourMinuteSecond.java

License:Open Source License

/**
 * Gets a copy of this date with the specified period added.
 * <p>/*from www.j a va2s.  c o m*/
 * If the addition is zero, then <code>this</code> is returned. Fields in the period that aren't present in the partial are
 * ignored.
 * <p>
 * This method is typically used to add multiple copies of complex period instances. Adding one field is best achieved using
 * methods like {@link #withFieldAdded(DurationFieldType, int)} or {@link #plusHours(int)}.
 * 
 * @param period
 *            the period to add to this one, null means zero
 * @param scalar
 *            the amount of times to add, such as -1 to subtract once
 * @return a copy of this instance with the period added
 * @throws ArithmeticException
 *             if the new datetime exceeds the capacity
 */
public HourMinuteSecond withPeriodAdded(ReadablePeriod period, int scalar) {
    if (period == null || scalar == 0) {
        return this;
    }
    int[] newValues = getValues();
    for (int i = 0; i < period.size(); i++) {
        DurationFieldType fieldType = period.getFieldType(i);
        int index = indexOf(fieldType);
        if (index >= 0) {
            newValues = getField(index).add(this, index, newValues,
                    FieldUtils.safeMultiply(period.getValue(i), scalar));
        }
    }
    return new HourMinuteSecond(this, newValues);
}

From source file:org.angnysa.yaba.service.impl.DefaultTransactionService.java

License:Open Source License

public double computeAvgYearlyBudget(TransactionDefinition td) {
    ReadablePeriod period = td.getPeriod();

    if (period instanceof Years) {
        return td.getAmount() / period.getValue(0);
    } else if (period instanceof Months) {
        return td.getAmount() * MONTH_PER_YEAR / period.getValue(0);
    } else if (period instanceof Weeks) {
        return td.getAmount() * AVG_WEEK_PER_YEAR / period.getValue(0);
    } else if (period instanceof Days) {
        return td.getAmount() * AVG_DAY_PER_YEAR / period.getValue(0);
    } else {/*from w w  w .j  a  v  a2s.  c o m*/
        return Double.NaN;
    }
}

From source file:org.angnysa.yaba.service.impl.DefaultTransactionService.java

License:Open Source License

public double computeAvgMonthlyBudget(TransactionDefinition td) {
    ReadablePeriod period = td.getPeriod();

    if (period instanceof Years) {
        return td.getAmount() / MONTH_PER_YEAR / period.getValue(0);
    } else if (period instanceof Months) {
        return td.getAmount() / period.getValue(0);
    } else if (period instanceof Weeks) {
        return td.getAmount() * AVG_WEEK_PER_MONTH / period.getValue(0);
    } else if (period instanceof Days) {
        return td.getAmount() * AVG_DAY_PER_MONTH / period.getValue(0);
    } else {/*from   ww  w.  j  av  a2 s  .  c  o  m*/
        return Double.NaN;
    }
}

From source file:org.angnysa.yaba.service.impl.DefaultTransactionService.java

License:Open Source License

public double computeAvgWeeklyBudget(TransactionDefinition td) {
    ReadablePeriod period = td.getPeriod();

    if (period instanceof Years) {
        return td.getAmount() / AVG_WEEK_PER_YEAR / period.getValue(0);
    } else if (period instanceof Months) {
        return td.getAmount() / AVG_WEEK_PER_MONTH / period.getValue(0);
    } else if (period instanceof Weeks) {
        return td.getAmount() / period.getValue(0);
    } else if (period instanceof Days) {
        return td.getAmount() * DAY_PER_WEEK / period.getValue(0);
    } else {/*from ww w .  j a v a 2 s .c o  m*/
        return Double.NaN;
    }
}

From source file:org.angnysa.yaba.service.impl.DefaultTransactionService.java

License:Open Source License

public double computeAvgDaylyBudget(TransactionDefinition td) {
    ReadablePeriod period = td.getPeriod();

    if (period instanceof Years) {
        return td.getAmount() / AVG_DAY_PER_YEAR / period.getValue(0);
    } else if (period instanceof Months) {
        return td.getAmount() / AVG_DAY_PER_MONTH / period.getValue(0);
    } else if (period instanceof Weeks) {
        return td.getAmount() / DAY_PER_WEEK / period.getValue(0);
    } else if (period instanceof Days) {
        return td.getAmount() / period.getValue(0);
    } else {/*w w  w .j a  va  2  s .c  om*/
        return Double.NaN;
    }
}