1 package org.djunits.value.vdouble.vector.base; 2 3 import org.djunits.unit.AbsoluteLinearUnit; 4 import org.djunits.unit.Unit; 5 import org.djunits.value.Absolute; 6 import org.djunits.value.ValueRuntimeException; 7 import org.djunits.value.base.Vector; 8 import org.djunits.value.vdouble.function.DoubleMathFunctions; 9 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarAbs; 10 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRelWithAbs; 11 import org.djunits.value.vdouble.vector.data.DoubleVectorData; 12 13 /** 14 * AbstractMutableDoubleVectorRelWithAbs.java. 15 * <p> 16 * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 17 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>. 18 * <p> 19 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a> 20 * @param <AU> the absolute unit belonging to the relative unit 21 * @param <A> the absolute scalar type belonging to the absolute vector type 22 * @param <AV> the (immutable or mutable) absolute vector type 23 * @param <RU> the relative unit belonging to the absolute unit 24 * @param <R> the relative scalar type belonging to the relative vector type 25 * @param <RV> the relative (immutable or mutable) vector type with this unit 26 */ 27 // @formatter:off 28 public abstract class AbstractDoubleVectorAbs< 29 AU extends AbsoluteLinearUnit<AU, RU>, 30 A extends AbstractDoubleScalarAbs<AU, A, RU, R>, 31 AV extends AbstractDoubleVectorAbs<AU, A, AV, RU, R, RV>, 32 RU extends Unit<RU>, 33 R extends AbstractDoubleScalarRelWithAbs<AU, A, RU, R>, 34 RV extends AbstractDoubleVectorRelWithAbs<AU, A, AV, RU, R, RV>> 35 extends AbstractDoubleVector<AU, A, AV> 36 implements Vector.Abs<AU, A, AV, RU, R, RV>, Absolute 37 // @formatter:on 38 { 39 /** */ 40 private static final long serialVersionUID = 20190908L; 41 42 /** 43 * Construct a new Relative Mutable DoubleVector. 44 * @param data DoubleVectorData; an internal data object 45 * @param unit U; the unit 46 */ 47 protected AbstractDoubleVectorAbs(final DoubleVectorData data, final AU unit) 48 { 49 super(data.copy(), unit); 50 } 51 52 /** {@inheritDoc} */ 53 @Override 54 public AV plus(final RV increment) throws ValueRuntimeException 55 { 56 return instantiateVector(this.getData().plus(increment.getData()), getDisplayUnit()); 57 } 58 59 /** {@inheritDoc} */ 60 @Override 61 public AV minus(final RV decrement) throws ValueRuntimeException 62 { 63 return instantiateVector(this.getData().minus(decrement.getData()), getDisplayUnit()); 64 } 65 66 /** {@inheritDoc} */ 67 @Override 68 public RV minus(final AV decrement) throws ValueRuntimeException 69 { 70 return instantiateVectorRel(this.getData().minus(decrement.getData()), decrement.getDisplayUnit().getRelativeUnit()); 71 } 72 73 /** 74 * Decrement all values of this vector by the decrement. This only works if this vector is mutable. 75 * @param decrement R; the scalar by which to decrement all values 76 * @return AV; this modified vector 77 * @throws ValueRuntimeException in case this vector is immutable 78 */ 79 @SuppressWarnings("unchecked") 80 public AV decrementBy(final R decrement) 81 { 82 checkCopyOnWrite(); 83 assign(DoubleMathFunctions.DEC(decrement.si)); 84 return (AV) this; 85 } 86 87 /** 88 * Decrement all values of this vector by the decrement on a value by value basis. This only works if this vector is 89 * mutable. 90 * @param decrement RV; the vector that contains the values by which to decrement the corresponding values 91 * @return AV; this modified vector 92 * @throws ValueRuntimeException in case this vector is immutable, when the sizes of the vectors differ, or 93 * <code>decrement</code> is null 94 */ 95 @SuppressWarnings("unchecked") 96 public AV decrementBy(final RV decrement) 97 { 98 checkCopyOnWrite(); 99 getData().decrementBy(decrement.getData()); 100 return (AV) this; 101 } 102 103 /** 104 * Instantiate a new relative vector of the class of this absolute vector. This can be used instead of the 105 * DoubleVector.instiantiate() methods in case another vector of this absolute vector class is known. The method is faster 106 * than DoubleVector.instantiate, and it will also work if the vector is user-defined. 107 * @param dvd DoubleVectorData; the data used to instantiate the vector 108 * @param displayUnit RU; the display unit of the relative vector 109 * @return RV; a relative vector of the correct type, belonging to this absolute vector type 110 */ 111 public abstract RV instantiateVectorRel(DoubleVectorData dvd, RU displayUnit); 112 113 /** 114 * Instantiate a new relative scalar for the class of this absolute vector. This can be used instead of the 115 * DoubleScalar.instiantiate() methods in case a vector of this class is known. The method is faster than 116 * DoubleScalar.instantiate, and it will also work if the vector and/or scalar are user-defined. 117 * @param valueSI double; the SI value of the relative scalar 118 * @param displayUunit RU; the unit in which the relative value will be displayed 119 * @return R; a relative scalar of the correct type, belonging to this absolute vector type 120 */ 121 public abstract R instantiateScalarRelSI(double valueSI, RU displayUunit); 122 123 }