List of usage examples for org.apache.commons.lang3.math Fraction getFraction
public static Fraction getFraction(int numerator, int denominator)
Creates a Fraction
instance with the 2 parts of a fraction Y/Z.
Any negative signs are resolved to be on the numerator.
From source file:org.libreplan.business.workingday.EffortDuration.java
public Fraction divivedBy(EffortDuration effortAssigned) { return Fraction.getFraction(this.seconds, effortAssigned.seconds); }
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 a v a 2 s.c o m 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.richfaces.tests.metamer.ftest.extension.attributes.coverage.saver.FullReportResultsSaver.java
protected void write(BufferedWriter bw) throws IOException { try {/* w w w. j a va 2s .c om*/ int covered = 0, notCovered = 0; for (CoverageResult result : getResults()) { bw.append(result.getReport()); bw.newLine(); bw.flush(); covered += result.getCovered().size() + result.getIgnored().size(); notCovered += result.getNotCovered().size(); } Fraction f = Fraction.getFraction(covered, covered + notCovered); bw.append("==========================================================="); bw.newLine(); bw.append("total coverage: ").append(f.toString()).append(" (") .append(String.valueOf((int) (f.doubleValue() * 100))).append("%)"); bw.newLine(); bw.flush(); } finally { if (bw != null) { bw.close(); } } }
From source file:org.zkoss.ganttz.DatesMapperOnInterval.java
public DatesMapperOnInterval(int horizontalSize, Interval interval) { this.horizontalSize = horizontalSize; this.interval = interval; this.millisecondsPerPixel = interval.getLengthBetween().getMillis() / horizontalSize; this.pixelsPerDay = Fraction.getFraction(horizontalSize, interval.getDaysBetween().getDays()); }
From source file:org.zkoss.ganttz.DatesMapperOnInterval.java
@Override public LocalDate toDate(int pixels) { int daysInto = Fraction.getFraction(pixels, 1).divideBy(pixelsPerDay).intValue(); return getInterval().getStart().plusDays(daysInto); }
From source file:org.zkoss.ganttz.DatesMapperOnInterval.java
private int toPixels(Fraction proportion) { try {// ww w . j ava 2 s .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:org.zkoss.ganttz.TaskList.java
public LocalDate toDate(int pixels, Fraction pixelsPerDay, Interval interval) { int daysInto = Fraction.getFraction(pixels, 1).divideBy(pixelsPerDay).intValue(); return interval.getStart().plusDays(daysInto); }
From source file:org.zkoss.ganttz.util.Interval.java
public Fraction getProportion(DateTime date) { Days fromStartToDate = Days.daysBetween(startInclusive, date.toLocalDate()); Fraction result = Fraction.getFraction(fromStartToDate.getDays(), this.daysBetween.getDays()); try {//from w w w.j a v a 2 s. c o m return result.add(inTheDayIncrement(date)); } catch (ArithmeticException e) { return result; } }
From source file:pcgen.system.PCGenTaskExecutor.java
@Override public void execute() { progressMultiplier = Fraction.getFraction(1, tasks.size()); while (!tasks.isEmpty()) { currentTask = tasks.poll();//from w ww .j a v a 2 s .c om setValues(currentTask.getMessage(), baseProgress.getNumerator(), baseProgress.getDenominator()); currentTask.addPCGenTaskListener(this); currentTask.execute(); currentTask.removePCGenTaskListener(this); baseProgress = baseProgress.add(progressMultiplier); } }
From source file:pcgen.system.PCGenTaskExecutor.java
@Override public void progressChanged(PCGenTaskEvent event) { if (currentTask.getMaximum() == 0) { return;//from w w w.j a v a2 s .c o m } Fraction progress = Fraction.getFraction(currentTask.getProgress(), currentTask.getMaximum()); progress = progress.multiplyBy(progressMultiplier); progress = baseProgress.add(progress); setValues(currentTask.getMessage(), progress.getNumerator(), progress.getDenominator()); }