1 package org.djunits.value.vdouble.scalar; 2 3 import org.djunits.unit.DimensionlessUnit; 4 import org.djunits.unit.MoneyPerMassUnit; 5 import org.djunits.unit.MoneyUnit; 6 7 /** 8 * Easy access methods for the MoneyPerMass DoubleScalar, which is relative by definition. Instead of: 9 * 10 * <pre> 11 * DoubleScalar.Rel<MoneyPerMassUnit> value = new DoubleScalar.Rel<MoneyPerMassUnit>(100.0, MoneyPerMassUnit.SI); 12 * </pre> 13 * 14 * we can now write: 15 * 16 * <pre> 17 * MoneyPerMass value = new MoneyPerMass(100.0, MoneyPerMassUnit.SI); 18 * </pre> 19 * 20 * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit 21 * used are compatible. 22 * <p> 23 * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 24 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>. 25 * <p> 26 * $LastChangedDate: 2019-02-27 23:44:43 +0100 (Wed, 27 Feb 2019) $, @version $Revision: 333 $, by $Author: averbraeck $, 27 * initial version Sep 5, 2015 <br> 28 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 29 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 30 */ 31 public class MoneyPerMass extends AbstractDoubleScalarRel<MoneyPerMassUnit, MoneyPerMass> 32 { 33 /** */ 34 private static final long serialVersionUID = 20150905L; 35 36 /** 37 * Construct MoneyPerMass scalar. 38 * @param value double value 39 * @param unit unit for the double value 40 */ 41 public MoneyPerMass(final double value, final MoneyPerMassUnit unit) 42 { 43 super(value, unit); 44 } 45 46 /** 47 * Construct MoneyPerMass scalar. 48 * @param value Scalar from which to construct this instance 49 */ 50 public MoneyPerMass(final MoneyPerMass value) 51 { 52 super(value); 53 } 54 55 /** {@inheritDoc} */ 56 @Override 57 public final MoneyPerMass instantiateRel(final double value, final MoneyPerMassUnit unit) 58 { 59 return new MoneyPerMass(value, unit); 60 } 61 62 /** 63 * Interpolate between two values. 64 * @param zero the low value 65 * @param one the high value 66 * @param ratio the ratio between 0 and 1, inclusive 67 * @return a Scalar at the ratio between 68 */ 69 public static MoneyPerMass interpolate(final MoneyPerMass zero, final MoneyPerMass one, final double ratio) 70 { 71 return new MoneyPerMass(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit()); 72 } 73 74 /** 75 * Return the maximum value of two monetary scalars. 76 * @param r1 the first scalar 77 * @param r2 the second scalar 78 * @return the maximum value of two monetary scalars 79 */ 80 public static MoneyPerMass max(final MoneyPerMass r1, final MoneyPerMass r2) 81 { 82 return (r1.gt(r2)) ? r1 : r2; 83 } 84 85 /** 86 * Return the maximum value of more than two monetary scalars. 87 * @param r1 the first scalar 88 * @param r2 the second scalar 89 * @param rn the other scalars 90 * @return the maximum value of more than two monetary scalars 91 */ 92 public static MoneyPerMass max(final MoneyPerMass r1, final MoneyPerMass r2, final MoneyPerMass... rn) 93 { 94 MoneyPerMass maxr = (r1.gt(r2)) ? r1 : r2; 95 for (MoneyPerMass r : rn) 96 { 97 if (r.gt(maxr)) 98 { 99 maxr = r; 100 } 101 } 102 return maxr; 103 } 104 105 /** 106 * Return the minimum value of two monetary scalars. 107 * @param r1 the first scalar 108 * @param r2 the second scalar 109 * @return the minimum value of two monetary scalars 110 */ 111 public static MoneyPerMass min(final MoneyPerMass r1, final MoneyPerMass r2) 112 { 113 return (r1.lt(r2)) ? r1 : r2; 114 } 115 116 /** 117 * Return the minimum value of more than two monetary scalars. 118 * @param r1 the first scalar 119 * @param r2 the second scalar 120 * @param rn the other scalars 121 * @return the minimum value of more than two monetary scalars 122 */ 123 public static MoneyPerMass min(final MoneyPerMass r1, final MoneyPerMass r2, final MoneyPerMass... rn) 124 { 125 MoneyPerMass minr = (r1.lt(r2)) ? r1 : r2; 126 for (MoneyPerMass r : rn) 127 { 128 if (r.lt(minr)) 129 { 130 minr = r; 131 } 132 } 133 return minr; 134 } 135 136 /** 137 * Calculate the division of MoneyPerMass and MoneyPerMass, which results in a Dimensionless scalar. 138 * @param v MoneyPerMass scalar 139 * @return Dimensionless scalar as a division of MoneyPerMass and MoneyPerMass 140 */ 141 public final Dimensionless divideBy(final MoneyPerMass v) 142 { 143 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI); 144 } 145 146 /** 147 * Calculate the multiplication of MoneyPerMass and Mass, which results in a Money scalar. 148 * @param v MoneyPerMass scalar 149 * @return Money scalar as a multiplication of MoneyPerMass and Mass 150 */ 151 public final Money multiplyBy(final Mass v) 152 { 153 return new Money(this.si * v.si, MoneyUnit.getStandardMoneyUnit()); 154 } 155 156 }