Giter VIP home page Giter VIP logo

money-kotlin's Introduction

Kotlin extensions for javax.money (Moneta) JSR 354

Extensions which makes working with javax.money JSR 354 with easier when using Kotlin.

This code builds upon the Money API of the JSR proposal, not the Moneta classes in the reference implementation.

Features

  • Kotlin extension functions for all the *Builder in the javax.money package.
  • Kotlin operator functions for the operators defined in javax.money.MonetaryAmount.

Requirements

At least Java 11.

Installation

Find the latest version on Maven Central.

Add the money-kotlin dependency to your project.

Gradle:

implementation("nl.hiddewieringa:money-kotlin:$moneyKotlinVersion")

Maven:

<dependency>
  <groupId>nl.hiddewieringa</groupId>
  <artifactId>money-kotlin</artifactId>
  <version>${moneyKotlin.version}</version>
</dependency>

Examples

All the extension/operator functions have an associated test in src/test/kotlin.

Monetary amount

// Create a monetary amount of a specific type and currency
val money = (10.0).ofCurrency<FastMoney>("EUR")

// add
money + money
+money
// subtract & negate
money - money
-money
// multiply
money * 2
2 * money
// divide & remainder
money / 2.0
money % 2.0

monetaryAmountFactoryQuery {
    setFixedScale(true)
}
monetaryContext {
    setPrecision(1)
}
typedMonetaryContext<FastMoney> {
    setPrecision(1)
}

Currency

"EUR".asCurrency()

currencyContext("PROVIDER") {
    setProviderName("PROVIDER")
}
currencyQuery {
    setCountries("NL".asCountryLocale())
}

Locale

"NL".asCountryLocale()
"NL".asCountryLocale().getCurrency()
"NL".asCountryLocale().getCurrencies()

Rounding

roundingContext("EUR", "PROVIDER") {
    setProviderName("PROVIDER")
}
roundingQuery {
    setScale(1)
}

Format

Locale.GERMANY.monetaryAmountFormat()

amountFormatContext {
    setFormatName("name")
}
amountFormatContext(Locale.GERMANY) {
    setFormatName("name")
}
amountFormatQuery("name") {
    setLocale(Locale.GERMANY)
}

Conversion

money.convertTo("EUR")
money.convertTo("EUR", provider)

providerContext("PROVIDER", RateType.ANY) {
    setProviderName("PROVIDER")
}
conversionContext {
    setRateType(RateType.ANY)
}
conversionQuery {
    setBaseCurrency("EUR")
}

Releasing and publishing

Preparation

Ensure that the properties signing.keyId, signing.password and signing.secretKeyRingFile= are set in ~/.gradle/gradle.properties. These properties are neccesary for signing releases.

Ensure that the properties sonatypeUsername and sonatypePassword are set in ~/.gradle/gradle.properties. These properties are credentials for publishing to Maven Central.

Building

Build the project

./gradlew clean build

Releasing

Release a version by tagging a Git commit

git tag -a 1.0.0 -m "Version 1.0.0"

Publishing

Publish the release to Sonatype

./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository

This will publish the artifacts to Maven Central.

money-kotlin's People

Contributors

hiddewie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.