SlideShare a Scribd company logo
1 of 43
Download to read offline
Go for the Money
Adopt JSR 354
Slideshare 2014
March 2014
Go for the money – Adopt JSR 354 -
http://java.net/projects/javamoney
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Bio
Anatole Tresch
Consultant, Coach
Credit Suisse
Technical Coordinator &
Architect
Specification Lead JSR 354
Regular Conference Speaker
Driving Java EE Config
Twitter/Google+: @atsticks
atsticks@java.net
anatole.tresch@credit-suisse.com
Java Config Discussion https://groups.google.com/forum/#!forum/java-config
Java Config Blog: http://javaeeconfig.blogspot.ch
Zurich Java Community (Google Community)
Zurich Hackergarten
2
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Agenda
3
Overview
Setup
Adoption Areas
API Challenge: Moneymachine
Helping out with the TCK
Adding functonalities to the RI,
e.g. Cash Roundings
Stabilizing JavaMoney Library
Other ?
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Overview
4
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Money Machine
5
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Overview of JSR 354 and Javamoney
API (javax.money):
CurrencyUnit, MonetaryAmount, MonetaryOperator,
MonetaryQuery, CurrencyConversion, ExchangeRate,
MonetaryAmountFormat, MonetaryException;
MonetaryCurrencies, MonetaryAmounts, MonetaryRoundings,
MonetaryConversions, MonetaryFormats
RI (org.javamoney.moneta):
BuildableCurrencyUnit, Money, FastMoney, MonetaryFunctions
TCK (org.javamoney.tck):
Javamoney (GitHub OSS project):
org.javamoney…
format (extended API)
currencies (mapping)
Regions
Validity
calc
6
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Currencies and Monetary Amounts
javax.money
7
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Currencies (continued)
API
8
Allow currencies with arbitrary other currency codes
Register additional Currency Units using an flexible SPI
Fluent API using a Builder (RI only)
Historic Validity of currencies related to regions/countries and vice
versa (not part of JSR, but javamoney OSS project)
public interface CurrencyUnit{
public String getCurrencyCode();
public int getNumericCode();
public int getDefaultFractionDigits();
}
public final class MonetaryCurrencies{
public CurrencyUnit getCurrency(String currencyCode);
public CurrencyUnit getCurrency(Locale locale);
public boolean isCurrencyAvailable(String currencyCode);
public boolean isCurrencyAvailable(String locale);
}
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Currencies (continued)
API Samples
CurrencyUnit currency1 = MonetaryCurrencies.getCurrency("USD");
CurrencyUnit currency2 = MonetaryCurrencies.getCurrency(
Locale.GERMANY);
CurrencyUnit bitcoin = new BuildableCurrencyUnit.Builder("BTC")
.setNumericCode(123456)
.setDefaultFractionDigits(8)
.create();
9
Access a CurrencyUnit
Build a CurrencyUnit (RI only)
Register a CurrencyUnit
CurrencyUnit bitcoin = ….create(true);
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Monetary Amounts
General Aspects
10
Amount = Currency + Numeric Value
+ Capabilities
Arithmetic Functions, Comparison
Fluent API
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Monetary Amounts (continued)
Key Decisions
11
Support Several Numeric Representations (instead of one
single fixed value type)
Use functional design for extendible functionality
(MonetaryOperator, MonetaryQuery)
Define Implementation Recommendations
• Rounding should to be modelled as separate concern
(a MonetaryOperator)
• Ensure Interoperability by the MonetaryAmount
interface
• Precision/scale capabilities should be inherited to its
operational results.
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Monetary Amounts (continued)
The API
public interface MonetaryAmount{
public CurrencyUnit getCurrency();
public NumberValue getNumber();
public MonetaryContext getMonetaryContext();
public MonetaryAmount with(MonetaryOperator operator);
public <R> R query(MonetaryQuery<R> query);
public MonetaryAmountFactory<? extends MonetaryAmount> getFactory();
…
public boolean isLessThanOrEqualTo(MonetaryAmount amt);
public boolean isLessThan(MonetaryAmount amt);
public boolean isEqualTo(MonetaryAmount amt);
public int signum();
…
public MonetaryAmount add(MonetaryAmount amount);
public MonetaryAmount subtract(MonetaryAmount amount);
public MonetaryAmount divide(long number);
public MonetaryAmount multiply(Number number);
public MonetaryAmount remainder(double number);
…
public MonetaryAmount stripTrailingZeros();
}
12
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Monetary Context
Model Amount Capabilities
13
Describes the capabilities of a MonetaryAmount.
Accessible from each MonetaryAmount instance.
Allows querying a feasible implementation type from
MonetaryAmounts.
Contains
common aspects
Max precision, max scale, amount flavor
Arbitrary attributes
E.g. RoundingMode, MathContext, …
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Monetary Context (continued)
The API
public final class MonetaryContext extends AbstractContext
implements Serializable {
public static enum AmountFlavor{ PRECISION, PERFORMANCE, UNDEFINED }
public int getPrecision();
public int getMaxScale();
public AmountFlavor getAmountFlavor();
public Class<? extends MonetaryAmount> getAmountType();
public static final class Builder{…}
}
public abstract class AbstractContext implements Serializable{
…
public <T> T getNamedAttribute(Class<T> type, Object key,
T defaultValue);
public <T> T getNamedAttribute(Class<T> type, Object key);
public <T> T getAttribute(Class<T> type, T defaultValue);
public <T> T getAttribute(Class<T> type);
public Set<Class<?>> getAttributeTypes();
}
14
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Creating Monetary Amounts
Monetary Amount Factory
15
Creates new instances of MonetaryAmount.
Declares
The concrete MonetaryAmount implementation type
returned.
The min/max MonetaryContext supported.
Can be configured with a target
CurrencyUnit
A numeric value
MonetaryContext.
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Creating Monetary Amounts (continued)
Monetary Amount Factory
public interface MonetaryAmountFactory<T extends MonetaryAmount> {
Class<? extends MonetaryAmount> getAmountType();
MonetaryAmountFactory<T> setCurrency(String currencyCode);
MonetaryAmountFactory<T> setCurrency(CurrencyUnit currency);
MonetaryAmountFactory<T> setNumber(double number);
MonetaryAmountFactory<T> setNumber(long number);
MonetaryAmountFactory<T> setNumber(Number number);
MonetaryAmountFactory<T> setContext(MonetaryContext monetaryContext);
MonetaryAmountFactory<T> setAmount(MonetaryAmount amount);
T create();
MonetaryContext getDefaultMonetaryContext();
MonetaryContext getMaximalMonetaryContext();
}
16
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Creating Monetary Amounts
Usage Samples
// Using the default type
MonetaryAmount amount1 = MonetaryAmounts.getAmountFactory()
.setCurrency("USD“)
.setNumber(1234566.15)
.create();
// Using an explicit type
Money amount2 = MonetaryAmounts.getAmountFactory(Money.class)
.setCurrency("USD“)
.setNumber(1234566.15)
.create();
// Query a matching implementation type
Class<? extends MonetaryAmount> type = MonetaryAmounts.queryAmontType(
new MonetaryContext.Builder()
.setAmountFlavor(
AmountFlavor.PERFORMANT)
.create());
MonetaryAmount amount3 = MonetaryAmounts.getAmountFactory(type)
.setCurrency("USD“)
.setNumber(1234566.15)
.create();
17
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Extension Points
javax.money
18
cmp Components
Component1
ProvidedInterface1
RequiredInterface
Component2
RequiredInterface
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Extension Points
MonetaryOperator
 Takes an amount and procudes some other amount.
• With different value
• With different currency
• Or both
// @FunctionalInterface
public interface MonetaryOperator {
public MonetaryAmount apply(MonetaryAmount amount);
}
• Operators then can be applied on every MonetaryAmount:
public interface MonetaryAmount{
…
public MonetaryAmount with (MonetaryOperator operator);
…
}
19
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Extension Points (continued)
MonetaryOperator: Use Cases
Extend the algorithmic capabilities
• Percentages
• Permil
• Different Minor Units
• Different Major Units
• Rounding
• Currency Conversion
• Financial Calculations
• …
20
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Extension Points (continued)
MonetaryOperator Example: Rounding and Percentage
21
// round an amount
MonetaryOperator rounding =
MoneyRoundings.getRounding(
MonetaryCurrencies.getCurrency(“USD”));
Money amount = Money.of(“USD”, 12.345567);
Money rounded = amount.with(rounding); // USD 12.35
// MonetaryFunctions, e.g. calculate 3% of it
Money threePercent = rounded.with(
MonetaryFunctions.getPercent(3));
// USD 0.3705
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Extension Points (continued)
MonetaryQuery
 A MonetaryQuery takes an amount and procuces an arbitrary
result:
// @FunctionalInterface
public interface MonetaryQuery<T> {
public T queryFrom(MonetaryAmount amount);
}
 Queries then can be applied on every MonetaryAmount:
public interface MonetaryAmount {
…
public <T> T query (MonetaryQuary<T> query);
…
}
22
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Currency Conversion
javax.money.convert.*
23
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Currency Conversion
ExchangeRate
 A ExchangeRate models a conversion between two currencies:
• Base CurrencyUnit
• Terminating/target CurrencyUnit
• Provider
• Conversion Factor, where M(term) = M(base) * f
• Additional attributes (ConversionContext)
• Rate chain (composite rates)
 Rates may be direct or derived (composite rates)
24
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Currency Conversion
ExchangeRateProvider
// access default provider (chain)
ExchangeRateProvider prov =
MonetaryConversions.getExchangeRateProvider();
// access a provider explicitly
prov = MonetaryConversions.getExchangeRateProvider("IMF");
// access explicit provider chain
prov = MonetaryConversions.getExchangeRateProvider("ECB", "IMF");
// access Exchange rates
ExchangeRate rate = provider.getExchangeRate("EUR", "CHF");
// Passing additional parameters
ExchangeRate rate = provider.getExchangeRate("EUR", "CHF",
ConversionContext.of(
System.currentTimeMillis() + 2000L) );
25Go for the money - JSR 354 - http://java.net/projects/javamoney
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Currency Conversion (continued)
Performing Conversion
Accessing a CurrencyConversion (always targeted to a terminating
CurrencyUnit):
// access from a ExchangeRateProvider
ExchangeRateProvider prov = …;
CurrencyConversion conv = prov.getCurrencyConversion("INR");
// access it directly (using default rate chain)
conv = MonetaryConversions.getConversion("INR");
// access it, using explicit provider chain
conv = MonetaryConversions.getConversion("INR", "ECB", "IMF");
Performing conversion:
MonetaryAmount chfAmount = MonetaryAmounts.of("CHF",10.50);
MonetaryAmount inrAmount = chfAmount.with(conv); // around EUR 8.75
26
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Formatting and Parsing
javax.money.format.*
27
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Formatting and Parsing
MonetaryAmountFormat
Similar to java.text.DecimalFormat, but also ME
compatible
Configured by AmountStyle, CurrencyStyle,
AmountFormatSymbols
Supports also custom formats
Building AmountStyle using a fluent API
Preconfigured format access is also possible
28Go for the money - JSR 354 - http://java.net/projects/javamoney
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Formatting and Parsing (continued)
MonetaryAmountFormat: Usage Example
// Access a provided format
MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(
new Locale(“”, “in”));
System.out.println(format.format(
Money.of("INR", 39101112.123456))));
output> INR 3,91,01,112.10
29Go for the money - JSR 354 - http://java.net/projects/javamoney
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
JavaMoney OSS Project
org.javamoney.*
30
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
JavaMoney OSS Project
Extended Currency Services
 Currency namespaces (e.g. ISO, VIRTUAL, …)
 Currency namespace mapping
Validity Services (Historization API)
• access of historic currency data related to regions
Region Services
 Region Forest
• Unicode CLDR region tree
• ISO 2-, 3-letter countries
• Custom Trees
Extendible token-based Formatting API
Financial Calculations & Formulas
31
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Links
Current Spec (work in progress, comments allowed):
https://docs.google.com/document/d/1FfihURoCYrbkDcSf1W
XM6fHoU3d3tKooMnZLCpmpyV8/edit
GitHub Project (JSR and JavaMoney):
https://github.com/JavaMoney/javamoney
Umbrella Page: http://javamoney.org
JSR 354: http://jcp.org
Java.net Project: http://java.net/projects/javamoney
JUG Chennai Adoption (TrakStok):
https://github.com/jugchennaiadoptjava/TrakStok
Twitter: @jsr354
Cash Rounding: http://en.wikipedia.org/wiki/Swedish_rounding
32
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Setup
33
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Setup
34
• Install VirtualBox, if not yet done, download from
https://www.virtualbox.org
• Download the prepared image and start it
• Login with debian/debian
• Open the IDE of your choice (Eclipse, IntelliJ and
Netbeans are preinstalled and setup)
• Update the projects/repositories
• For Contributors:
• Ensure you have a GitHub user account
• Create your own Branch of the corresponding repositories
• Switch your local repositories on your VM, on which you want to commit,
to your branched repos
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Adoption Areas JSR 354
API Challenge: MoneyMachine
35
Objective: Test the API for usability, make proposals to improve
How:
Checkout/update the MoneyMachine project from
https://github.com/atsticks/moneymachine.git
Implement the classes in the src/main/java to make the tests
green (skeletons are already there)
The challenge will guide you throughout the whole JSR
Overall 34 test cases of different complexity, you may also selct
only a subset ;-)
Tell me about improvements
Email atsticks@gmail.com (please add [moneymachine] in your
subject header)
Issues on java.net or gitub
Blog your (hopefully positive) experience, twitter, …
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Adoption Areas JSR 354
API Challenge: MoneyMachine Example
36
/**
* This class has to be implemented and helps us giving feedback on the JSR's API. This
* part of the
* project deals with basic aspects such as getting currencies and amounts.
* Created by Anatole on 07.03.14.
*/
public class Basics{
/**
* Get a CurrencyUnit using a currency code.
*
* @param currencyCode the currency code
* @return the corresponding CurrencyUnit instance.
*/
public CurrencyUnit getProvidedCurrency(String currencyCode){
throw new UnsupportedOperationException();
}
/**
* Get a CurrencyUnit using a Locale, modeling a country.
*
* @param locale The country locale.
* @return the corresponding CurrencyUnit instance.
*/
public CurrencyUnit getProvidedCurrency(Locale locale){
throw new UnsupportedOperationException();
}
...
}
Describes
the task to
be done
(incl. Some
hints)
Replace this
with the
code
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Adoption Areas JSR 354
API Challenge: MoneyMachine Testing
37
To check your
implementation is correct,
simply execute the test suite
Correct ;-)
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Adoption Areas JSR 354
Helping on the TCK
38
Objective: Help writing the JSRs TCK
How:
If the JSR is completely new: Checkout the slides, read the spec,
so you have a basic idea
Branch TCK and RI (sometimes you may also find an issue in the
RI)
Update/checkout the JSR’s API, RI, JavaMoney parent and TCK
Look for the test classes present in the TCK
Select tests you want to contribute and coordinate with me
Write the tests, if not sure how, you may ask me ;-)
If it is the first time working on a TCK, you may do pair
programming with a more experienced person
Commit your code to your branch
Create a Git Pull Request
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Adoption Areas JSR 354
Helping on the TCK (continued)
39
/**
* Test successful conversion for possible currency pairs.<br/>
* Hint: you may only check for rate factory, when using a hardcoded
* ExchangeRateProvider, such a provider
* must be also implemented and registered as an SPI.
*/
@Test @SpecAssertion(id = "432-A1", section="4.3.2")
public void testConversion(){
Assert.fail();
}
Describes the test
very briefly
References the according
section in the spec
Add your test code here.
Hint 1: if you are unsure first write a story line
Hint 2: some aspects may require to implement multiple
tests, just ensure the annotations are on all tests
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Adoption Areas JSR 354
Extending the Reference Implementation
40
Objective: Adding functonalities to the RI
How:
If the JSR is completely new: Talk with me first
Discuss your ideas with me to see where your idea fits
best
Branch RI (and/or JavaMoney Library)
Adding functonalities/tests to the RI (and/or JavaMoney
Lib)
Write/enhance documentation
Commit your changes
Create a Pull Request
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Adoption Areas JSR 354
Stabilizing JavaMoney Library
41
Objective: Help stabilizing the functionality of JavaMoney
How:
If the JSR is completely new: Talk with me first
Branch JavaMoney Library
Write tests, e.g. for financial calculations
Write/enhance documentation
New functionalities: discuss with me first
Commit your changes
Create a Pull Request
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
Q & A
42
Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014
The End
43

