Example usage for org.apache.commons.lang3.math Fraction multiplyBy

List of usage examples for org.apache.commons.lang3.math Fraction multiplyBy

Introduction

In this page you can find the example usage for org.apache.commons.lang3.math Fraction multiplyBy.

Prototype

public Fraction multiplyBy(final Fraction fraction) 

Source Link

Document

Multiplies the value of this fraction by another, returning the result in reduced form.

Usage

From source file:org.libreplan.web.resourceload.LoadPeriodGenerator.java

private int calculateLoadPercentage(EffortDuration totalEffort, EffortDuration effortAssigned) {
    if (totalEffort.isZero()) {
        return effortAssigned.isZero() ? 0 : Integer.MAX_VALUE;
    }/* w w w  . j  av a 2 s .c om*/

    if (effortAssigned.isZero()) {
        LOG.warn("total effort is " + totalEffort + " but effortAssigned is zero");
        getEffortAssigned();

        return 0;
    }
    Fraction fraction = effortAssigned.divivedBy(totalEffort);
    Fraction percentage = fraction.multiplyBy(Fraction.getFraction(100, 1));

    return percentage.intValue();
}

From source file:org.zkoss.ganttz.DatesMapperOnInterval.java

private int toPixels(Fraction proportion) {
    try {/* ww w.ja  v  a2s .  c  om*/
        return proportion.multiplyBy(Fraction.getFraction(horizontalSize, 1)).intValue();
    } catch (ArithmeticException e) {
        double d = Math.log10(horizontalSize);
        int scale = (int) d + 1;

        BigDecimal quotient = new BigDecimal(proportion.getNumerator())
                .divide(new BigDecimal(proportion.getDenominator()), scale, RoundingMode.HALF_UP);

        return quotient.multiply(new BigDecimal(horizontalSize)).intValue();
    }
}

From source file:pcgen.system.PCGenTaskExecutor.java

@Override
public void progressChanged(PCGenTaskEvent event) {
    if (currentTask.getMaximum() == 0) {
        return;//from w  ww  . j  av a2s  .  co m
    }
    Fraction progress = Fraction.getFraction(currentTask.getProgress(), currentTask.getMaximum());
    progress = progress.multiplyBy(progressMultiplier);
    progress = baseProgress.add(progress);
    setValues(currentTask.getMessage(), progress.getNumerator(), progress.getDenominator());
}