KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > util > MathUtil


1 /*
2  * MathUtil, utility class for math operations.
3  * Copyright (C) Achim Westermann, created on 09.09.2004, 12:38:21
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * If you modify or optimize the code in a useful way please let me know.
20  * Achim.Westermann@gmx.de
21  *
22  */

23 package info.monitorenter.util;
24
25 /**
26  * Static helpers for working with numbers.
27  * <p>
28  * Maybe not always the fastest solution to call in here, but working. Also
29  * usable for seeing examples and cutting code for manual inlining.
30  * <p>
31  *
32  * @author Achim.Westermann@gmx.de
33  *
34  * @version $Revision: 1.1 $
35  */

36 public final class MathUtil {
37   /** Singleton instance. */
38   private static MathUtil instance = null;
39
40   /**
41    * Returns the singleton instance of this class.
42    * <p>
43    *
44    * This method is useless for now as all methods are static. It may be used in
45    * future if VM-global configuration will be put to the state of the instance.
46    * <p>#
47    *
48    * @return the singleton instance of this class.
49    */

50   public static MathUtil getInstance() {
51     if (MathUtil.instance == null) {
52       MathUtil.instance = new MathUtil();
53     }
54     return MathUtil.instance;
55   }
56
57   /**
58    * Asserts that the given double is not invalid for calculation.
59    * <p>
60    * It must not be one of:
61    * <ul>
62    * <li> {@link Double#NaN} </li>
63    * <li> {@link Double#NEGATIVE_INFINITY} </li>
64    * <li> {@link Double#POSITIVE_INFINITY} </li>
65    * </ul>
66    * <p>
67    *
68    * @param d
69    * the double to test.
70    *
71    * @throws IllegalArgumentException
72    * if the assertion fails.
73    */

74   public static void assertDouble(final double d) throws IllegalArgumentException JavaDoc {
75     if (Double.isInfinite(d) || Double.isNaN(d)) {
76       throw new IllegalArgumentException JavaDoc(d + " is not valid.");
77     }
78   }
79
80   /**
81    * Avoids creation from outside for singleton support.
82    * <p>
83    *
84    */

85   private MathUtil() {
86     // nop
87
}
88 }
89
Popular Tags