More Related Content

Similar to Go for the Money - Adopt JSR 354 and Help Stabilize JavaMoney

Go for the Money - JSR 354
Go for the Money - JSR 354Go for the Money - JSR 354
Go for the Money - JSR 354Anatole Tresch
 
JSR 354: Money and Currency API - Short Overview
JSR 354: Money and Currency API - Short OverviewJSR 354: Money and Currency API - Short Overview
JSR 354: Money and Currency API - Short OverviewWerner Keil
 
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !jazoon13
 
JSR354 Utrecht JUG 20171027
JSR354 Utrecht JUG 20171027JSR354 Utrecht JUG 20171027
JSR354 Utrecht JUG 20171027Wim van Haaren
 
Introduction to JSR 354 (Currency and Money) by Anatole Tresch
Introduction to JSR 354 (Currency and Money) by Anatole TreschIntroduction to JSR 354 (Currency and Money) by Anatole Tresch
Introduction to JSR 354 (Currency and Money) by Anatole TreschCodemotion
 
JSR 354 - Money and Currency API
JSR 354 - Money and Currency APIJSR 354 - Money and Currency API
JSR 354 - Money and Currency APIRajmahendra Hegde
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTechAntya Dev
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner Keil
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner KeilIntroduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner Keil
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner KeilCodemotion
 
