1 package org.djunits.value.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.Relative; 7 import org.djunits.value.Value; 8 9 /** 10 * Scalar to distinguish a scalar from vectors and matrices. 11 * <p> 12 * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 13 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>. 14 * <p> 15 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a> 16 * @param <U> the unit 17 * @param <S> the scalar type with the given unit 18 */ 19 public interface Scalar<U extends Unit<U>, S extends Scalar<U, S>> extends Value<U, S>, Comparable<S> 20 { 21 /** 22 * Test if this DoubleScalar is less than another DoubleScalar. 23 * @param o T, a relative typed DoubleScalar; the right hand side operand of the comparison 24 * @return boolean; true if this is less than other; false if this is not less than other 25 */ 26 boolean lt(S o); 27 28 /** 29 * Test if this DoubleScalar is less than or equal to another DoubleScalar. 30 * @param o T, a relative typed DoubleScalar; the right hand side operand of the comparison 31 * @return boolean 32 */ 33 boolean le(S o); 34 35 /** 36 * Test if this DoubleScalar is greater than or equal to a DoubleScalar. 37 * @param o T, a relative typed DoubleScalar; the right hand side operand of the comparison 38 * @return boolean; true if this is greater than or equal to other; false if this is not greater than or equal to other 39 */ 40 boolean gt(S o); 41 42 /** 43 * Test if this DoubleScalar is greater than a DoubleScalar. 44 * @param o T, a relative typed DoubleScalar; the right hand side operand of the comparison 45 * @return boolean; true if this is greater than other; false if this is not greater than other 46 */ 47 boolean ge(S o); 48 49 /** 50 * Test if this DoubleScalar is equal to a DoubleScalar. 51 * @param o T, a relative typed DoubleScalar; the right hand side operand of the comparison 52 * @return boolean; true if this is equal to other; false if this is not equal to other 53 */ 54 boolean eq(S o); 55 56 /** 57 * Test if this DoubleScalar is not equal to a DoubleScalar. 58 * @param o T, a relative typed DoubleScalar; the right hand side operand of the comparison 59 * @return boolean; true if this is not equal to other; false if this is equal to other 60 */ 61 boolean ne(S o); 62 63 /** 64 * Test if this DoubleScalar is less than 0.0. 65 * @return boolean; true if this is less than 0.0; false if this is not less than 0.0 66 */ 67 boolean lt0(); 68 69 /** 70 * Test if this DoubleScalar is less than or equal to 0.0. 71 * @return boolean; true if this is less than or equal to 0.0; false if this is not less than or equal to 0.0 72 */ 73 boolean le0(); 74 75 /** 76 * Test if this DoubleScalar is greater than or equal to 0.0. 77 * @return boolean; true if this is greater than or equal to 0.0; false if this is not greater than or equal to 0.0 78 */ 79 boolean gt0(); 80 81 /** 82 * Test if this DoubleScalar is greater than 0.0. 83 * @return boolean; true if this is greater than 0.0; false if this is not greater than 0.0 84 */ 85 boolean ge0(); 86 87 /** 88 * Test if this DoubleScalar is equal to 0.0. 89 * @return boolean; true if this is equal to 0.0; false if this is not equal to 0.0 90 */ 91 boolean eq0(); 92 93 /** 94 * Test if this DoubleScalar is not equal to 0.0. 95 * @return boolean; true if this is not equal to 0.0; false if this is equal to 0.0 96 */ 97 boolean ne0(); 98 99 /** 100 * Methods for Relative Scalar. 101 * <p> 102 * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 103 * <br> 104 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>. 105 * <p> 106 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a> 107 * @param <U> the unit 108 * @param <R> the relative scalar 109 */ 110 public interface Rel<U extends Unit<U>, R extends Scalar.Rel<U, R>> extends Scalar<U, R>, Relative<U, R> 111 { 112 /** 113 * Add a Relative value to this Relative value. A new value is returned due to immutability. 114 * @param increment R; the value to add 115 * @return R; the sum of this value and the operand as a new object 116 */ 117 R plus(R increment); 118 119 /** 120 * Subtract a Relative value from this Relative value. A new value is returned due to immutability. 121 * @param decrement R; the value to subtract 122 * @return R; the difference of this value and the operand 123 */ 124 R minus(R decrement); 125 } 126 127 /** 128 * Additional methods for Relative Scalar that has a corresponding Absolute Scalar. An example is the relative scalar Length 129 * that has a corresponding absolute scalar Position. 130 * <p> 131 * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 132 * <br> 133 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>. 134 * <p> 135 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a> 136 * @param <AU> the absolute unit belonging to the absoluteunit 137 * @param <A> the absolute scalar belonging to the relative scalar 138 * @param <RU> the absolute unit belonging to the relative unit 139 * @param <R> the relative scalar belonging to the absolute scalar 140 */ 141 public interface RelWithAbs<AU extends AbsoluteLinearUnit<AU, RU>, A extends Scalar.Abs<AU, A, RU, R>, 142 RU extends Unit<RU>, R extends Scalar.RelWithAbs<AU, A, RU, R>> extends Scalar.Rel<RU, R> 143 { 144 /** 145 * Add an Absolute value to this relative value. A new value is returned due to immutability. The unit of the result is 146 * the unit of the absolute operand. 147 * @param abs A; A the right operand 148 * @return A; the sum of this value and the operand 149 */ 150 A plus(A abs); 151 } 152 153 /** 154 * Methods for Absolute Scalar. 155 * <p> 156 * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 157 * <br> 158 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>. 159 * <p> 160 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a> 161 * @param <AU> the absolute unit belonging to the absoluteunit 162 * @param <A> the absolute scalar belonging to the relative scalar 163 * @param <RU> the absolute unit belonging to the relative unit 164 * @param <R> the relative scalar belonging to the absolute scalar 165 */ 166 public interface Abs<AU extends AbsoluteLinearUnit<AU, RU>, A extends Scalar.Abs<AU, A, RU, R>, RU extends Unit<RU>, 167 R extends Scalar.RelWithAbs<AU, A, RU, R>> extends Scalar<AU, A>, Absolute 168 { 169 /** 170 * Add a Relative value to this Absolute value. A new value is returned due to immutability. 171 * @param rel R; R the right operand 172 * @return A; the sum of this value and the operand 173 */ 174 A plus(R rel); 175 176 /** 177 * Subtract a Relative value from this Absolute value. A new value is returned due to immutability. 178 * @param rel R; R the right operand 179 * @return A; the subtraction of this value and the operand 180 */ 181 A minus(R rel); 182 183 /** 184 * Subtract an Absolute value from this Absolute value, resulting in a Relative value. A new value is returned due to 185 * immutability. 186 * @param abs A; A the right operand 187 * @return R; the subtraction of this value and the operand 188 */ 189 R minus(A abs); 190 } 191 }