View Javadoc
1   package org.opentrafficsim.core.value.vfloat.scalar;
2   
3   import org.opentrafficsim.core.unit.Unit;
4   import org.opentrafficsim.core.value.Absolute;
5   import org.opentrafficsim.core.value.Relative;
6   import org.opentrafficsim.core.value.ValueUtil;
7   import org.opentrafficsim.core.value.vfloat.FloatMathFunctions;
8   
9   /**
10   * MutableFloatScalar.
11   * <p>
12   * This file was generated by the OpenTrafficSim value classes generator, 09 mrt, 2015
13   * <p>
14   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version 09 mrt, 2015 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   * @param <U> Unit; the unit of this MutableFloatScalar
21   */
22  public abstract class MutableFloatScalar<U extends Unit<U>> extends FloatScalar<U> implements
23          FloatMathFunctions<FloatScalar<U>>
24  {
25      /**  */
26      private static final long serialVersionUID = 20150309L;
27  
28      /**
29       * Construct a new MutableFloatScalar.
30       * @param unit U; the unit of the new MutableFloatScalar
31       */
32      protected MutableFloatScalar(final U unit)
33      {
34          super(unit);
35          // System.out.println("Created MutableFloatScalar");
36      }
37  
38      /**
39       * @param <U> Unit
40       */
41      public static class Abs<U extends Unit<U>> extends MutableFloatScalar<U> implements Absolute, Comparable<Abs<U>>
42      {
43          /**  */
44          private static final long serialVersionUID = 20150309L;
45  
46          /**
47           * Construct a new Absolute MutableFloatScalar.
48           * @param value float; the value of the new Absolute MutableFloatScalar
49           * @param unit U; the unit of the new Absolute MutableFloatScalar
50           */
51          public Abs(final float value, final U unit)
52          {
53              super(unit);
54              // System.out.println("Created Abs");
55              initialize(value);
56          }
57  
58          /**
59           * Construct a new Absolute MutableFloatScalar from an existing Absolute Immutable FloatScalar.
60           * @param value FloatScalar.Abs&lt;U&gt;; the reference
61           */
62          public Abs(final FloatScalar.Abs<U> value)
63          {
64              super(value.getUnit());
65              // System.out.println("Created Abs");
66              initialize(value);
67          }
68  
69          /**
70           * Construct a new Absolute MutableFloatScalar from an existing Absolute MutableFloatScalar.
71           * @param value MutableFloatScalar.Abs&lt;U&gt;; the reference
72           */
73          public Abs(final MutableFloatScalar.Abs<U> value)
74          {
75              super(value.getUnit());
76              // System.out.println("Created Abs");
77              initialize(value);
78          }
79  
80          /** {@inheritDoc} */
81          @Override
82          public final MutableFloatScalar.Abs<U> mutable()
83          {
84              return new MutableFloatScalar.Abs<U>(this);
85          }
86  
87          /** {@inheritDoc} */
88          @Override
89          public final FloatScalar.Abs<U> immutable()
90          {
91              return new FloatScalar.Abs<U>(this);
92          }
93  
94          /** {@inheritDoc} */
95          @Override
96          public final int compareTo(final Abs<U> o)
97          {
98              return new Float(getSI()).compareTo(o.getSI());
99          }
100 
101         /** {@inheritDoc} */
102         @Override
103         public final MutableFloatScalar.Abs<U> copy()
104         {
105             return new MutableFloatScalar.Abs<U>(this);
106         }
107 
108         /**
109          * Increment the value by the supplied value and return the result.
110          * @param increment FloatScalar.Rel&lt;U&gt;; amount by which the value is incremented
111          * @return MutableFloatScalar.Abs&lt;U&gt;
112          */
113         public final MutableFloatScalar.Abs<U> incrementBy(final FloatScalar.Rel<U> increment)
114         {
115             return (MutableFloatScalar.Abs<U>) incrementByImpl(increment);
116         }
117 
118         /**
119          * Decrement the value by the supplied value and return the result.
120          * @param decrement FloatScalar.Rel&lt;U&gt;; amount by which the value is decremented
121          * @return MutableFloatScalar.Abs&lt;U&gt;
122          */
123         public final MutableFloatScalar.Abs<U> decrementBy(final FloatScalar.Rel<U> decrement)
124         {
125             return (MutableFloatScalar.Abs<U>) decrementByImpl(decrement);
126         }
127 
128         /**********************************************************************************/
129         /********************************** MATH METHODS **********************************/
130         /**********************************************************************************/
131 
132         /** {@inheritDoc} */
133         @Override
134         public final MutableFloatScalar.Abs<U> abs()
135         {
136             setValueSI(Math.abs(getSI()));
137             return this;
138         }
139 
140         /** {@inheritDoc} */
141         @Override
142         public final MutableFloatScalar.Abs<U> acos()
143         {
144             setValueSI((float) Math.acos(getSI()));
145             return this;
146         }
147 
148         /** {@inheritDoc} */
149         @Override
150         public final MutableFloatScalar.Abs<U> asin()
151         {
152             setValueSI((float) Math.asin(getSI()));
153             return this;
154         }
155 
156         /** {@inheritDoc} */
157         @Override
158         public final MutableFloatScalar.Abs<U> atan()
159         {
160             setValueSI((float) Math.atan(getSI()));
161             return this;
162         }
163 
164         /** {@inheritDoc} */
165         @Override
166         public final MutableFloatScalar.Abs<U> cbrt()
167         {
168             setValueSI((float) Math.cbrt(getSI()));
169             return this;
170         }
171 
172         /** {@inheritDoc} */
173         @Override
174         public final MutableFloatScalar.Abs<U> ceil()
175         {
176             setValueSI((float) Math.ceil(getSI()));
177             return this;
178         }
179 
180         /** {@inheritDoc} */
181         @Override
182         public final MutableFloatScalar.Abs<U> cos()
183         {
184             setValueSI((float) Math.cos(getSI()));
185             return this;
186         }
187 
188         /** {@inheritDoc} */
189         @Override
190         public final MutableFloatScalar.Abs<U> cosh()
191         {
192             setValueSI((float) Math.cosh(getSI()));
193             return this;
194         }
195 
196         /** {@inheritDoc} */
197         @Override
198         public final MutableFloatScalar.Abs<U> exp()
199         {
200             setValueSI((float) Math.exp(getSI()));
201             return this;
202         }
203 
204         /** {@inheritDoc} */
205         @Override
206         public final MutableFloatScalar.Abs<U> expm1()
207         {
208             setValueSI((float) Math.expm1(getSI()));
209             return this;
210         }
211 
212         /** {@inheritDoc} */
213         @Override
214         public final MutableFloatScalar.Abs<U> floor()
215         {
216             setValueSI((float) Math.floor(getSI()));
217             return this;
218         }
219 
220         /** {@inheritDoc} */
221         @Override
222         public final MutableFloatScalar.Abs<U> log()
223         {
224             setValueSI((float) Math.log(getSI()));
225             return this;
226         }
227 
228         /** {@inheritDoc} */
229         @Override
230         public final MutableFloatScalar.Abs<U> log10()
231         {
232             setValueSI((float) Math.log10(getSI()));
233             return this;
234         }
235 
236         /** {@inheritDoc} */
237         @Override
238         public final MutableFloatScalar.Abs<U> log1p()
239         {
240             setValueSI((float) Math.log1p(getSI()));
241             return this;
242         }
243 
244         /** {@inheritDoc} */
245         @Override
246         public final MutableFloatScalar.Abs<U> pow(final double x)
247         {
248             setValueSI((float) Math.pow(getSI(), x));
249             return this;
250         }
251 
252         /** {@inheritDoc} */
253         @Override
254         public final MutableFloatScalar.Abs<U> rint()
255         {
256             setValueSI((float) Math.rint(getSI()));
257             return this;
258         }
259 
260         /** {@inheritDoc} */
261         @Override
262         public final MutableFloatScalar.Abs<U> round()
263         {
264             setValueSI(Math.round(getSI()));
265             return this;
266         }
267 
268         /** {@inheritDoc} */
269         @Override
270         public final MutableFloatScalar.Abs<U> signum()
271         {
272             setValueSI(Math.signum(getSI()));
273             return this;
274         }
275 
276         /** {@inheritDoc} */
277         @Override
278         public final MutableFloatScalar.Abs<U> sin()
279         {
280             setValueSI((float) Math.sin(getSI()));
281             return this;
282         }
283 
284         /** {@inheritDoc} */
285         @Override
286         public final MutableFloatScalar.Abs<U> sinh()
287         {
288             setValueSI((float) Math.sinh(getSI()));
289             return this;
290         }
291 
292         /** {@inheritDoc} */
293         @Override
294         public final MutableFloatScalar.Abs<U> sqrt()
295         {
296             setValueSI((float) Math.sqrt(getSI()));
297             return this;
298         }
299 
300         /** {@inheritDoc} */
301         @Override
302         public final MutableFloatScalar.Abs<U> tan()
303         {
304             setValueSI((float) Math.tan(getSI()));
305             return this;
306         }
307 
308         /** {@inheritDoc} */
309         @Override
310         public final MutableFloatScalar.Abs<U> tanh()
311         {
312             setValueSI((float) Math.tanh(getSI()));
313             return this;
314         }
315 
316         /** {@inheritDoc} */
317         @Override
318         public final MutableFloatScalar.Abs<U> toDegrees()
319         {
320             setValueSI((float) Math.toDegrees(getSI()));
321             return this;
322         }
323 
324         /** {@inheritDoc} */
325         @Override
326         public final MutableFloatScalar.Abs<U> toRadians()
327         {
328             setValueSI((float) Math.toRadians(getSI()));
329             return this;
330         }
331 
332         /** {@inheritDoc} */
333         @Override
334         public final MutableFloatScalar.Abs<U> inv()
335         {
336             setValueSI(1.0f / getSI());
337             return this;
338         }
339 
340     }
341 
342     /**
343      * @param <U> Unit
344      */
345     public static class Rel<U extends Unit<U>> extends MutableFloatScalar<U> implements Relative, Comparable<Rel<U>>
346     {
347         /**  */
348         private static final long serialVersionUID = 20150309L;
349 
350         /**
351          * Construct a new Relative MutableFloatScalar.
352          * @param value float; the value of the new Relative MutableFloatScalar
353          * @param unit U; the unit of the new Relative MutableFloatScalar
354          */
355         public Rel(final float value, final U unit)
356         {
357             super(unit);
358             // System.out.println("Created Rel");
359             initialize(value);
360         }
361 
362         /**
363          * Construct a new Relative MutableFloatScalar from an existing Relative Immutable FloatScalar.
364          * @param value FloatScalar.Rel&lt;U&gt;; the reference
365          */
366         public Rel(final FloatScalar.Rel<U> value)
367         {
368             super(value.getUnit());
369             // System.out.println("Created Rel");
370             initialize(value);
371         }
372 
373         /**
374          * Construct a new Relative MutableFloatScalar from an existing Relative MutableFloatScalar.
375          * @param value MutableFloatScalar.Rel&lt;U&gt;; the reference
376          */
377         public Rel(final MutableFloatScalar.Rel<U> value)
378         {
379             super(value.getUnit());
380             // System.out.println("Created Rel");
381             initialize(value);
382         }
383 
384         /** {@inheritDoc} */
385         @Override
386         public final MutableFloatScalar.Rel<U> mutable()
387         {
388             return new MutableFloatScalar.Rel<U>(this);
389         }
390 
391         /** {@inheritDoc} */
392         @Override
393         public final FloatScalar.Rel<U> immutable()
394         {
395             return new FloatScalar.Rel<U>(this);
396         }
397 
398         /** {@inheritDoc} */
399         @Override
400         public final int compareTo(final Rel<U> o)
401         {
402             return new Float(getSI()).compareTo(o.getSI());
403         }
404 
405         /** {@inheritDoc} */
406         @Override
407         public final MutableFloatScalar.Rel<U> copy()
408         {
409             return new MutableFloatScalar.Rel<U>(this);
410         }
411 
412         /**
413          * Increment the value by the supplied value and return the result.
414          * @param increment FloatScalar.Rel&lt;U&gt;; amount by which the value is incremented
415          * @return MutableFloatScalar.Rel&lt;U&gt;
416          */
417         public final MutableFloatScalar.Rel<U> incrementBy(final FloatScalar.Rel<U> increment)
418         {
419             return (MutableFloatScalar.Rel<U>) incrementByImpl(increment);
420         }
421 
422         /**
423          * Decrement the value by the supplied value and return the result.
424          * @param decrement FloatScalar.Rel&lt;U&gt;; amount by which the value is decremented
425          * @return MutableFloatScalar.Rel&lt;U&gt;
426          */
427         public final MutableFloatScalar.Rel<U> decrementBy(final FloatScalar.Rel<U> decrement)
428         {
429             return (MutableFloatScalar.Rel<U>) decrementByImpl(decrement);
430         }
431 
432         /**********************************************************************************/
433         /********************************** MATH METHODS **********************************/
434         /**********************************************************************************/
435 
436         /** {@inheritDoc} */
437         @Override
438         public final MutableFloatScalar.Rel<U> abs()
439         {
440             setValueSI(Math.abs(getSI()));
441             return this;
442         }
443 
444         /** {@inheritDoc} */
445         @Override
446         public final MutableFloatScalar.Rel<U> acos()
447         {
448             setValueSI((float) Math.acos(getSI()));
449             return this;
450         }
451 
452         /** {@inheritDoc} */
453         @Override
454         public final MutableFloatScalar.Rel<U> asin()
455         {
456             setValueSI((float) Math.asin(getSI()));
457             return this;
458         }
459 
460         /** {@inheritDoc} */
461         @Override
462         public final MutableFloatScalar.Rel<U> atan()
463         {
464             setValueSI((float) Math.atan(getSI()));
465             return this;
466         }
467 
468         /** {@inheritDoc} */
469         @Override
470         public final MutableFloatScalar.Rel<U> cbrt()
471         {
472             setValueSI((float) Math.cbrt(getSI()));
473             return this;
474         }
475 
476         /** {@inheritDoc} */
477         @Override
478         public final MutableFloatScalar.Rel<U> ceil()
479         {
480             setValueSI((float) Math.ceil(getSI()));
481             return this;
482         }
483 
484         /** {@inheritDoc} */
485         @Override
486         public final MutableFloatScalar.Rel<U> cos()
487         {
488             setValueSI((float) Math.cos(getSI()));
489             return this;
490         }
491 
492         /** {@inheritDoc} */
493         @Override
494         public final MutableFloatScalar.Rel<U> cosh()
495         {
496             setValueSI((float) Math.cosh(getSI()));
497             return this;
498         }
499 
500         /** {@inheritDoc} */
501         @Override
502         public final MutableFloatScalar.Rel<U> exp()
503         {
504             setValueSI((float) Math.exp(getSI()));
505             return this;
506         }
507 
508         /** {@inheritDoc} */
509         @Override
510         public final MutableFloatScalar.Rel<U> expm1()
511         {
512             setValueSI((float) Math.expm1(getSI()));
513             return this;
514         }
515 
516         /** {@inheritDoc} */
517         @Override
518         public final MutableFloatScalar.Rel<U> floor()
519         {
520             setValueSI((float) Math.floor(getSI()));
521             return this;
522         }
523 
524         /** {@inheritDoc} */
525         @Override
526         public final MutableFloatScalar.Rel<U> log()
527         {
528             setValueSI((float) Math.log(getSI()));
529             return this;
530         }
531 
532         /** {@inheritDoc} */
533         @Override
534         public final MutableFloatScalar.Rel<U> log10()
535         {
536             setValueSI((float) Math.log10(getSI()));
537             return this;
538         }
539 
540         /** {@inheritDoc} */
541         @Override
542         public final MutableFloatScalar.Rel<U> log1p()
543         {
544             setValueSI((float) Math.log1p(getSI()));
545             return this;
546         }
547 
548         /** {@inheritDoc} */
549         @Override
550         public final MutableFloatScalar.Rel<U> pow(final double x)
551         {
552             setValueSI((float) Math.pow(getSI(), x));
553             return this;
554         }
555 
556         /** {@inheritDoc} */
557         @Override
558         public final MutableFloatScalar.Rel<U> rint()
559         {
560             setValueSI((float) Math.rint(getSI()));
561             return this;
562         }
563 
564         /** {@inheritDoc} */
565         @Override
566         public final MutableFloatScalar.Rel<U> round()
567         {
568             setValueSI(Math.round(getSI()));
569             return this;
570         }
571 
572         /** {@inheritDoc} */
573         @Override
574         public final MutableFloatScalar.Rel<U> signum()
575         {
576             setValueSI(Math.signum(getSI()));
577             return this;
578         }
579 
580         /** {@inheritDoc} */
581         @Override
582         public final MutableFloatScalar.Rel<U> sin()
583         {
584             setValueSI((float) Math.sin(getSI()));
585             return this;
586         }
587 
588         /** {@inheritDoc} */
589         @Override
590         public final MutableFloatScalar.Rel<U> sinh()
591         {
592             setValueSI((float) Math.sinh(getSI()));
593             return this;
594         }
595 
596         /** {@inheritDoc} */
597         @Override
598         public final MutableFloatScalar.Rel<U> sqrt()
599         {
600             setValueSI((float) Math.sqrt(getSI()));
601             return this;
602         }
603 
604         /** {@inheritDoc} */
605         @Override
606         public final MutableFloatScalar.Rel<U> tan()
607         {
608             setValueSI((float) Math.tan(getSI()));
609             return this;
610         }
611 
612         /** {@inheritDoc} */
613         @Override
614         public final MutableFloatScalar.Rel<U> tanh()
615         {
616             setValueSI((float) Math.tanh(getSI()));
617             return this;
618         }
619 
620         /** {@inheritDoc} */
621         @Override
622         public final MutableFloatScalar.Rel<U> toDegrees()
623         {
624             setValueSI((float) Math.toDegrees(getSI()));
625             return this;
626         }
627 
628         /** {@inheritDoc} */
629         @Override
630         public final MutableFloatScalar.Rel<U> toRadians()
631         {
632             setValueSI((float) Math.toRadians(getSI()));
633             return this;
634         }
635 
636         /** {@inheritDoc} */
637         @Override
638         public final MutableFloatScalar.Rel<U> inv()
639         {
640             setValueSI(1.0f / getSI());
641             return this;
642         }
643 
644     }
645 
646     /**
647      * Make (immutable) FloatScalar equivalent for any type of MutableFloatScalar. <br>
648      * The immutable version is created as a deep copy of this. Delayed copying is not worthwhile for a Scalar.
649      * @return FloatScalar&lt;U&gt;; immutable version of this FloatScalar
650      */
651     public abstract FloatScalar<U> immutable();
652 
653     /**
654      * Replace the stored value by the supplied value which is expressed in the standard SI unit.
655      * @param valueSI float; the value to store (value must already be in the standard SI unit)
656      */
657     final void setSI(final float valueSI)
658     {
659         setValueSI(valueSI);
660     }
661 
662     /**
663      * Replace the stored value by the supplied value.
664      * @param value FloatScalar&lt;U&gt;; the strongly typed value to store
665      */
666     final void set(final FloatScalar<U> value)
667     {
668         setValueSI(value.getSI());
669     }
670 
671     /**
672      * Replace the stored value by the supplied value which can be expressed in any compatible unit.
673      * @param value float; the value to store
674      * @param valueUnit U; the unit of the supplied value
675      */
676     final void setInUnit(final float value, final U valueUnit)
677     {
678         setValueSI((float) ValueUtil.expressAsSIUnit(value, valueUnit));
679     }
680 
681     /** {@inheritDoc} */
682     @Override
683     public final MutableFloatScalar<U> multiply(final float constant)
684     {
685         setValueSI(getSI() * constant);
686         return this;
687     }
688 
689     /** {@inheritDoc} */
690     @Override
691     public final MutableFloatScalar<U> divide(final float constant)
692     {
693         setValueSI(getSI() / constant);
694         return this;
695     }
696 
697     /**********************************************************************************/
698     /******************************* NON-STATIC METHODS *******************************/
699     /**********************************************************************************/
700 
701     /**
702      * Increment the value in this MutableFloatScalar by the value in a FloatScalar.
703      * @param increment FloatScalar&lt;U&gt;; the amount by which to increment the value in this MutableFloatScalar
704      * @return MutableFloatScalar&lt;U&gt;; this modified MutableFloatScalar
705      */
706     protected final MutableFloatScalar<U> incrementBy(final FloatScalar<U> increment)
707     {
708         setValueSI(getSI() + increment.getSI());
709         return this;
710     }
711 
712     /**
713      * Decrement the value in this MutableFloatScalar by the value in a FloatScalar.
714      * @param decrement FloatScalar&lt;U&gt;; the amount by which to decrement the value in this MutableFloatScalar
715      * @return MutableFloatScalar&lt;U&gt;; this modified MutableFloatScalar
716      */
717     protected final MutableFloatScalar<U> decrementBy(final FloatScalar<U> decrement)
718     {
719         setValueSI(getSI() - decrement.getSI());
720         return this;
721     }
722 
723     /**
724      * Increment the value in this MutableFloatScalar by the value in a Relative FloatScalar. <br>
725      * Only Relative values are allowed; adding an Absolute value to an Absolute value is not allowed. Adding an
726      * Absolute value to an existing Relative value would require the result to become Absolute, which is a type change
727      * that is impossible. For that operation use a static method.
728      * @param rel FloatScalar.Rel&lt;U&gt;; the Relative FloatScalar
729      * @return MutableFloatScalar&lt;U&gt;; this modified MutableFloatScalar
730      */
731     protected final MutableFloatScalar<U> incrementByImpl(final FloatScalar.Rel<U> rel)
732     {
733         setValueSI(getSI() + rel.getSI());
734         return this;
735     }
736 
737     /**
738      * Decrement the value of this Relative FloatScalar from the value of this MutableFloatScalar. <br>
739      * Only Relative values are allowed; subtracting an Absolute value from a Relative value is not allowed. Subtracting
740      * an Absolute value from an existing Absolute value would require the result to become Relative, which is a type
741      * change that is impossible. For that operation use a static method.
742      * @param rel FloatScalar.Rel&lt;U&gt;; the Relative FloatScalar
743      * @return MutableFloatScalar&lt;U&gt;; this modified MutableFloatScalar
744      */
745     protected final MutableFloatScalar<U> decrementByImpl(final FloatScalar.Rel<U> rel)
746     {
747         setValueSI(getSI() - rel.getSI());
748         return this;
749     }
750 
751 }