Groovy On The Trading Desk
Groovy On The Trading DeskGroovy On The Trading Desk
Groovy On The Trading DeskJonathan Felch
 
Week 8
Week 8Week 8
Week 8A VD
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureJeroen Rosenberg
 
A mysterious journey to MVP world - Viber Android Meetup 2018
A mysterious journey to MVP world - Viber Android Meetup 2018A mysterious journey to MVP world - Viber Android Meetup 2018
A mysterious journey to MVP world - Viber Android Meetup 2018Yegor Malyshev
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Matt Raible
 
Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScriptCodemotion
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every dayVadym Khondar
 
2015 Java update and roadmap, JUG sevilla
2015  Java update and roadmap, JUG sevilla2015  Java update and roadmap, JUG sevilla
2015 Java update and roadmap, JUG sevillaTrisha Gee
 

Similar to Go for the Money - Adopt JSR 354 and Help Stabilize JavaMoney (20)

JSR 354 LJC-Hackday
JSR 354 LJC-HackdayJSR 354 LJC-Hackday
JSR 354 LJC-Hackday
 
Go for the Money - JSR 354
Go for the Money - JSR 354Go for the Money - JSR 354
Go for the Money - JSR 354
 
JSR 354: Money and Currency API - Short Overview
JSR 354: Money and Currency API - Short OverviewJSR 354: Money and Currency API - Short Overview
JSR 354: Money and Currency API - Short Overview
 
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
 
