View Javadoc
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      * Concise textual representation of this value, without the engineering formatting, so without trailing zeroes. A space is
101      * added between the number and the unit.
102      * @return a String with the value with the default textual representation of the unit attached.
103      */
104     String toTextualString();
105 
106     /**
107      * Concise textual representation of this value, without the engineering formatting, so without trailing zeroes. A space is
108      * added between the number and the unit.
109      * @param displayUnit U; the display unit for the value
110      * @return a String with the value with the default textual representation of the provided unit attached.
111      */
112     String toTextualString(U displayUnit);
113 
114     /**
115      * Concise display description of this value, without the engineering formatting, so without trailing zeroes. A space is
116      * added between the number and the unit.
117      * @return a String with the value with the default display representation of the unit attached.
118      */
119     String toDisplayString();
120 
121     /**
122      * Concise display description of this value, without the engineering formatting, so without trailing zeroes. A space is
123      * added between the number and the unit.
124      * @param displayUnit U; the display unit for the value
125      * @return a String with the value with the default display representation of the provided unit attached.
126      */
127     String toDisplayString(U displayUnit);
128 
129     /**
130      * Methods for Relative Scalar.
131      * <p>
132      * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
133      * <br>
134      * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
135      * <p>
136      * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
137      * @param <U> the unit
138      * @param <R> the relative scalar
139      */
140     public interface Rel<U extends Unit<U>, R extends Scalar.Rel<U, R>> extends Scalar<U, R>, Relative<U, R>
141     {
142         /**
143          * Add a Relative value to this Relative value. A new value is returned due to immutability.
144          * @param increment R; the value to add
145          * @return R; the sum of this value and the operand as a new object
146          */
147         R plus(R increment);
148 
149         /**
150          * Subtract a Relative value from this Relative value. A new value is returned due to immutability.
151          * @param decrement R; the value to subtract
152          * @return R; the difference of this value and the operand
153          */
154         R minus(R decrement);
155     }
156 
157     /**
158      * Additional methods for Relative Scalar that has a corresponding Absolute Scalar. An example is the relative scalar Length
159      * that has a corresponding absolute scalar Position.
160      * <p>
161      * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
162      * <br>
163      * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
164      * <p>
165      * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
166      * @param <AU> the absolute unit belonging to the absoluteunit
167      * @param <A> the absolute scalar belonging to the relative scalar
168      * @param <RU> the absolute unit belonging to the relative unit
169      * @param <R> the relative scalar belonging to the absolute scalar
170      */
171     public interface RelWithAbs<AU extends AbsoluteLinearUnit<AU, RU>, A extends Scalar.Abs<AU, A, RU, R>, RU extends Unit<RU>,
172             R extends Scalar.RelWithAbs<AU, A, RU, R>> extends Scalar.Rel<RU, R>
173     {
174         /**
175          * Add an Absolute value to this relative value. A new value is returned due to immutability. The unit of the result is
176          * the unit of the absolute operand.
177          * @param abs A; A the right operand
178          * @return A; the sum of this value and the operand
179          */
180         A plus(A abs);
181     }
182 
183     /**
184      * Methods for Absolute Scalar.
185      * <p>
186      * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
187      * <br>
188      * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
189      * <p>
190      * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
191      * @param <AU> the absolute unit belonging to the absoluteunit
192      * @param <A> the absolute scalar belonging to the relative scalar
193      * @param <RU> the absolute unit belonging to the relative unit
194      * @param <R> the relative scalar belonging to the absolute scalar
195      */
196     public interface Abs<AU extends AbsoluteLinearUnit<AU, RU>, A extends Scalar.Abs<AU, A, RU, R>, RU extends Unit<RU>,
197             R extends Scalar.RelWithAbs<AU, A, RU, R>> extends Scalar<AU, A>, Absolute
198     {
199         /**
200          * Add a Relative value to this Absolute value. A new value is returned due to immutability.
201          * @param rel R; R the right operand
202          * @return A; the sum of this value and the operand
203          */
204         A plus(R rel);
205 
206         /**
207          * Subtract a Relative value from this Absolute value. A new value is returned due to immutability.
208          * @param rel R; R the right operand
209          * @return A; the subtraction of this value and the operand
210          */
211         A minus(R rel);
212 
213         /**
214          * Subtract an Absolute value from this Absolute value, resulting in a Relative value. A new value is returned due to
215          * immutability.
216          * @param abs A; A the right operand
217          * @return R; the subtraction of this value and the operand
218          */
219         R minus(A abs);
220     }
221 }