Java Doc for NumberUtils.java in  » Library » Apache-common-lang » org » apache » commons » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common lang » org.apache.commons.lang 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.lang.NumberUtils

NumberUtils
final public class NumberUtils (Code)

Provides extra functionality for Java Number classes.


author:
   Rand McNeely
author:
   Stephen Colebourne
author:
   Steve Downey
author:
   Eric Pugh
author:
   Phil Steitz
since:
   1.0
version:
   $Id: NumberUtils.java 488819 2006-12-19 21:50:04Z bayard $



Constructor Summary
public  NumberUtils()
    

NumberUtils instances should NOT be constructed in standard programming.


Method Summary
public static  intcompare(double lhs, double rhs)
    

Compares two doubles for order.

This method is more comprehensive than the standard Java greater than, less than and equals operators.

  • It returns -1 if the first value is less than the second.
public static  intcompare(float lhs, float rhs)
    

Compares two floats for order.

This method is more comprehensive than the standard Java greater than, less than and equals operators.

  • It returns -1 if the first value is less than the second.
public static  BigDecimalcreateBigDecimal(String val)
    
public static  BigIntegercreateBigInteger(String val)
    
public static  DoublecreateDouble(String val)
    
public static  FloatcreateFloat(String val)
    
public static  IntegercreateInteger(String val)
    
public static  LongcreateLong(String val)
    
public static  NumbercreateNumber(String val)
    

Turns a string value into a java.lang.Number.

First, the value is examined for a type qualifier on the end ('f','F','d','D','l','L').

public static  booleanisDigits(String str)
    
public static  booleanisNumber(String str)
    

Checks whether the String a valid Java number.

Valid numbers include hexadecimal marked with the 0x qualifier, scientific notation and numbers marked with a type qualifier (e.g.

public static  longmaximum(long a, long b, long c)
    
public static  intmaximum(int a, int b, int c)
    
public static  longminimum(long a, long b, long c)
    
public static  intminimum(int a, int b, int c)
    
public static  intstringToInt(String str)
    
public static  intstringToInt(String str, int defaultValue)
    


Constructor Detail
NumberUtils
public NumberUtils()(Code)

NumberUtils instances should NOT be constructed in standard programming. Instead, the class should be used as NumberUtils.stringToInt("6");.

This constructor is public to permit tools that require a JavaBean instance to operate.





Method Detail
compare
public static int compare(double lhs, double rhs)(Code)

Compares two doubles for order.

This method is more comprehensive than the standard Java greater than, less than and equals operators.

  • It returns -1 if the first value is less than the second.
  • It returns +1 if the first value is greater than the second.
  • It returns 0 if the values are equal.

The ordering is as follows, largest to smallest:

  • NaN
  • Positive infinity
  • Maximum double
  • Normal positive numbers
  • +0.0
  • -0.0
  • Normal negative numbers
  • Minimum double (-Double.MAX_VALUE)
  • Negative infinity

Comparing NaN with NaN will return 0.


Parameters:
  lhs - the first double
Parameters:
  rhs - the second double -1 if lhs is less, +1 if greater,0 if equal to rhs



compare
public static int compare(float lhs, float rhs)(Code)

Compares two floats for order.

This method is more comprehensive than the standard Java greater than, less than and equals operators.

  • It returns -1 if the first value is less than the second.
  • It returns +1 if the first value is greater than the second.
  • It returns 0 if the values are equal.

The ordering is as follows, largest to smallest:

  • NaN
  • Positive infinity
  • Maximum float
  • Normal positive numbers
  • +0.0
  • -0.0
  • Normal negative numbers
  • Minimum float (-Float.MAX_VALUE)
  • Negative infinity

Comparing NaN with NaN will return 0.


Parameters:
  lhs - the first float
Parameters:
  rhs - the second float -1 if lhs is less, +1 if greater,0 if equal to rhs



createBigDecimal
public static BigDecimal createBigDecimal(String val)(Code)

Convert a String to a BigDecimal.


Parameters:
  val - a String to convert converted BigDecimal
throws:
  NumberFormatException - if the value cannot be converted



createBigInteger
public static BigInteger createBigInteger(String val)(Code)

Convert a String to a BigInteger.


Parameters:
  val - a String to convert converted BigInteger
throws:
  NumberFormatException - if the value cannot be converted



createDouble
public static Double createDouble(String val)(Code)

Convert a String to a Double.


Parameters:
  val - a String to convert converted Double
throws:
  NumberFormatException - if the value cannot be converted



createFloat
public static Float createFloat(String val)(Code)

Convert a String to a Float.


Parameters:
  val - a String to convert converted Float
throws:
  NumberFormatException - if the value cannot be converted



createInteger
public static Integer createInteger(String val)(Code)

Convert a String to a Integer, handling hex and octal notations.


Parameters:
  val - a String to convert converted Integer
throws:
  NumberFormatException - if the value cannot be converted



createLong
public static Long createLong(String val)(Code)

Convert a String to a Long.


Parameters:
  val - a String to convert converted Long
throws:
  NumberFormatException - if the value cannot be converted



createNumber
public static Number createNumber(String val) throws NumberFormatException(Code)

Turns a string value into a java.lang.Number.

First, the value is examined for a type qualifier on the end ('f','F','d','D','l','L'). If it is found, it starts trying to create successively larger types from the type specified until one is found that can hold the value.

If a type specifier is not found, it will check for a decimal point and then try successively larger types from Integer to BigInteger and from Float to BigDecimal.

If the string starts with 0x or -0x, it will be interpreted as a hexadecimal integer. Values with leading 0's will not be interpreted as octal.


Parameters:
  val - String containing a number Number created from the string
throws:
  NumberFormatException - if the value cannot be converted



isDigits
public static boolean isDigits(String str)(Code)

Checks whether the String contains only digit characters.

Null and empty String will return false.


Parameters:
  str - the String to check true if str contains only unicode numeric



isNumber
public static boolean isNumber(String str)(Code)

Checks whether the String a valid Java number.

Valid numbers include hexadecimal marked with the 0x qualifier, scientific notation and numbers marked with a type qualifier (e.g. 123L).

Null and empty String will return false.


Parameters:
  str - the String to check true if the string is a correctly formatted number



maximum
public static long maximum(long a, long b, long c)(Code)

Gets the maximum of three long values.


Parameters:
  a - value 1
Parameters:
  b - value 2
Parameters:
  c - value 3 the largest of the values



maximum
public static int maximum(int a, int b, int c)(Code)

Gets the maximum of three int values.


Parameters:
  a - value 1
Parameters:
  b - value 2
Parameters:
  c - value 3 the largest of the values



minimum
public static long minimum(long a, long b, long c)(Code)

Gets the minimum of three long values.


Parameters:
  a - value 1
Parameters:
  b - value 2
Parameters:
  c - value 3 the smallest of the values



minimum
public static int minimum(int a, int b, int c)(Code)

Gets the minimum of three int values.


Parameters:
  a - value 1
Parameters:
  b - value 2
Parameters:
  c - value 3 the smallest of the values



stringToInt
public static int stringToInt(String str)(Code)

Convert a String to an int, returning zero if the conversion fails.


Parameters:
  str - the string to convert the int represented by the string, or zero ifconversion fails



stringToInt
public static int stringToInt(String str, int defaultValue)(Code)

Convert a String to an int, returning a default value if the conversion fails.


Parameters:
  str - the string to convert
Parameters:
  defaultValue - the default value the int represented by the string, or the default if conversion fails



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.