JSR354 Utrecht JUG 20171027
JSR354 Utrecht JUG 20171027JSR354 Utrecht JUG 20171027
JSR354 Utrecht JUG 20171027
 
Introduction to JSR 354 (Currency and Money) by Anatole Tresch
Introduction to JSR 354 (Currency and Money) by Anatole TreschIntroduction to JSR 354 (Currency and Money) by Anatole Tresch
Introduction to JSR 354 (Currency and Money) by Anatole Tresch
 
JSR 354 - Money and Currency API
JSR 354 - Money and Currency APIJSR 354 - Money and Currency API
JSR 354 - Money and Currency API
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTech
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner Keil
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner KeilIntroduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner Keil
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner Keil
 
Groovy On The Trading Desk
Groovy On The Trading DeskGroovy On The Trading Desk
Groovy On The Trading Desk
 
Week 8
Week 8Week 8
Week 8
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal Architecture
 
A mysterious journey to MVP world - Viber Android Meetup 2018
A mysterious journey to MVP world - Viber Android Meetup 2018A mysterious journey to MVP world - Viber Android Meetup 2018
A mysterious journey to MVP world - Viber Android Meetup 2018
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
 
Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScript
 
A First Date With Scala
A First Date With ScalaA First Date With Scala
A First Date With Scala
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
2015 Java update and roadmap, JUG sevilla
2015  Java update and roadmap, JUG sevilla2015  Java update and roadmap, JUG sevilla
2015 Java update and roadmap, JUG sevilla
 

More from Anatole Tresch

Jsr382: Konfiguration in Java
Jsr382: Konfiguration in JavaJsr382: Konfiguration in Java
Jsr382: Konfiguration in JavaAnatole Tresch
 
