KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jscience > physics > quantities > Dimensionless


1 /*
2  * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
3  * Copyright (C) 2005 - JScience (http://jscience.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */

9 package org.jscience.physics.quantities;
10 import javolution.lang.MathLib;
11
12 import org.jscience.physics.units.SI;
13 import org.jscience.physics.units.Unit;
14
15 /**
16  * This class represents a dimensionless quantity. It contains methods for
17  * performing basic numeric operations such as the elementary exponential,
18  * logarithm and trigonometric functions.
19  *
20  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
21  * @version 1.0, October 24, 2004
22  */

23 public class Dimensionless extends Quantity {
24
25     /**
26      * Holds the associated unit.
27      */

28     private final static Unit<Dimensionless> UNIT = Unit.ONE;
29
30     /**
31      * Holds the factory for this class.
32      */

33     private final static Factory<Dimensionless> FACTORY = new Factory<Dimensionless>(
34             UNIT) {
35         protected Dimensionless create() {
36             return new Dimensionless();
37         }
38     };
39
40     /**
41      * Represents a {@link Dimensionless} amounting to nothing.
42      */

43     public final static Dimensionless ZERO = Quantity.valueOf(0, UNIT);
44
45     /**
46      * Represents a {@link Dimensionless} amounting to <code>1</code>.
47      */

48     public final static Dimensionless ONE = Quantity.valueOf(1, UNIT);
49
50     /**
51      * Holds the natural logarithmic base.
52      */

53     public static final Dimensionless e = Quantity.valueOf(MathLib.E, UNIT);
54
55     /**
56      * Default constructor (allows for derivation).
57      */

58     protected Dimensionless() {
59     }
60
61     /**
62      * Returns the dimensionless corresponding to the specified
63      * <code>doubleValue</code>
64      *
65      * @param doubleValue the double value.
66      */

67     public static Dimensionless valueOf(double doubleValue) {
68         return Quantity.valueOf(doubleValue, Unit.ONE);
69     }
70
71     /**
72      * Shows {@link Dimensionless} instances in the specified unit.
73      *
74      * @param unit the display unit for {@link Dimensionless} instances.
75      */

76     public static void showAs(Unit unit) {
77         QuantityFormat.show(Dimensionless.class, unit);
78     }
79
80
81     /////////////////////
82
// SCALAR SPECIFIC //
83
/////////////////////
84

85     /**
86      * Returns the exponential number <i>e</i> raised to the power of this
87      * {@link Dimensionless}.
88      *
89      * @return <code>exp(this)</code>
90      */

91     public Dimensionless exp() {
92         return Quantity.valueOf(
93             MathLib.exp(getMinimum()), MathLib.exp(getMaximum()), UNIT);
94     }
95
96     /**
97      * Returns the natural logarithm (base e) of this {@link Dimensionless}.
98      *
99      * @return <code>log(this)</code>
100      */

101     public Dimensionless log() {
102         return Quantity.valueOf(
103             MathLib.log(getMinimum()), MathLib.log(getMaximum()), UNIT);
104     }
105
106     /**
107      * Returns this {@link Dimensionless} raised to the power of the specified
108      * {@link Dimensionless} exponent.
109      *
110      * @param exp the exponent.
111      * @return <code>this**exp</code>
112      */

113     public Dimensionless pow(Dimensionless exp) {
114         Dimensionless system = to(Unit.ONE);
115         double min = system.getMinimum();
116         double max = system.getMaximum();
117         return Quantity.valueOf(
118             MathLib.pow(getMinimum(), exp.getMinimum()),
119             MathLib.pow(getMaximum(), exp.getMaximum()), UNIT);
120     }
121
122     /**
123      * Returns an {@link Angle} such as its sine is this {@link Dimensionless}.
124      *
125      * @return the arc sine of this angle.
126      */

127     public Angle asin() {
128         double min = getMinimum();
129         double max = getMaximum();
130         if (min < -1.0) {
131             min = -1;
132         }
133         if (max > 1.0) {
134             max = 1;
135         }
136         return Quantity.valueOf(
137             MathLib.asin(min), MathLib.asin(max), SI.RADIAN);
138     }
139
140     /**
141      * Returns an {@link Angle} such as its cosine is this {@link Dimensionless}.
142      *
143      * @return the arc cosine of this angle.
144      */

145     public Angle acos() {
146         double min = getMinimum();
147         double max = getMaximum();
148         if (min < -1.0) {
149             min = -1;
150         }
151         if (max > 1.0) {
152             max = 1;
153         }
154         return Quantity.valueOf(
155             MathLib.acos(max), MathLib.acos(min), SI.RADIAN);
156     }
157
158     /**
159      * Returns an {@link Angle} such as its tangent is this {@link Dimensionless}.
160      *
161      * @return the arc tangent of this angle
162      */

163     public Angle atan() {
164         return Angle.atan2(this, ONE);
165     }
166
167     private static final long serialVersionUID = 1L;
168 }
169
Popular Tags