类org.apache.commons.lang3.math.Fraction源码实例Demo

下面列出了怎么用org.apache.commons.lang3.math.Fraction的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: tracecompass   文件: PeriodicMarkerEventSource.java
private PeriodicMarkerEventSource(String category, Reference reference, double period, long rollover, boolean foreground, RGBA color1, @Nullable RGBA color2) {
    if (period <= 0) {
        throw new IllegalArgumentException("period cannot be less than or equal to zero"); //$NON-NLS-1$
    }
    if (rollover < 0) {
        throw new IllegalArgumentException("rollover cannot be less than zero"); //$NON-NLS-1$
    }
    fCategory = category;
    fReference = reference;
    fPeriod = period;
    fPeriodInteger = (long) period;
    try {
        fPeriodFraction = Fraction.getFraction(fPeriod - fPeriodInteger);
    } catch (ArithmeticException e) {
        /* can't convert to fraction, use floating-point arithmetic */
        fPeriodFraction = null;
    }
    fRollover = rollover;
    fColor1 = color1;
    fColor2 = color2;
    fForeground = foreground;
}
 
源代码2 项目: tracecompass   文件: PeriodicMarkerEventSource.java
private Reference adjustReference(Reference baseReference, long time) {
    long offsetIndex = (long) ((time - baseReference.time) / fPeriod);
    long offsetTime = 0;
    Fraction fraction = fPeriodFraction;
    if (fraction != null) {
        /*
         * If period = int num/den, find an offset index that is an exact
         * multiple of den and calculate index * period = (index * int) +
         * (index / den * num), all exact calculations.
         */
        offsetIndex = offsetIndex - offsetIndex % fraction.getDenominator();
        offsetTime = offsetIndex * fPeriodInteger + offsetIndex / fraction.getDenominator() * fraction.getNumerator();
    } else {
        /*
         * Couldn't compute fractional part as fraction, use simple
         * multiplication but with possible rounding error.
         */
        offsetTime = Math.round(offsetIndex * fPeriod);
    }
    Reference reference = new Reference(baseReference.time + offsetTime, baseReference.index + offsetIndex);
    return reference;
}
 
源代码3 项目: pcgen   文件: PCGenTaskExecutor.java
@Override
public void run()
{
	progressMultiplier = Fraction.getFraction(1, tasks.size());
	while (!tasks.isEmpty())
	{
		currentTask = tasks.poll();
		setValues(currentTask.getMessage(), baseProgress.getNumerator(), baseProgress.getDenominator());
		currentTask.addPCGenTaskListener(this);
		currentTask.run();
		currentTask.removePCGenTaskListener(this);
		baseProgress = baseProgress.add(progressMultiplier);
	}
}
 
源代码4 项目: pcgen   文件: PCGenTaskExecutor.java
@Override
public void progressChanged(PCGenTaskEvent event)
{
	if (currentTask.getMaximum() == 0)
	{
		return;
	}
	Fraction progress = Fraction.getFraction(currentTask.getProgress(), currentTask.getMaximum());
	progress = progress.multiplyBy(progressMultiplier);
	progress = baseProgress.add(progress);
	setValues(currentTask.getMessage(), progress.getNumerator(), progress.getDenominator());
}
 
源代码5 项目: pcgen   文件: PCGenTaskExecutor.java
@Override
public void run()
{
	progressMultiplier = Fraction.getFraction(1, tasks.size());
	while (!tasks.isEmpty())
	{
		currentTask = tasks.poll();
		setValues(currentTask.getMessage(), baseProgress.getNumerator(), baseProgress.getDenominator());
		currentTask.addPCGenTaskListener(this);
		currentTask.run();
		currentTask.removePCGenTaskListener(this);
		baseProgress = baseProgress.add(progressMultiplier);
	}
}
 
源代码6 项目: pcgen   文件: PCGenTaskExecutor.java
@Override
public void progressChanged(PCGenTaskEvent event)
{
	if (currentTask.getMaximum() == 0)
	{
		return;
	}
	Fraction progress = Fraction.getFraction(currentTask.getProgress(), currentTask.getMaximum());
	progress = progress.multiplyBy(progressMultiplier);
	progress = baseProgress.add(progress);
	setValues(currentTask.getMessage(), progress.getNumerator(), progress.getDenominator());
}
 
源代码7 项目: tutorials   文件: FractionUnitTest.java
@Test
public void givenFractionClass_whenCalledgetFraction_thenCorrect() {
    assertThat(Fraction.getFraction(5, 6)).isInstanceOf(Fraction.class);
}
 
源代码8 项目: tutorials   文件: FractionUnitTest.java
@Test
public void givenTwoFractionInstances_whenCalledadd_thenCorrect() {
    Fraction fraction1 = Fraction.getFraction(1, 4);
    Fraction fraction2 = Fraction.getFraction(3, 4);
    assertThat(fraction1.add(fraction2).toString()).isEqualTo("1/1");
}
 
源代码9 项目: tutorials   文件: FractionUnitTest.java
@Test
public void givenTwoFractionInstances_whenCalledsubstract_thenCorrect() {
    Fraction fraction1 = Fraction.getFraction(3, 4);
    Fraction fraction2 = Fraction.getFraction(1, 4);
    assertThat(fraction1.subtract(fraction2).toString()).isEqualTo("1/2");
}
 
源代码10 项目: tutorials   文件: FractionUnitTest.java
@Test
public void givenTwoFractionInstances_whenCalledmultiply_thenCorrect() {
    Fraction fraction1 = Fraction.getFraction(3, 4);
    Fraction fraction2 = Fraction.getFraction(1, 4);
    assertThat(fraction1.multiplyBy(fraction2).toString()).isEqualTo("3/16");
}
 
源代码11 项目: OpenModsLib   文件: CalcState.java
@Override
public Calculator<?, ExprType> newCalculator(final SenderHolder holder) {
	final Calculator<Fraction, ExprType> calculator = FractionCalculatorFactory.createDefault();

	calculator.environment.setGlobalSymbol("_x", () -> Fraction.getFraction(holder.getX(), 1));

	calculator.environment.setGlobalSymbol("_y", () -> Fraction.getFraction(holder.getY(), 1));

	calculator.environment.setGlobalSymbol("_z", () -> Fraction.getFraction(holder.getZ(), 1));

	return calculator;
}
 
 类所在包
 类方法
 同包方法