org.jscience.physics.amount

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 » Science » jscience 4.3.1 » org.jscience.physics.amount 
org.jscience.physics.amount

Provides support for exact or arbitrary precision measurements.

Amount as {@link javax.measure.Measurable measurable} quantity:

The {@link org.jscience.physics.amount.Amount Amount} base class is parameterized with the quantity onto which the measure applies (Amount<Q extends Quantity>). If the quantity is not known then <?> can be used. For example:[code] Amount carMileage = Amount.valueOf(20, MILE.divide(GALLON_LIQUID_US)); Amount gazPrice = Amount.valueOf(1.2, EUR.divide(LITER)); // 1.2 €/L [/code] If the expected quantity result for a measure is known but has been lost due to the calculations performed; better than using <?>, the measure can be stated in a known unit for this quantity. It ensures dynamic check of the measure dimension/unit and avoid compiler warnings. For example:[code] // No problem here as the measure type is infered from the unit. Amount tripDistance = Amount.valueOf(400, KILO(SI.METRE)); // Warning as the measure type is lost during calculation. Amount tripCost = tripDistance.divide(carMileage).times(gazPrice); // Better: Dimension check and no warning (USD is a Currency (Unit)) Amount tripCost = tripDistance.divide(carMileage).times(gazPrice).to(USD); [/code] It should be noted that this conversion is immediate if the specified unit is the actual unit for the amount (which is then returned unchanged).

Error calculations:

Amount take into account measurement and calculation errors. For example:[code] import static org.jscience.physics.units.SI.*; ... Amount x = Amount.valueOf(1.0, METRE); Amount v = Amount.valueOf(0.01, METRE_PER_SECOND); Amount t = Amount.valueOf(1.0, MICRO(SECOND)); for (int i = 0; i < 10000000; i++) { x = x.plus(v.times(t)); } AmountFormat.setInstance(AmountFormat.getExactDigitsInstance()); System.out.println(x); > 1.10000000 m The exact value is guaranteed to be in the range: ]1.09999999 m, 1.10000001 m[ The same calculation using primitive double type would have display: > 1.099999999392253 with no idea on the accuracy of the result.[/code]

Dimension checking.

The unit of an amount determinates its type. For example, Amount.valueOf("1 µm") and Amount.valueOf("1.2 ft") are Length amounts (both "µm" and "ft" units are derived from SI.METRE). Multiple physical models are supported (e.g. Standard, Relativistic, High-Energy, Quantum and Natural). The physical model sets which conversions are allowed or disallowed. For example:[code] RelativisticModel.select(); // Selects a relativistic model. Amount x = Amount.valueOf(100, NonSI.INCH); x = x.plus(Amount.valueOf("2.3 µs")).to(METRE); // Length and Duration can be added. Amount m = Amount.valueOf("12 GeV").to(KILOGRAM); // Energy is compatible with mass (E=mc2) System.out.println(x); System.out.println(m); > (692.06265340000008 ± 5.1E-13) m > (2.1391940763025056E-26 ± 4.3E-42) kg[/code]

Physical Constants

Finally, this package holds the latest physical {@link org.jscience.physics.amount.Constants constants} measurements with the best known accuracy (the more accurate the constant, the higher the precision of the calculations making use of these constants).
Java Source File NameTypeComment
Amount.javaClass

This class represents a determinate or estimated amount for which operations such as addition, subtraction, multiplication and division can be performed (it implements the Field interface).

The nature of an amount can be deduced from its parameterization (compile time) or its Amount.getUnit() unit (run time). Its precision is given by its Amount.getAbsoluteError() error .

Amounts can be Amount.isExact() exact , in which case they can be expressed as an exact long integer in the amount unit. The framework tries to keep amount exact as much as possible. For example:[code] Amount m = Amount.valueOf(33, FOOT).divide(11).times(2); System.out.println(m); System.out.println(m.isExact() ? "exact" : "inexact"); System.out.println(m.getExactValue()); > 6 ft > exact > 6[/code]

Errors (including numeric errors) are calculated using numeric intervals. It is possible to resolve systems of linear equations involving org.jscience.mathematics.vector.Matrix matrices , even if the system is close to singularity; in which case the error associated with some (or all) components of the solution may be large.

By default, non-exact amounts are shown using the plus/minus character ('±') (see AmountFormat ).

AmountException.javaClass Signals that an illegal measure operation has been performed.
AmountFormat.javaClass

This class provides the interface for formatting and parsing Amount measures instances.

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