View Javadoc
1   package org.djunits.quantity;
2   
3   import org.djunits.quantity.def.Quantity;
4   import org.djunits.unit.Unitless;
5   import org.djunits.unit.si.SIUnit;
6   
7   /**
8    * Dimensionless quantity.
9    * <p>
10   * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
11   * for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
12   * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
13   * @author Alexander Verbraeck
14   */
15  public class Dimensionless extends Quantity<Dimensionless>
16  {
17      /** Constant with value zero. */
18      public static final Dimensionless ZERO = ofSi(0.0);
19  
20      /** Constant with value one. */
21      public static final Dimensionless ONE = ofSi(1.0);
22  
23      /** Constant with value NaN. */
24      @SuppressWarnings("checkstyle:constantname")
25      public static final Dimensionless NaN = ofSi(Double.NaN);
26  
27      /** Constant with value POSITIVE_INFINITY. */
28      public static final Dimensionless POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
29  
30      /** Constant with value NEGATIVE_INFINITY. */
31      public static final Dimensionless NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
32  
33      /** Constant with value MAX_VALUE. */
34      public static final Dimensionless POS_MAXVALUE = ofSi(Double.MAX_VALUE);
35  
36      /** Constant with value -MAX_VALUE. */
37      public static final Dimensionless NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
38  
39      /** */
40      private static final long serialVersionUID = 600L;
41  
42      /**
43       * Instantiate a Dimensionless quantity with a unit.
44       * @param valueInUnit the value, expressed in the unit
45       * @param unit the unit in which the value is expressed
46       */
47      public Dimensionless(final double valueInUnit, final Unitless unit)
48      {
49          super(valueInUnit, unit);
50      }
51  
52      /**
53       * Return a Dimensionless instance based on an SI value.
54       * @param si the si value
55       * @return the Dimensionless instance based on an SI value
56       */
57      public static Dimensionless ofSi(final double si)
58      {
59          return new Dimensionless(si, Unitless.BASE);
60      }
61  
62      @Override
63      public Dimensionless instantiateSi(final double si)
64      {
65          return ofSi(si);
66      }
67  
68      @Override
69      public SIUnit siUnit()
70      {
71          return Unitless.SI_UNIT;
72      }
73  
74      /**
75       * Returns a Dimensionless representation of a textual representation of a value with a unit. The String representation that
76       * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
77       * allowed, but not required, between the value and the unit.
78       * @param text the textual representation to parse into a Dimensionless
79       * @return the Scalar representation of the value in its unit
80       * @throws IllegalArgumentException when the text cannot be parsed
81       * @throws NullPointerException when the text argument is null
82       */
83      public static Dimensionless valueOf(final String text)
84      {
85          return Quantity.valueOf(text, ZERO);
86      }
87  
88      /**
89       * Returns a Dimensionless based on a value and the textual representation of the unit, which can be localized.
90       * @param valueInUnit the value, expressed in the unit as given by unitString
91       * @param unitString the textual representation of the unit
92       * @return the Scalar representation of the value in its unit
93       * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
94       * @throws NullPointerException when the unitString argument is null
95       */
96      public static Dimensionless of(final double valueInUnit, final String unitString)
97      {
98          return Quantity.of(valueInUnit, unitString, ZERO);
99      }
100 
101     @Override
102     public Unitless getDisplayUnit()
103     {
104         return (Unitless) super.getDisplayUnit();
105     }
106 
107     /**
108      * Calculate the division of Dimensionless and Dimensionless, which results in a Dimensionless quantity.
109      * @param v quantity
110      * @return quantity as a division of Dimensionless and Dimensionless
111      */
112     public final Dimensionless divide(final Dimensionless v)
113     {
114         return new Dimensionless(this.si() / v.si(), Unitless.BASE);
115     }
116 
117     /**
118      * Calculate the division of Dimensionless and Length, which results in a LinearObjectDensity scalar.
119      * @param v scalar
120      * @return scalar as a division of Dimensionless and Length
121      */
122     public final LinearObjectDensity divide(final Length v)
123     {
124         return new LinearObjectDensity(this.si() / v.si(), LinearObjectDensity.Unit.SI);
125     }
126 
127     /**
128      * Calculate the division of Dimensionless and LinearObjectDensity, which results in a Length scalar.
129      * @param v scalar
130      * @return scalar as a division of Dimensionless and LinearObjectDensity
131      */
132     public final Length divide(final LinearObjectDensity v)
133     {
134         return new Length(this.si() / v.si(), Length.Unit.SI);
135     }
136 
137     /**
138      * Calculate the division of Dimensionless and Duration, which results in a Frequency scalar.
139      * @param v scalar
140      * @return scalar as a division of Dimensionless and Duration
141      */
142     public final Frequency divide(final Duration v)
143     {
144         return new Frequency(this.si() / v.si(), Frequency.Unit.SI);
145     }
146 
147     /**
148      * Calculate the division of Dimensionless and Frequency, which results in a Duration scalar.
149      * @param v scalar
150      * @return scalar as a division of Dimensionless and Frequency
151      */
152     public final Duration divide(final Frequency v)
153     {
154         return new Duration(this.si() / v.si(), Duration.Unit.SI);
155     }
156 
157     /**
158      * Calculate the division of Dimensionless and ElectricalConductance, which results in a ElectricalResistance scalar.
159      * @param v scalar
160      * @return scalar as a division of Dimensionless and ElectricalConductance
161      */
162     public final ElectricalResistance divide(final ElectricalConductance v)
163     {
164         return new ElectricalResistance(this.si() / v.si(), ElectricalResistance.Unit.SI);
165     }
166 
167     /**
168      * Calculate the division of Dimensionless and ElectricalResistance, which results in a ElectricalConductance scalar.
169      * @param v scalar
170      * @return scalar as a division of Dimensionless and ElectricalResistance
171      */
172     public final ElectricalConductance divide(final ElectricalResistance v)
173     {
174         return new ElectricalConductance(this.si() / v.si(), ElectricalConductance.Unit.SI);
175     }
176 
177     @Override
178     public Dimensionless reciprocal()
179     {
180         return ofSi(1.0 / this.si());
181     }
182 
183 }