MoneyPerDuration.java
package org.djunits.value.vdouble.scalar;
import org.djunits.unit.DimensionlessUnit;
import org.djunits.unit.MoneyPerDurationUnit;
import org.djunits.unit.MoneyUnit;
/**
* Easy access methods for the MoneyPerDuration DoubleScalar, which is relative by definition. Instead of:
*
* <pre>
* DoubleScalar.Rel<MoneyPerDurationUnit> value = new DoubleScalar.Rel<MoneyPerDurationUnit>(100.0, MoneyPerDurationUnit.SI);
* </pre>
*
* we can now write:
*
* <pre>
* MoneyPerDuration value = new MoneyPerDuration(100.0, MoneyPerDurationUnit.SI);
* </pre>
*
* The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
* used are compatible.
* <p>
* Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
* BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
* <p>
* $LastChangedDate: 2019-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, by $Author: averbraeck $,
* initial version Sep 5, 2015 <br>
* @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
* @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
*/
public class MoneyPerDuration extends AbstractDoubleScalarRel<MoneyPerDurationUnit, MoneyPerDuration>
{
/** */
private static final long serialVersionUID = 20150905L;
/**
* Construct MoneyPerDuration scalar.
* @param value double; double value
* @param unit MoneyPerDurationUnit; unit for the double value
*/
public MoneyPerDuration(final double value, final MoneyPerDurationUnit unit)
{
super(value, unit);
}
/**
* Construct MoneyPerDuration scalar.
* @param value MoneyPerDuration; Scalar from which to construct this instance
*/
public MoneyPerDuration(final MoneyPerDuration value)
{
super(value);
}
/** {@inheritDoc} */
@Override
public final MoneyPerDuration instantiateRel(final double value, final MoneyPerDurationUnit unit)
{
return new MoneyPerDuration(value, unit);
}
/**
* Interpolate between two values.
* @param zero MoneyPerDuration; the low value
* @param one MoneyPerDuration; the high value
* @param ratio double; the ratio between 0 and 1, inclusive
* @return a Scalar at the ratio between
*/
public static MoneyPerDuration interpolate(final MoneyPerDuration zero, final MoneyPerDuration one, final double ratio)
{
return new MoneyPerDuration(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
}
/**
* Return the maximum value of two monetary scalars.
* @param r1 MoneyPerDuration; the first scalar
* @param r2 MoneyPerDuration; the second scalar
* @return the maximum value of two monetary scalars
*/
public static MoneyPerDuration max(final MoneyPerDuration r1, final MoneyPerDuration r2)
{
return (r1.gt(r2)) ? r1 : r2;
}
/**
* Return the maximum value of more than two monetary scalars.
* @param r1 MoneyPerDuration; the first scalar
* @param r2 MoneyPerDuration; the second scalar
* @param rn MoneyPerDuration...; the other scalars
* @return the maximum value of more than two monetary scalars
*/
public static MoneyPerDuration max(final MoneyPerDuration r1, final MoneyPerDuration r2, final MoneyPerDuration... rn)
{
MoneyPerDuration maxr = (r1.gt(r2)) ? r1 : r2;
for (MoneyPerDuration r : rn)
{
if (r.gt(maxr))
{
maxr = r;
}
}
return maxr;
}
/**
* Return the minimum value of two monetary scalars.
* @param r1 MoneyPerDuration; the first scalar
* @param r2 MoneyPerDuration; the second scalar
* @return the minimum value of two monetary scalars
*/
public static MoneyPerDuration min(final MoneyPerDuration r1, final MoneyPerDuration r2)
{
return (r1.lt(r2)) ? r1 : r2;
}
/**
* Return the minimum value of more than two monetary scalars.
* @param r1 MoneyPerDuration; the first scalar
* @param r2 MoneyPerDuration; the second scalar
* @param rn MoneyPerDuration...; the other scalars
* @return the minimum value of more than two monetary scalars
*/
public static MoneyPerDuration min(final MoneyPerDuration r1, final MoneyPerDuration r2, final MoneyPerDuration... rn)
{
MoneyPerDuration minr = (r1.lt(r2)) ? r1 : r2;
for (MoneyPerDuration r : rn)
{
if (r.lt(minr))
{
minr = r;
}
}
return minr;
}
/**
* Calculate the division of MoneyPerDuration and MoneyPerDuration, which results in a Dimensionless scalar.
* @param v MoneyPerDuration; MoneyPerDuration scalar
* @return Dimensionless scalar as a division of MoneyPerDuration and MoneyPerDuration
*/
public final Dimensionless divideBy(final MoneyPerDuration v)
{
return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
}
/**
* Calculate the multiplication of MoneyPerDuration and Duration, which results in a Money scalar.
* @param v Duration; MoneyPerDuration scalar
* @return Money scalar as a multiplication of MoneyPerDuration and Duration
*/
public final Money multiplyBy(final Duration v)
{
return new Money(this.si * v.si, MoneyUnit.getStandardMoneyUnit());
}
/**
* Calculate the division of MoneyPerDuration and Frequency, which results in a Money scalar.
* @param v Frequency; MoneyPerDuration scalar
* @return Money scalar as a division of MoneyPerDuration and Frequency
*/
public final Money divideBy(final Frequency v)
{
return new Money(this.si / v.si, MoneyUnit.getStandardMoneyUnit());
}
}