View Javadoc
1   package org.djunits.value.vfloat.scalar.base;
2   
3   import org.djunits.unit.AbsoluteLinearUnit;
4   import org.djunits.unit.Unit;
5   import org.djunits.value.Absolute;
6   
7   /**
8    * The typed, abstract FloatScalarAbs class that forms the basis of all FloatScalar definitions and extensions.<br>
9    * Note: A relative scalar class can implement the toAbs() method if it has an absolute equivalent.
10   * <p>
11   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
13   * </p>
14   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
16   * @param <AU> the absolute unit
17   * @param <A> the Absolute class for reference purposes
18   * @param <RU> the relative unit
19   * @param <R> the Relative class for reference purposes
20   */
21  public abstract class FloatScalarAbs<AU extends AbsoluteLinearUnit<AU, RU>, A extends FloatScalarAbs<AU, A, RU, R>,
22          RU extends Unit<RU>, R extends FloatScalarRelWithAbs<AU, A, RU, R>> extends FloatScalar<AU, A>
23          implements Absolute<AU, A, RU, R>
24  {
25      /**  */
26      private static final long serialVersionUID = 20150626L;
27  
28      /**
29       * Construct a new Absolute Immutable FloatScalar.
30       * @param value the value of the new Absolute Immutable FloatScalar
31       * @param unit the unit of the new Absolute Immutable FloatScalar
32       */
33      public FloatScalarAbs(final float value, final AU unit)
34      {
35          super(value, unit);
36      }
37  
38      /**
39       * Construct a new Absolute Immutable FloatScalar from an existing Absolute Immutable FloatScalar.
40       * @param value the reference
41       */
42      public FloatScalarAbs(final A value)
43      {
44          super(value);
45      }
46  
47      /**
48       * Construct a new Relative Immutable FloatScalar of the right type. Each extending class must implement this method.
49       * @param value the float value
50       * @param unit the unit
51       * @return R a new relative instance of the FloatScalar of the right type
52       */
53      public abstract R instantiateRel(float value, RU unit);
54  
55      /**
56       * Construct a new Absolute Immutable FloatScalar of the right type. Each extending class must implement this method.
57       * @param value the float value
58       * @param unit the absolute unit
59       * @return A a new absolute instance of the FloatScalar of the right type
60       */
61      public abstract A instantiateAbs(float value, AU unit);
62  
63      @Override
64      public final A plus(final R increment)
65      {
66          AU targetUnit = getDisplayUnit();
67          return instantiateAbs(getInUnit() + increment.getInUnit(targetUnit.getRelativeUnit()), targetUnit);
68      }
69  
70      @Override
71      public final A minus(final R decrement)
72      {
73          AU targetUnit = getDisplayUnit();
74          return instantiateAbs(getInUnit() - decrement.getInUnit(targetUnit.getRelativeUnit()), targetUnit);
75      }
76  
77      @Override
78      public final R minus(final A decrement)
79      {
80          RU targetUnit = getDisplayUnit().getRelativeUnit();
81          return instantiateRel(getInUnit() - decrement.getInUnit(getDisplayUnit()), targetUnit);
82      }
83  
84      /**********************************************************************************/
85      /********************************** MATH METHODS **********************************/
86      /**********************************************************************************/
87  
88      @Override
89      @SuppressWarnings("checkstyle:designforextension")
90      public A abs()
91      {
92          return instantiateAbs(Math.abs(getInUnit()), getDisplayUnit());
93      }
94  
95      @Override
96      @SuppressWarnings("checkstyle:designforextension")
97      public A ceil()
98      {
99          return instantiateAbs((float) Math.ceil(getInUnit()), getDisplayUnit());
100     }
101 
102     @Override
103     @SuppressWarnings("checkstyle:designforextension")
104     public A floor()
105     {
106         return instantiateAbs((float) Math.floor(getInUnit()), getDisplayUnit());
107     }
108 
109     @Override
110     @SuppressWarnings("checkstyle:designforextension")
111     public A neg()
112     {
113         return instantiateAbs(-getInUnit(), getDisplayUnit());
114     }
115 
116     @Override
117     @SuppressWarnings("checkstyle:designforextension")
118     public A rint()
119     {
120         return instantiateAbs((float) Math.rint(getInUnit()), getDisplayUnit());
121     }
122 
123 }