Monetary values are a key feature of many applications, yet the JDK provides little or no support. The existing java.util.Currency class is strictly a structure used for representing ISO-4217 currencies, but not associated values or custom currencies. It also provides no support for arithmetic or currency conversion, nor for a standard value type to represent a monetary amount. JSR 354: Money and Currency API aims to address this by introducing new types for money and currency. The JSR aims to address a wide range of general-purpose cases while being suitable for many domain cases; it provides formatting, foreign exchange, rounding, arithmetic, and strong typing. This session describes the motivation, use cases, and implementation of the API.
Introduction to JSR 354 (Currency and Money) by Anatole TreschCodemotion
The presentation introduces JSR 354 (Java Currency and Money). As a start the presentation will discuss some considerations done regarding numeric precision and will also strive some possible issues with the ISO 4217 currency standard. The second part presents the JSR’s API for representing and manipulating monetary amounts in different currencies (including virtual ones), currency conversion, complex rounding, formatting/parsing and more. Finally a running demo of the JSR 354 reference implementation shows things in action.
Money, Money, Money, can be funny with JSR 354 (DWX 2019)Werner Keil
Maintenance Leads Werner Keil and Anatole Tresch will present JSR 354 (Money and Currency). They will discuss the API from a developer as well as user perspective and share details on the design decisions behind the JSR.
Monetary values are a key feature of many applications, yet the JDK provides little or no support. The existing java.util.Currency class is strictly a structure used for representing current ISO-4217 currencies, but not associated values or custom currencies. The JDK also provides no support for monetary arithmetic or currency conversion, nor for a standard value type to represent a monetary amount.
The session will demonstrate how the JSR models monetary capabilities, monetary amounts, currencies, rounding, financial arithmetics as well as formatting and currency conversion in a platform independent and flexible manner. The first part of the talk will focus on key concepts, improvements like Java 9/Jigsaw modularity and planned new features for a future release followed by a live coding session demonstrating the Money JSR in action.
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner KeilCodemotion
The presentation introduces JSR 354 (Java Currency and Money). It is shown how the JSR allows to flexible represent and manipulate monetary
amounts in different currencies (including virtual ones). The presentation will discuss some considerations done according to numeric precision.
Finally the presentation will also discuss more advanced usage scenarios such as currency exchange, complex rounding and formatting parsing.
Also included is a running demo that uses the specification in a EE context and also illustrates some of the SPIs defined.
Introduction to JSR 354 (Currency and Money) by Anatole TreschCodemotion
The presentation introduces JSR 354 (Java Currency and Money). As a start the presentation will discuss some considerations done regarding numeric precision and will also strive some possible issues with the ISO 4217 currency standard. The second part presents the JSR’s API for representing and manipulating monetary amounts in different currencies (including virtual ones), currency conversion, complex rounding, formatting/parsing and more. Finally a running demo of the JSR 354 reference implementation shows things in action.
Money, Money, Money, can be funny with JSR 354 (DWX 2019)Werner Keil
Maintenance Leads Werner Keil and Anatole Tresch will present JSR 354 (Money and Currency). They will discuss the API from a developer as well as user perspective and share details on the design decisions behind the JSR.
Monetary values are a key feature of many applications, yet the JDK provides little or no support. The existing java.util.Currency class is strictly a structure used for representing current ISO-4217 currencies, but not associated values or custom currencies. The JDK also provides no support for monetary arithmetic or currency conversion, nor for a standard value type to represent a monetary amount.
The session will demonstrate how the JSR models monetary capabilities, monetary amounts, currencies, rounding, financial arithmetics as well as formatting and currency conversion in a platform independent and flexible manner. The first part of the talk will focus on key concepts, improvements like Java 9/Jigsaw modularity and planned new features for a future release followed by a live coding session demonstrating the Money JSR in action.
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner KeilCodemotion
The presentation introduces JSR 354 (Java Currency and Money). It is shown how the JSR allows to flexible represent and manipulate monetary
amounts in different currencies (including virtual ones). The presentation will discuss some considerations done according to numeric precision.
Finally the presentation will also discuss more advanced usage scenarios such as currency exchange, complex rounding and formatting parsing.
Also included is a running demo that uses the specification in a EE context and also illustrates some of the SPIs defined.
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Rajmahendra Hegde
For the long time, we have used various build tools to package applications for new software releases or applying patches to existing applications etc. dependency management, version controlling, scalability, flexibility, single-multiple projects sup portability are some of the key areas that drove the selection of a build tool, This session focuses on Gradle as a successful build tool and looks into all the above areas and uses Groovy as a DSL. We will also look into how easy it is to use Gradle as compared to other open source build tools.
Photos: https://plus.google.com/u/0/photos/105295086916869617504/albums/5739617166453582993
Gradle build tool that rocks with DSL By Rajmahendra Hegde at JavaOne Hyderabad, India on 4th May 2012
If you are inspired during practical and hands-on sessions during the three days at Devoxx UK 2015, have you thought about how you might pass on this knowledge and experience to others? If so, then we have just the right solution for you! Running a Hackday, either at your workplace or within your local community, can be very rewarding. Come along to this session and learn all about the art of running hack session from Richard Warburton, author of Java 8 Lambda and regular organiser of hackdays in the London Java Community.
You will be able to answer your own questions like: Why you should run a hackday ? What’s involved in running one ? Examples of successful hackdays Tips for being successful
Writing a "Hello World!” application is always easy, and a Java developer can learn how to write it with JavaFX in some minutes. But if you want to create a productive application, knowledge of "Hello World!” isn't enough. A real application should be well structured, provide an automatic build that ends in usable artifacts, and contain only needed dependencies. In addition, such an application should be testable and maintainable. This session presents some general concepts regarding how you can create and structure a JavaFX application that can easily grow and become more complex without losing control of the code, functionality, and maintainability. At the end, each attendee will have a template to use to start creating JavaFX-based applications.
The presentation introduces JSR 354 (Currency and Money). It will discuss the API from a user perspective, and gives details on the design decisions done. The presentation will demonstrate how the JSR models monetary capabilities, monetary amounts, currencies, roundings, financial arithmetics as well as formatting and currency conversion in a platform independent and flexible way.
The presentation is targeting more advanced developers being interested in modeling financial concerns in Java and advanced API design in general.
JSR 354: Money and Currency API - Short OverviewWerner Keil
JavaMoney is the new monetary API for the Java™ Platform as well as related projects and libraries. Whereas the API (JSR 354) provides a portable and extendible API for handling of Money & Currency models, Moneta provides a production ready reference implementation.
The JavaMoney libraries add additional functionalities that were built on top of the API such as
- Basic financial operations
- Rounding
- Currency conversion
- Extended formatting (usable for arbitrary types)
Smartphone Behavior On A Featurephone BudgetGail Frederick
JavaOne 2009 BoF Presentation
Mobile application features typical in smartphones can also be implemented on mass-market featurephones using Java ME and Web 2.0 back-end services. In this presentation, we explore the multimodality and rich user interface of a search-driven portal application written in Java ME and broadly ported to mass-market featurephones. Multimodality enables the user to search, browse and discover using familiar activities on a mobile device - saying a phrase, entering text and snapping a photo.
Snippets of Java ME code used to implement voice recording, image capture, location awareness and advanced mapping are presented and analyzed.
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Rajmahendra Hegde
For the long time, we have used various build tools to package applications for new software releases or applying patches to existing applications etc. dependency management, version controlling, scalability, flexibility, single-multiple projects sup portability are some of the key areas that drove the selection of a build tool, This session focuses on Gradle as a successful build tool and looks into all the above areas and uses Groovy as a DSL. We will also look into how easy it is to use Gradle as compared to other open source build tools.
Photos: https://plus.google.com/u/0/photos/105295086916869617504/albums/5739617166453582993
Gradle build tool that rocks with DSL By Rajmahendra Hegde at JavaOne Hyderabad, India on 4th May 2012
If you are inspired during practical and hands-on sessions during the three days at Devoxx UK 2015, have you thought about how you might pass on this knowledge and experience to others? If so, then we have just the right solution for you! Running a Hackday, either at your workplace or within your local community, can be very rewarding. Come along to this session and learn all about the art of running hack session from Richard Warburton, author of Java 8 Lambda and regular organiser of hackdays in the London Java Community.
You will be able to answer your own questions like: Why you should run a hackday ? What’s involved in running one ? Examples of successful hackdays Tips for being successful
Writing a "Hello World!” application is always easy, and a Java developer can learn how to write it with JavaFX in some minutes. But if you want to create a productive application, knowledge of "Hello World!” isn't enough. A real application should be well structured, provide an automatic build that ends in usable artifacts, and contain only needed dependencies. In addition, such an application should be testable and maintainable. This session presents some general concepts regarding how you can create and structure a JavaFX application that can easily grow and become more complex without losing control of the code, functionality, and maintainability. At the end, each attendee will have a template to use to start creating JavaFX-based applications.
The presentation introduces JSR 354 (Currency and Money). It will discuss the API from a user perspective, and gives details on the design decisions done. The presentation will demonstrate how the JSR models monetary capabilities, monetary amounts, currencies, roundings, financial arithmetics as well as formatting and currency conversion in a platform independent and flexible way.
The presentation is targeting more advanced developers being interested in modeling financial concerns in Java and advanced API design in general.
JSR 354: Money and Currency API - Short OverviewWerner Keil
JavaMoney is the new monetary API for the Java™ Platform as well as related projects and libraries. Whereas the API (JSR 354) provides a portable and extendible API for handling of Money & Currency models, Moneta provides a production ready reference implementation.
The JavaMoney libraries add additional functionalities that were built on top of the API such as
- Basic financial operations
- Rounding
- Currency conversion
- Extended formatting (usable for arbitrary types)
Smartphone Behavior On A Featurephone BudgetGail Frederick
JavaOne 2009 BoF Presentation
Mobile application features typical in smartphones can also be implemented on mass-market featurephones using Java ME and Web 2.0 back-end services. In this presentation, we explore the multimodality and rich user interface of a search-driven portal application written in Java ME and broadly ported to mass-market featurephones. Multimodality enables the user to search, browse and discover using familiar activities on a mobile device - saying a phrase, entering text and snapping a photo.
Snippets of Java ME code used to implement voice recording, image capture, location awareness and advanced mapping are presented and analyzed.
Refactoring Large Web Applications with Backbone.jsStacy London
Have you ever starting working on a large, existing web application and jQuery spaghetti-code is all over the place? Your mind swirls as you try to figure out what code belongs to what component on what page. There are no JavaScript unit tests and you're terrified of making a change and breaking everything? I'm going to talk through the real life story of how Backbone.js helped to bring organization/structure, modularity, and testability to a large multi-page web application.
Refactor to Reactive With Spring 5 and Project ReactorEatDog
Доклад Олега Докуки для Съесть собаку #11: Java, 21/12/2017.
Тезисы:
- Проблемный обзор не реактивных приложений;
- Обзор реактивной архитектуры;
- Spring 5 в качестве ключевого решения;
- Spring 4 to Spring 5: пошаговый рефакторинг;
- Анализ результатов
- Демо.
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
20 Comprehensive Checklist of Designing and Developing a WebsitePixlogix Infotech
Dive into the world of Website Designing and Developing with Pixlogix! Looking to create a stunning online presence? Look no further! Our comprehensive checklist covers everything you need to know to craft a website that stands out. From user-friendly design to seamless functionality, we've got you covered. Don't miss out on this invaluable resource! Check out our checklist now at Pixlogix and start your journey towards a captivating online presence today.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Climate Impact of Software Testing at Nordic Testing DaysKari Kakkonen
My slides at Nordic Testing Days 6.6.2024
Climate impact / sustainability of software testing discussed on the talk. ICT and testing must carry their part of global responsibility to help with the climat warming. We can minimize the carbon footprint but we can also have a carbon handprint, a positive impact on the climate. Quality characteristics can be added with sustainability, and then measured continuously. Test environments can be used less, and in smaller scale and on demand. Test techniques can be used in optimizing or minimizing number of tests. Test automation can be used to speed up testing.
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
In the rapidly evolving landscape of technologies, XML continues to play a vital role in structuring, storing, and transporting data across diverse systems. The recent advancements in artificial intelligence (AI) present new methodologies for enhancing XML development workflows, introducing efficiency, automation, and intelligent capabilities. This presentation will outline the scope and perspective of utilizing AI in XML development. The potential benefits and the possible pitfalls will be highlighted, providing a balanced view of the subject.
We will explore the capabilities of AI in understanding XML markup languages and autonomously creating structured XML content. Additionally, we will examine the capacity of AI to enrich plain text with appropriate XML markup. Practical examples and methodological guidelines will be provided to elucidate how AI can be effectively prompted to interpret and generate accurate XML markup.
Further emphasis will be placed on the role of AI in developing XSLT, or schemas such as XSD and Schematron. We will address the techniques and strategies adopted to create prompts for generating code, explaining code, or refactoring the code, and the results achieved.
The discussion will extend to how AI can be used to transform XML content. In particular, the focus will be on the use of AI XPath extension functions in XSLT, Schematron, Schematron Quick Fixes, or for XML content refactoring.
The presentation aims to deliver a comprehensive overview of AI usage in XML development, providing attendees with the necessary knowledge to make informed decisions. Whether you’re at the early stages of adopting AI or considering integrating it in advanced XML development, this presentation will cover all levels of expertise.
By highlighting the potential advantages and challenges of integrating AI with XML development tools and languages, the presentation seeks to inspire thoughtful conversation around the future of XML development. We’ll not only delve into the technical aspects of AI-powered XML development but also discuss practical implications and possible future directions.
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
How to Get CNIC Information System with Paksim Ga.pptxdanishmna97
Pakdata Cf is a groundbreaking system designed to streamline and facilitate access to CNIC information. This innovative platform leverages advanced technology to provide users with efficient and secure access to their CNIC details.
UiPath Test Automation using UiPath Test Suite series, part 5DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 5. In this session, we will cover CI/CD with devops.
Topics covered:
CI/CD with in UiPath
End-to-end overview of CI/CD pipeline with Azure devops
Speaker:
Lyndsey Byblow, Test Suite Sales Engineer @ UiPath, Inc.
Full-RAG: A modern architecture for hyper-personalizationZilliz
Mike Del Balso, CEO & Co-Founder at Tecton, presents "Full RAG," a novel approach to AI recommendation systems, aiming to push beyond the limitations of traditional models through a deep integration of contextual insights and real-time data, leveraging the Retrieval-Augmented Generation architecture. This talk will outline Full RAG's potential to significantly enhance personalization, address engineering challenges such as data management and model training, and introduce data enrichment with reranking as a key solution. Attendees will gain crucial insights into the importance of hyperpersonalization in AI, the capabilities of Full RAG for advanced personalization, and strategies for managing complex data integrations for deploying cutting-edge AI solutions.
1. JSR 354: Money and Currency API
Rajmahendra Hegde
JUGChennai Lead
Tweets: @rajonjava
JavaOne India 2013 Hyderabad 8th & 9th M
2. Bio
Rajmahendra Hegde
Founder and Leader of JUGChennai
Working for CGI as Project Lead/Architect
Individual JCP Member
Committer: Visage, ScalaFX,
Interest: JEE, Glassfish, Groovy, Scala, JavaFX, Visage, ScalaFX, Gradle,
Netbeans
3. Agenda
> History and Motivation
> Overview
> Currencies and Amounts
> Precision and Rounding
> Formatting and Parsing
> Currency Conversion
> Currency Services and Extensions
> Extras
> Adopt – A – JSR
> TrakStok
> Demo
Platform (SE) Scope1
Standalone Scope
1 See http://mreinhold.org/blog/secure-the-train
this may no longer be part of Money API 1.0
4. History and Motivation
Gold coin of Muhammad bin Sam showing the Goddess Lakshmi
Minted in Delhi, AD 1192 - 1206
This gold coin features a stylized image of the Hindu goddess Lakshmi. It
is an image which was prevalent on coins throughout the Indian sub-
continent for over a millennium, so much so that it was even used by
Muslim rulers.
Source: http://www.britishmuseum.org/explore/highlights/highlight_objects/cm/g/gold_coin_of_muhammad_ibn_sam.aspx
5. Earlier Approaches
Martin Fowler:
A large proportion of the computers in this
world manipulate money, so it’s always
puzzled me that money isn’t actually a first
class data type in any mainstream
programming language. The lack of a type
causes problems, the most obvious
surrounding currencies…
see
http://martinfowler.com/eaaCatalog/money.html
Eric Evans – Time and Money:
On project after project, software developers have
to reinvent the wheel, creating objects for simple
recurring concepts such as “money” and
“currency”. Although most languages have a
“date” or “time” object, these are rudimentary, and
do not cover many needs, such as recurring
sequences of time, durations of time, or intervals
of time. …
To be quite frank, their code isn’t more than an
academic POC, factories called dollars() or
euros() are useless in real globally deployed
frameworks, but he made a good point.
6. Motivation
> Monetary values are a key feature to many applications and it’s a very important
scope of any general purpose language
> Existing java.util.Currency class is strictly a structure used for representing
ISO-4217 standard currencies.
> No standard value type to represent a monetary amount
> No support for currency arithmetic or conversion
> JDK Formatting features lack flexibility
7. Schedule
> Standalone JSR
EDR: April 2013 - Just started
> Java ME/Embedded 8 oder 9
Following the EC Merge and Standard/Embedded harmonization, no JSR should be SE/EE or
ME only. Money is so important, and has almost no legacy in the JDK except
java.util.Currency, that it should be supported by all possible platforms, except maybe
JavaCard for now.
> Minimum Java Version: 7 (given, 8 won’t be here till 2014)
with reasonable support of previous Java versions
still relevant (e.g. Java 6)
Java SE 9: Early 2016
Either a Maintenance Release or new version of this JSR shall be integrated
with
OpenJDK 9.
JSR Renewal Ballot - 2013-02-04
11. Currencies
ISO 4217
Special Codes
Ambiguities
Unmodeled Aspects
Minor units
• Precious Metals (XAU, XAG)
• Testing (XTS)
• No Currency (XXX)
• Supranational currencies, e.g. East Caribbean dollar, the CFP
franc, the CFA franc.
• CFA franc: West African CFA franc und Central African CFA
franc = denotes 2 effectively interchangeable (!).
• Switzerland: CHF, CHE (WIR-EURO), CHW (WIR)
• USA: USD, USN (next day), USS (same day)
Legal acceptance, e.g. Indian Rupees are legally accepted in
Bhutan/Nepal, but not vice versa!
Typically 1/100, rarely 1/1000, but also 1/5
(Mauritania, Madagascar), 0.00000001 (Bitcoin)
12. Virtual Currencies
> Video Game Currencies (Gold, Gil, Rupees, Credits, Gold Rings, Hearts, Zenny,
Potch, Munny, Nuyen…)
> Facebook Credits are a virtual currency you can use to buy
virtual goods in any games or apps of the Facebook
platform that accept payments. You can purchase
Facebook Credits directly from within an app using your
credit card, PayPal, mobile phone and many other local
payment methods.
> Bitcoin (sign: BTC) is a decentralized digital currency
based on an open-source, peer-to-peer internet protocol.
It was introduced by a pseudonymous developer named
Satoshi Nakamoto in 2009.
13. Improve java.util.Currency
Current Limitations
> No support for historical Currencies
> No support for non standard Currencies
(e.g. cows or camels)
> No support for virtual
Currencies (Lindon Dollars Brixton Pound,
Bitcoin, Social Currencies)
> No support for custom
schemes (e.g. legacy codes)
> Only access by currency
code, or Locale
> No support for special use
cases/extensions
Implementation:
MoneyCurrency
public interface CurrencyUnit{
public String getCurrencyCode();
public int getNumericCode();
public int getDefaultFractionDigits();
// new methods
public String getNamespace();
public boolean isLegalTender();
public boolean isVirtual();
public Long getValidFrom();
public Long getValidUntil();
}
public interface Localizable{
public String getDisplayName(Locale locale);
}
14. Access/Create Currencies
Usage
/**
* Shows simple creation of a CurrencyUnit for ISO, backed by JDK
* Currency implementation.
*/
public void forISOCurrencies() {
CurrencyUnit currency = MoneyCurrency.of("USD"); // backed up util.Currency!
currency = MoneyCurrency.of("myNamespace", "myCode"); // may be null!
}
15. Access/Create Currencies
Usage (continued)
public void buildACurrencyUnit() {
MoneyCurrency.Builder builder = new MoneyCurrency.Builder();
builder.setNamespace("myNamespace");
builder.setCurrencyCode("myCode");
builder.setDefaultFractionDigits(4);
builder.setLegalTender(false);
builder.setValidFrom(System.currentTimeMillis());
builder.setVirtual(true);
CurrencyUnit unit = builder.build();
// nevertheless MoneyCurrency.of("myNamespace", "myCode"); still returns
// null, since the instance created is not added to the cache for reuse!
unit = builder.build(true);
// now it is added to the cache, so the unit == unit2
CurrencyUnit unit2 = MoneyCurrency.of("myNamespace", "myCode"); }
16. Monetary Amount
Amount = Number + Currency + Operations
How to represent the numeric amount? Contradictory requirements:
Performance (e.g. for trading)
Precision and Scale (e.g. for calculations)
Must model small numbers (e.g. web shop)
Must support large Numbers (e.g. risk calculations, statistics)
Rounding
Financial Operations and Functions, function chaining
Solution:
• support several numeric representations!
• MonetaryFunction similar to java.function.Function
• MonetaryOperator similar to java.function.UnaryOperator
17. Monetary Amount (continued)
public interface MonetaryAmount{
public CurrencyUnit getCurrency();
public Class<?> getNumberType();
public <T> T asType(Class<T>);
public int intValue(); public int intValueExact();
public long longValue(); public long longValueExact();
[…]
public MonetaryAmount abs();
public MonetaryAmount min(…);
public MonetaryAmount max(…);
public MonetaryAmount add(…);
public MonetaryAmount substract(…);
public MonetaryAmount divide(…);
public MonetaryAmount[] divideAndRemainder(…);
public MonetaryAmount divideToIntegralValue(…);
public MonetaryAmount remainder(…);
public MonetaryAmount multiply(…);
public MonetaryAmount withAmount(Number amount);
[…]
public int getScale(); public int getPrecision();
[…]
public boolean isPositive(); public boolean isPositiveOrZero();
public boolean isNegative(); public boolean isNegativeOrZero();
public boolean isLessThan(…);
public boolean isLessThanOrEqualTo(…);
[…]
public MonetaryAmount with(MonetaryOperator op);
}
Algorithmic Operations…
Data Representation and
Comparison.
Data Access.
Implementation:
Money
18. Monetary Function, Monetary Operator
//@FunctionalInterface for Java 9
public interface MonetaryFunction<T, R> {
public R apply(T value);
}
Implementations:
MinorPart
MajorPart
Reciprocal
MonetaryRounding
CurrencyConversion
//@FunctionalInterface for Java 9
public interface MonetaryOperator
extends
MonetaryFunction<MonetaryAmount,MonetaryAmount> {
}
Implementations:
Minimum
Maximum
Average
SeparateAmount
SeparateCurrencies
Total
19. Creating Amounts
Usage
/**
* Simplest case create an amount with an ISO currency.
*/
public void forISOCurrencies() {
Money amount = Money.of("USD", 1234566.15); // using ISO namespace by default
}
/**
* Create an amount using a custom currency.
*/
public void forCustomCurrencies() {
CurrencyUnit currency = MoneyCurrency.of(
"myNamespace", "myCode");
Money amount = Money.of(currency, 1234566.15);
}
21. Numeric Precision
> Internal Precision (implied by internal number type)
> External Precision (Rounding applied, when the numeric part is accessed/passed
outside)
> Formatting Precision (Rounding for display and output)
> Interoperability
– Different precision/scale
– Distinct numeric representations
– Serialization
By default
• only internal rounding is applied automatically.
• The precision/scale capabilities of an MonetaryAmount are inherited to
its operational results
22. Mixing Numeric Representations
• Mechanism applies similarly for operation chaining
Money amt1 = Money.of(“CHF”, 10.23d);
IntegralMoney amt2 = IntegralMoney.of(“CHF”, 123456789);
MonetaryAmount result = amt1.add(amt2);
// returns Money instance, since its the class on which
// add() was called.
Money amt1 = …;
IntegralMoney amt2 = …;
CurrencyConversion conversion = …;
MonetaryAmount result = amt1
.add(amt2)
.multiply(2)
.with(conversion)
.round(MoneyRounding.of());
23. Rounding
> External Rounding and Formatting Rounding can be implemented in many ways,
depending on the use cases
> Rounding is modeled as a MonetaryOperator
Example for non standard-rounding Argentina:
If the third digit is 2 or less, change it to 0
or drop it.
If the third digit is between 3 and 7,
change it to 5.
If the third digit is 8 or more, add one to
the second digit and drop the third digit or
change it to 0.
Original Rounded Remark
123.452 123.45 3. digit <3 -> round down
123.456 123.455 3<= 3. digit <=7 -> change to 5
123.459 123.46 3. digit >=8 -> round up
Implementation:
MoneyRounding
24. Rounding
Usage
/**
* Round amount based on its currency (defaultFractionUnits).
*/
public MonetaryAmount roundDefault(MonetaryAmount amount){
Rounding rounding = MoneyRounding.of();
return rounding.round(amount);
}
public MonetaryAmount halfConvertAndRound(MonetaryAmount amount,
CurrencyConversion conversion){
return amount.divide(2).with(conversion).with(MoneyRounding.of());
}
26. Formatting and Parsing
Challenges
> Multiple Locale instances for Translation, Dates, Time, Numbers, Currencies
> Additional parameters, e.g. Currency Placement, Rounding, Lenient Fractions, Min,
Max etc.
> Natural language support for non-decimal valuations for example
– Lakhs, Crores (1 Lakh = 100,000,
1 Crore = 100 Lakh)
– INR 12,34,56,000.21 is written 12 Crore, 34 Lakh,
56 Thousand Rupees and 21 Paise
> How handle different formatting styles?
LocalizationStyle
ItemFormat
ItemFormatBuilder
MonetaryFormats singleton
public class LocalizationStyle
implements Serializable {
[…]
public String getId();
public Locale getTranslationLocale();
public Locale getNumberLocale();
public Locale getDateLocale();
public Locale getTimeLocale();
public Map<String, Object> getAttributes() ;
public <T> T getAttribute(
String key, Class<T> type);
public boolean isDefaultStyle() ;
[…]
public static LocalizationStyle of(
Locale locale);
}
27. public interface ItemFormat<T> {
public Class<T> getTargetClass();
public LocalizationStyle getStyle();
public String format(T item);
public void print(Appendable appendable,
T item)
throws IOException;
public T parse(CharSequence input)
throws ParseException;
}
public class ItemFormatBuilder<T> {
private List<FormatToken<T>> tokens = new ArrayList<FormatToken<T>>();
[…]
public ItemFormatBuilder(){…}
public ItemFormatBuilder(Class<T> targetType){…}
public ItemFormatBuilder<T> addToken(FormatToken<T> token) {…}
public ItemFormatBuilder<T> addLiteral(String token) {…}
public boolean isBuildable() {…}
public ItemFormat<T> build() {…}
[…] }
public interface FormatToken<T> {
public void print(Appendable appendable,
T item, LocalizationStyle s)
throws IOException;
public void parse(ParseContext<T> context,
LocalizationStyle style)
throws ItemParseException;
}
Implementations:
LiteralToken
NumberToken
CurrencyToken
AmountToken
…
Formatting and Parsing
ItemFormat, FormatToken and ItemFormatBuilder
29. Currency Conversion
> ExchangeRateType
> ExchangeRate:
– ExchangeRateType
– Base, Term currency
– Conversion factor
– Validity (from/until)
– Provider (optional)
– Direct/Derived Rates
> ConversionProvider/CurrencyConverter
> MonetaryConversions accessor singleton
public interface ExchangeRate {
public ExchangeRateType getExchangeRateType();
public CurrencyUnit getBase();
public CurrencyUnit getTerm();
public BigDecimal getFactor();
public Long getValidFrom();
public Long getValidUntil();
public boolean isValid();
public String getProvider();
public List<ExchangeRate> getExchangeRateChain();
public boolean isDerived();
}
30. Currency Conversion
Usage
/**
* Shows simple conversion of an amount.
*/
public Money convertAmountToCHF(Money amount){
ConversionProvider provider = MonetaryConversion
.getConversionProvider(ExchangeRateType.of("EZB"));
CurrencyConversion chfConversion = provider.getConverter()
.getCurrencyConversion(MoneyCurrency.of("CHF"));
return amount.with(chfConversion);
}
32. > javax.money.MonetaryCurrencies singleton provides
access to registered namespaces
access to contained currencies within a namespace
access to historic currencies
Mapping of currencies between (or within) namespaces
public final class MonetaryCurrencies{
[…]
public static boolean isNamespaceAvailable(String namespace){…}
public static Collection<String> getNamespaces(){…}
public static boolean isAvailable(String namespace, String code, Long timestamp
public static CurrencyUnit get(String namespace, String code, Long timestamp)
public static Collection<CurrencyUnit> getAll(String namespace)
public static Collection<CurrencyUnit> getAll(String namespace, Long timestamp)
[…]
public static CurrencyUnit map(String targetNamespace, Long timestamp,
CurrencyUnit currencyUnit)
public static List<CurrencyUnit> mapAll(String targetNamespace, Long timestamp, CurrencyUnit... units)
}
Currency Services & Extensions
MonetaryCurrencies Singleton
33. Extensions
Some Functionalities that may or may not be included with the JSR:
Calculation Utilities
Regions/Regional Providers,
e.g. for mapping accepting
currencies, legal tenders etc.
…
Recent direction:
If and what extensions are useful
Some could be factored out into Extras (see next slide)
34. Extras
Additional Functionalities, not part of the
actual JSR
Multi-Currency
Compound Values
Statistical Modules
Financial Modules
CDI Extensions (e.g. via Apache DeltaSpike)
JavaFX Bindings and Components
…
Extras are provided:
as separate javamoney-extras GitHub repository
What’s in for you, e.g. like javamoney-examples, no full JCP
Membership is required to contribute there, contribute if you want/can…
35. Adopt – A - JSR
> JUG’s initiative to encourage there members to
contribute to JSRs
> Open for all the Java User Groups
> MainSite: http://adoptajsr.java.net/
> For JSR-354
London Java Community
JUGChennai
36. > Started by JUGChennai
> Currently 5 members on-board
> Built using: current version of JSR-354, Glassfish,
PrimeFaces
> Current Status: Integrating basic design with the JSR,
Integrating EmpireAvenue using Agorava
> Future plan:JavaFX, Mobile (Android & Blackberry),
Identity API (Proposed), Virtual Currency (Proposed)
> GitHub: https://github.com/jugchennaiadoptjava/TrakStok
TrakStok - POC project using JSR-354