Wie man Applikationen nicht bauen sollte...
Wie man Applikationen nicht bauen sollte...Wie man Applikationen nicht bauen sollte...
Wie man Applikationen nicht bauen sollte...Anatole Tresch
 
The Gib Five - Modern IT Architecture
The Gib Five - Modern IT ArchitectureThe Gib Five - Modern IT Architecture
The Gib Five - Modern IT ArchitectureAnatole Tresch
 
The Big Five - IT Architektur Heute
The Big Five - IT Architektur HeuteThe Big Five - IT Architektur Heute
The Big Five - IT Architektur HeuteAnatole Tresch
 
Disruption is Change is Future
Disruption is Change is FutureDisruption is Change is Future
Disruption is Change is FutureAnatole Tresch
 
Configuration with Microprofile and Apache Tamaya
Configuration with Microprofile and Apache TamayaConfiguration with Microprofile and Apache Tamaya
Configuration with Microprofile and Apache TamayaAnatole Tresch
 
Configuration beyond Java EE 8
Configuration beyond Java EE 8Configuration beyond Java EE 8
Configuration beyond Java EE 8Anatole Tresch
 
Alles Docker oder Was ?
Alles Docker oder Was ?Alles Docker oder Was ?
Alles Docker oder Was ?Anatole Tresch
 
Configure once, run everywhere 2016
Configure once, run everywhere 2016Configure once, run everywhere 2016
Configure once, run everywhere 2016Anatole Tresch
 
Configuration with Apache Tamaya
Configuration with Apache TamayaConfiguration with Apache Tamaya
Configuration with Apache TamayaAnatole Tresch
 
Wie Monolithen für die Zukuft trimmen
Wie Monolithen für die Zukuft trimmenWie Monolithen für die Zukuft trimmen
Wie Monolithen für die Zukuft trimmenAnatole Tresch
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaAnatole Tresch
 
Legacy Renewal of Central Framework in the Enterprise
Legacy Renewal of Central Framework in the EnterpriseLegacy Renewal of Central Framework in the Enterprise
Legacy Renewal of Central Framework in the EnterpriseAnatole Tresch
 
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...Anatole Tresch
 
A first Draft to Java Configuration
A first Draft to Java ConfigurationA first Draft to Java Configuration
A first Draft to Java ConfigurationAnatole Tresch
 

More from Anatole Tresch (17)

Jsr382: Konfiguration in Java
Jsr382: Konfiguration in JavaJsr382: Konfiguration in Java
Jsr382: Konfiguration in Java
 
Wie man Applikationen nicht bauen sollte...
Wie man Applikationen nicht bauen sollte...Wie man Applikationen nicht bauen sollte...
Wie man Applikationen nicht bauen sollte...
 
The Gib Five - Modern IT Architecture
The Gib Five - Modern IT ArchitectureThe Gib Five - Modern IT Architecture
The Gib Five - Modern IT Architecture
 
The Big Five - IT Architektur Heute
The Big Five - IT Architektur HeuteThe Big Five - IT Architektur Heute
The Big Five - IT Architektur Heute
 
Microservices in Java
Microservices in JavaMicroservices in Java
Microservices in Java
 
Disruption is Change is Future
Disruption is Change is FutureDisruption is Change is Future
Disruption is Change is Future
 
Configuration with Microprofile and Apache Tamaya
Configuration with Microprofile and Apache TamayaConfiguration with Microprofile and Apache Tamaya
Configuration with Microprofile and Apache Tamaya
 
Configuration beyond Java EE 8
Configuration beyond Java EE 8Configuration beyond Java EE 8
Configuration beyond Java EE 8
 
Alles Docker oder Was ?
Alles Docker oder Was ?Alles Docker oder Was ?
Alles Docker oder Was ?
 
Going Resilient...
Going Resilient...Going Resilient...
Going Resilient...
 
Configure once, run everywhere 2016
Configure once, run everywhere 2016Configure once, run everywhere 2016
Configure once, run everywhere 2016
 
Configuration with Apache Tamaya
Configuration with Apache TamayaConfiguration with Apache Tamaya
Configuration with Apache Tamaya
 
Wie Monolithen für die Zukuft trimmen
Wie Monolithen für die Zukuft trimmenWie Monolithen für die Zukuft trimmen
Wie Monolithen für die Zukuft trimmen
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache Tamaya
 
Legacy Renewal of Central Framework in the Enterprise
Legacy Renewal of Central Framework in the EnterpriseLegacy Renewal of Central Framework in the Enterprise
Legacy Renewal of Central Framework in the Enterprise
 
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
 
A first Draft to Java Configuration
A first Draft to Java ConfigurationA first Draft to Java Configuration
A first Draft to Java Configuration
 

Recently uploaded

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Recently uploaded (20)

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

