1 package org.djunits.value.vdouble.scalar; 2 3 import org.djunits.unit.DimensionlessUnit; 4 import org.djunits.unit.MoneyPerLengthUnit; 5 import org.djunits.unit.MoneyUnit; 6 7 /** 8 * Easy access methods for the MoneyPerLength DoubleScalar, which is relative by definition. Instead of: 9 * 10 * <pre> 11 * DoubleScalar.Rel<MoneyPerLengthUnit> value = new DoubleScalar.Rel<MoneyPerLengthUnit>(100.0, MoneyPerLengthUnit.SI); 12 * </pre> 13 * 14 * we can now write: 15 * 16 * <pre> 17 * MoneyPerLength value = new MoneyPerLength(100.0, MoneyPerLengthUnit.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-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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 MoneyPerLength extends AbstractDoubleScalarRel<MoneyPerLengthUnit, MoneyPerLength> 32 { 33 /** */ 34 private static final long serialVersionUID = 20150905L; 35 36 /** 37 * Construct MoneyPerLength scalar. 38 * @param value double value 39 * @param unit unit for the double value 40 */ 41 public MoneyPerLength(final double value, final MoneyPerLengthUnit unit) 42 { 43 super(value, unit); 44 } 45 46 /** 47 * Construct MoneyPerLength scalar. 48 * @param value Scalar from which to construct this instance 49 */ 50 public MoneyPerLength(final MoneyPerLength value) 51 { 52 super(value); 53 } 54 55 /** {@inheritDoc} */ 56 @Override 57 public final MoneyPerLength instantiateRel(final double value, final MoneyPerLengthUnit unit) 58 { 59 return new MoneyPerLength(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 MoneyPerLength interpolate(final MoneyPerLength zero, final MoneyPerLength one, final double ratio) 70 { 71 return new MoneyPerLength(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 MoneyPerLength max(final MoneyPerLength r1, final MoneyPerLength 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 MoneyPerLength max(final MoneyPerLength r1, final MoneyPerLength r2, final MoneyPerLength... rn) 93 { 94 MoneyPerLength maxr = (r1.gt(r2)) ? r1 : r2; 95 for (MoneyPerLength 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 MoneyPerLength min(final MoneyPerLength r1, final MoneyPerLength 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 MoneyPerLength min(final MoneyPerLength r1, final MoneyPerLength r2, final MoneyPerLength... rn) 124 { 125 MoneyPerLength minr = (r1.lt(r2)) ? r1 : r2; 126 for (MoneyPerLength 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 MoneyPerLength and MoneyPerLength, which results in a Dimensionless scalar. 138 * @param v MoneyPerLength scalar 139 * @return Dimensionless scalar as a division of MoneyPerLength and MoneyPerLength 140 */ 141 public final Dimensionless divideBy(final MoneyPerLength v) 142 { 143 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI); 144 } 145 146 /** 147 * Calculate the multiplication of MoneyPerLength and Length, which results in a Money scalar. 148 * @param v MoneyPerLength scalar 149 * @return Money scalar as a multiplication of MoneyPerLength and Length 150 */ 151 public final Money multiplyBy(final Length v) 152 { 153 return new Money(this.si * v.si, MoneyUnit.getStandardMoneyUnit()); 154 } 155 156 /** 157 * Calculate the division of MoneyPerLength and LinearDensity, which results in a Money scalar. 158 * @param v MoneyPerLength scalar 159 * @return Money scalar as a division of MoneyPerLength and LinearDensity 160 */ 161 public final Money divideBy(final LinearDensity v) 162 { 163 return new Money(this.si / v.si, MoneyUnit.getStandardMoneyUnit()); 164 } 165 166 }