Go for the Money - Adopt JSR 354 and Help Stabilize JavaMoney

  • 1. Go for the Money Adopt JSR 354 Slideshare 2014 March 2014 Go for the money – Adopt JSR 354 - http://java.net/projects/javamoney
  • 2. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Bio Anatole Tresch Consultant, Coach Credit Suisse Technical Coordinator & Architect Specification Lead JSR 354 Regular Conference Speaker Driving Java EE Config Twitter/Google+: @atsticks atsticks@java.net anatole.tresch@credit-suisse.com Java Config Discussion https://groups.google.com/forum/#!forum/java-config Java Config Blog: http://javaeeconfig.blogspot.ch Zurich Java Community (Google Community) Zurich Hackergarten 2
  • 3. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Agenda 3 Overview Setup Adoption Areas API Challenge: Moneymachine Helping out with the TCK Adding functonalities to the RI, e.g. Cash Roundings Stabilizing JavaMoney Library Other ?
  • 4. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Overview 4
  • 5. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Money Machine 5
  • 6. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Overview of JSR 354 and Javamoney API (javax.money): CurrencyUnit, MonetaryAmount, MonetaryOperator, MonetaryQuery, CurrencyConversion, ExchangeRate, MonetaryAmountFormat, MonetaryException; MonetaryCurrencies, MonetaryAmounts, MonetaryRoundings, MonetaryConversions, MonetaryFormats RI (org.javamoney.moneta): BuildableCurrencyUnit, Money, FastMoney, MonetaryFunctions TCK (org.javamoney.tck): Javamoney (GitHub OSS project): org.javamoney… format (extended API) currencies (mapping) Regions Validity calc 6
  • 7. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Currencies and Monetary Amounts javax.money 7
  • 8. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Currencies (continued) API 8 Allow currencies with arbitrary other currency codes Register additional Currency Units using an flexible SPI Fluent API using a Builder (RI only) Historic Validity of currencies related to regions/countries and vice versa (not part of JSR, but javamoney OSS project) public interface CurrencyUnit{ public String getCurrencyCode(); public int getNumericCode(); public int getDefaultFractionDigits(); } public final class MonetaryCurrencies{ public CurrencyUnit getCurrency(String currencyCode); public CurrencyUnit getCurrency(Locale locale); public boolean isCurrencyAvailable(String currencyCode); public boolean isCurrencyAvailable(String locale); }
  • 9. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Currencies (continued) API Samples CurrencyUnit currency1 = MonetaryCurrencies.getCurrency("USD"); CurrencyUnit currency2 = MonetaryCurrencies.getCurrency( Locale.GERMANY); CurrencyUnit bitcoin = new BuildableCurrencyUnit.Builder("BTC") .setNumericCode(123456) .setDefaultFractionDigits(8) .create(); 9 Access a CurrencyUnit Build a CurrencyUnit (RI only) Register a CurrencyUnit CurrencyUnit bitcoin = ….create(true);
  • 10. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Monetary Amounts General Aspects 10 Amount = Currency + Numeric Value + Capabilities Arithmetic Functions, Comparison Fluent API
  • 11. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Monetary Amounts (continued) Key Decisions 11 Support Several Numeric Representations (instead of one single fixed value type) Use functional design for extendible functionality (MonetaryOperator, MonetaryQuery) Define Implementation Recommendations • Rounding should to be modelled as separate concern (a MonetaryOperator) • Ensure Interoperability by the MonetaryAmount interface • Precision/scale capabilities should be inherited to its operational results.
  • 12. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Monetary Amounts (continued) The API public interface MonetaryAmount{ public CurrencyUnit getCurrency(); public NumberValue getNumber(); public MonetaryContext getMonetaryContext(); public MonetaryAmount with(MonetaryOperator operator); public <R> R query(MonetaryQuery<R> query); public MonetaryAmountFactory<? extends MonetaryAmount> getFactory(); … public boolean isLessThanOrEqualTo(MonetaryAmount amt); public boolean isLessThan(MonetaryAmount amt); public boolean isEqualTo(MonetaryAmount amt); public int signum(); … public MonetaryAmount add(MonetaryAmount amount); public MonetaryAmount subtract(MonetaryAmount amount); public MonetaryAmount divide(long number); public MonetaryAmount multiply(Number number); public MonetaryAmount remainder(double number); … public MonetaryAmount stripTrailingZeros(); } 12
  • 13. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Monetary Context Model Amount Capabilities 13 Describes the capabilities of a MonetaryAmount. Accessible from each MonetaryAmount instance. Allows querying a feasible implementation type from MonetaryAmounts. Contains common aspects Max precision, max scale, amount flavor Arbitrary attributes E.g. RoundingMode, MathContext, …
  • 14. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Monetary Context (continued) The API public final class MonetaryContext extends AbstractContext implements Serializable { public static enum AmountFlavor{ PRECISION, PERFORMANCE, UNDEFINED } public int getPrecision(); public int getMaxScale(); public AmountFlavor getAmountFlavor(); public Class<? extends MonetaryAmount> getAmountType(); public static final class Builder{…} } public abstract class AbstractContext implements Serializable{ … public <T> T getNamedAttribute(Class<T> type, Object key, T defaultValue); public <T> T getNamedAttribute(Class<T> type, Object key); public <T> T getAttribute(Class<T> type, T defaultValue); public <T> T getAttribute(Class<T> type); public Set<Class<?>> getAttributeTypes(); } 14
  • 15. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Creating Monetary Amounts Monetary Amount Factory 15 Creates new instances of MonetaryAmount. Declares The concrete MonetaryAmount implementation type returned. The min/max MonetaryContext supported. Can be configured with a target CurrencyUnit A numeric value MonetaryContext.
  • 16. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Creating Monetary Amounts (continued) Monetary Amount Factory public interface MonetaryAmountFactory<T extends MonetaryAmount> { Class<? extends MonetaryAmount> getAmountType(); MonetaryAmountFactory<T> setCurrency(String currencyCode); MonetaryAmountFactory<T> setCurrency(CurrencyUnit currency); MonetaryAmountFactory<T> setNumber(double number); MonetaryAmountFactory<T> setNumber(long number); MonetaryAmountFactory<T> setNumber(Number number); MonetaryAmountFactory<T> setContext(MonetaryContext monetaryContext); MonetaryAmountFactory<T> setAmount(MonetaryAmount amount); T create(); MonetaryContext getDefaultMonetaryContext(); MonetaryContext getMaximalMonetaryContext(); } 16
  • 17. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Creating Monetary Amounts Usage Samples // Using the default type MonetaryAmount amount1 = MonetaryAmounts.getAmountFactory() .setCurrency("USD“) .setNumber(1234566.15) .create(); // Using an explicit type Money amount2 = MonetaryAmounts.getAmountFactory(Money.class) .setCurrency("USD“) .setNumber(1234566.15) .create(); // Query a matching implementation type Class<? extends MonetaryAmount> type = MonetaryAmounts.queryAmontType( new MonetaryContext.Builder() .setAmountFlavor( AmountFlavor.PERFORMANT) .create()); MonetaryAmount amount3 = MonetaryAmounts.getAmountFactory(type) .setCurrency("USD“) .setNumber(1234566.15) .create(); 17
  • 18. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Extension Points javax.money 18 cmp Components Component1 ProvidedInterface1 RequiredInterface Component2 RequiredInterface
  • 19. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Extension Points MonetaryOperator  Takes an amount and procudes some other amount. • With different value • With different currency • Or both // @FunctionalInterface public interface MonetaryOperator { public MonetaryAmount apply(MonetaryAmount amount); } • Operators then can be applied on every MonetaryAmount: public interface MonetaryAmount{ … public MonetaryAmount with (MonetaryOperator operator); … } 19
  • 20. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Extension Points (continued) MonetaryOperator: Use Cases Extend the algorithmic capabilities • Percentages • Permil • Different Minor Units • Different Major Units • Rounding • Currency Conversion • Financial Calculations • … 20
  • 21. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Extension Points (continued) MonetaryOperator Example: Rounding and Percentage 21 // round an amount MonetaryOperator rounding = MoneyRoundings.getRounding( MonetaryCurrencies.getCurrency(“USD”)); Money amount = Money.of(“USD”, 12.345567); Money rounded = amount.with(rounding); // USD 12.35 // MonetaryFunctions, e.g. calculate 3% of it Money threePercent = rounded.with( MonetaryFunctions.getPercent(3)); // USD 0.3705
  • 22. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Extension Points (continued) MonetaryQuery  A MonetaryQuery takes an amount and procuces an arbitrary result: // @FunctionalInterface public interface MonetaryQuery<T> { public T queryFrom(MonetaryAmount amount); }  Queries then can be applied on every MonetaryAmount: public interface MonetaryAmount { … public <T> T query (MonetaryQuary<T> query); … } 22
  • 23. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Currency Conversion javax.money.convert.* 23
  • 24. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Currency Conversion ExchangeRate  A ExchangeRate models a conversion between two currencies: • Base CurrencyUnit • Terminating/target CurrencyUnit • Provider • Conversion Factor, where M(term) = M(base) * f • Additional attributes (ConversionContext) • Rate chain (composite rates)  Rates may be direct or derived (composite rates) 24
  • 25. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Currency Conversion ExchangeRateProvider // access default provider (chain) ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(); // access a provider explicitly prov = MonetaryConversions.getExchangeRateProvider("IMF"); // access explicit provider chain prov = MonetaryConversions.getExchangeRateProvider("ECB", "IMF"); // access Exchange rates ExchangeRate rate = provider.getExchangeRate("EUR", "CHF"); // Passing additional parameters ExchangeRate rate = provider.getExchangeRate("EUR", "CHF", ConversionContext.of( System.currentTimeMillis() + 2000L) ); 25Go for the money - JSR 354 - http://java.net/projects/javamoney
  • 26. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Currency Conversion (continued) Performing Conversion Accessing a CurrencyConversion (always targeted to a terminating CurrencyUnit): // access from a ExchangeRateProvider ExchangeRateProvider prov = …; CurrencyConversion conv = prov.getCurrencyConversion("INR"); // access it directly (using default rate chain) conv = MonetaryConversions.getConversion("INR"); // access it, using explicit provider chain conv = MonetaryConversions.getConversion("INR", "ECB", "IMF"); Performing conversion: MonetaryAmount chfAmount = MonetaryAmounts.of("CHF",10.50); MonetaryAmount inrAmount = chfAmount.with(conv); // around EUR 8.75 26
  • 27. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Formatting and Parsing javax.money.format.* 27
  • 28. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Formatting and Parsing MonetaryAmountFormat Similar to java.text.DecimalFormat, but also ME compatible Configured by AmountStyle, CurrencyStyle, AmountFormatSymbols Supports also custom formats Building AmountStyle using a fluent API Preconfigured format access is also possible 28Go for the money - JSR 354 - http://java.net/projects/javamoney
  • 29. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Formatting and Parsing (continued) MonetaryAmountFormat: Usage Example // Access a provided format MonetaryAmountFormat format = MonetaryFormats.getAmountFormat( new Locale(“”, “in”)); System.out.println(format.format( Money.of("INR", 39101112.123456)))); output> INR 3,91,01,112.10 29Go for the money - JSR 354 - http://java.net/projects/javamoney
  • 30. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 JavaMoney OSS Project org.javamoney.* 30
  • 31. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 JavaMoney OSS Project Extended Currency Services  Currency namespaces (e.g. ISO, VIRTUAL, …)  Currency namespace mapping Validity Services (Historization API) • access of historic currency data related to regions Region Services  Region Forest • Unicode CLDR region tree • ISO 2-, 3-letter countries • Custom Trees Extendible token-based Formatting API Financial Calculations & Formulas 31
  • 32. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Links Current Spec (work in progress, comments allowed): https://docs.google.com/document/d/1FfihURoCYrbkDcSf1W XM6fHoU3d3tKooMnZLCpmpyV8/edit GitHub Project (JSR and JavaMoney): https://github.com/JavaMoney/javamoney Umbrella Page: http://javamoney.org JSR 354: http://jcp.org Java.net Project: http://java.net/projects/javamoney JUG Chennai Adoption (TrakStok): https://github.com/jugchennaiadoptjava/TrakStok Twitter: @jsr354 Cash Rounding: http://en.wikipedia.org/wiki/Swedish_rounding 32
  • 33. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Setup 33
  • 34. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Setup 34 • Install VirtualBox, if not yet done, download from https://www.virtualbox.org • Download the prepared image and start it • Login with debian/debian • Open the IDE of your choice (Eclipse, IntelliJ and Netbeans are preinstalled and setup) • Update the projects/repositories • For Contributors: • Ensure you have a GitHub user account • Create your own Branch of the corresponding repositories • Switch your local repositories on your VM, on which you want to commit, to your branched repos
  • 35. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Adoption Areas JSR 354 API Challenge: MoneyMachine 35 Objective: Test the API for usability, make proposals to improve How: Checkout/update the MoneyMachine project from https://github.com/atsticks/moneymachine.git Implement the classes in the src/main/java to make the tests green (skeletons are already there) The challenge will guide you throughout the whole JSR Overall 34 test cases of different complexity, you may also selct only a subset ;-) Tell me about improvements Email atsticks@gmail.com (please add [moneymachine] in your subject header) Issues on java.net or gitub Blog your (hopefully positive) experience, twitter, …
  • 36. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Adoption Areas JSR 354 API Challenge: MoneyMachine Example 36 /** * This class has to be implemented and helps us giving feedback on the JSR's API. This * part of the * project deals with basic aspects such as getting currencies and amounts. * Created by Anatole on 07.03.14. */ public class Basics{ /** * Get a CurrencyUnit using a currency code. * * @param currencyCode the currency code * @return the corresponding CurrencyUnit instance. */ public CurrencyUnit getProvidedCurrency(String currencyCode){ throw new UnsupportedOperationException(); } /** * Get a CurrencyUnit using a Locale, modeling a country. * * @param locale The country locale. * @return the corresponding CurrencyUnit instance. */ public CurrencyUnit getProvidedCurrency(Locale locale){ throw new UnsupportedOperationException(); } ... } Describes the task to be done (incl. Some hints) Replace this with the code
  • 37. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Adoption Areas JSR 354 API Challenge: MoneyMachine Testing 37 To check your implementation is correct, simply execute the test suite Correct ;-)
  • 38. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Adoption Areas JSR 354 Helping on the TCK 38 Objective: Help writing the JSRs TCK How: If the JSR is completely new: Checkout the slides, read the spec, so you have a basic idea Branch TCK and RI (sometimes you may also find an issue in the RI) Update/checkout the JSR’s API, RI, JavaMoney parent and TCK Look for the test classes present in the TCK Select tests you want to contribute and coordinate with me Write the tests, if not sure how, you may ask me ;-) If it is the first time working on a TCK, you may do pair programming with a more experienced person Commit your code to your branch Create a Git Pull Request
  • 39. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Adoption Areas JSR 354 Helping on the TCK (continued) 39 /** * Test successful conversion for possible currency pairs.<br/> * Hint: you may only check for rate factory, when using a hardcoded * ExchangeRateProvider, such a provider * must be also implemented and registered as an SPI. */ @Test @SpecAssertion(id = "432-A1", section="4.3.2") public void testConversion(){ Assert.fail(); } Describes the test very briefly References the according section in the spec Add your test code here. Hint 1: if you are unsure first write a story line Hint 2: some aspects may require to implement multiple tests, just ensure the annotations are on all tests
  • 40. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Adoption Areas JSR 354 Extending the Reference Implementation 40 Objective: Adding functonalities to the RI How: If the JSR is completely new: Talk with me first Discuss your ideas with me to see where your idea fits best Branch RI (and/or JavaMoney Library) Adding functonalities/tests to the RI (and/or JavaMoney Lib) Write/enhance documentation Commit your changes Create a Pull Request
  • 41. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Adoption Areas JSR 354 Stabilizing JavaMoney Library 41 Objective: Help stabilizing the functionality of JavaMoney How: If the JSR is completely new: Talk with me first Branch JavaMoney Library Write tests, e.g. for financial calculations Write/enhance documentation New functionalities: discuss with me first Commit your changes Create a Pull Request
  • 42. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 Q & A 42
  • 43. Go for the money - JSR 354 - http://java.net/projects/javamoney March 2014 The End 43