io.randomseed.bankster.jsr-354

added in 2.0.0

JSR-354 (javax.money) naming-compatible façade for Bankster.

This namespace is intentionally Clojure-only: it does not implement javax.money.* interfaces. Instead, it provides functions whose names (and arities, after translating receiver->first-arg) mirror the JSR-354 API so that people familiar with JSR-354 can quickly orient themselves in the Bankster world.

Naming:

  • kebab-case vars are the canonical ones,
  • camelCase vars are provided as simple aliases.

Currency resolution policy defaults to Bankster’s registry semantics (weight-based canonical selection).

->MonetaryContext

(->MonetaryContext amount-type number-type precision max-scale fixed-scale? attrs bankster)

Positional factory function for class io.randomseed.bankster.jsr_354.MonetaryContext.

abs

added in 2.0.0

(abs a)

JSR-354-ish: MonetaryAmount.abs().

add

added in 2.0.0

(add a b)

JSR-354-ish: MonetaryAmount.add(MonetaryAmount).

attr-amount-type

added in 2.0.0

Standard MonetaryContext attribute key for amount type.

attr-fixed-scale

added in 2.0.0

Standard MonetaryContext attribute key for fixed-scale flag.

attr-max-scale

added in 2.0.0

Standard MonetaryContext attribute key for max scale.

attr-number-type

added in 2.0.0

Standard MonetaryContext attribute key for number type.

attr-precision

added in 2.0.0

Standard MonetaryContext attribute key for precision.

compare-to

added in 2.0.0

(compare-to a b)

JSR-354-ish: MonetaryAmount.compareTo(MonetaryAmount).

compareTo

context

added in 2.0.0

(context)(context opts)

Builds a MonetaryContext.

Options (all optional):

  • :amount-type -> Class (default: io.randomseed.bankster.Money)
  • :number-type -> Class (default: java.math.BigDecimal)
  • :precision -> integer/long or nil
  • :max-scale -> integer/long or nil
  • :fixed-scale? -> boolean or nil
  • :attrs -> map (keys normalized to strings; see attr-* vars)

Bankster runtime extras (stored under :bankster in the resulting record):

  • :registry -> io.randomseed.bankster.Registry (or nil)
  • :rounding-mode -> rounding spec accepted by scale/post-parse-rounding
  • :rescale-each? -> boolean
  • :currency-resolution -> keyword (default: :weight)

The builder also standardizes a small set of string keys in attrs: attr-amount-type, attr-number-type, and (when present) attr-precision, attr-max-scale, attr-fixed-scale.

create

JSR-354-ish: MonetaryAmountFactory-like constructor.

Delegates to io.randomseed.bankster.money/value (Accountable).

divide

added in 2.0.0

(divide a divisor)(divide a divisor rounding-mode)

JSR-354-ish: MonetaryAmount.divide(Number) and MonetaryAmount.divide(Number, RoundingMode).

get-currencies

added in 2.0.0

(get-currencies)

JSR-354-ish: Monetary.getCurrencies().

Returns a set of currencies known to the default registry.

get-currency

added in 2.0.0

(get-currency currency-or-money)

JSR-354-ish: Monetary.getCurrency(String) and MonetaryAmount.getCurrency().

Returns a Bankster Currency resolved in the default registry (weight-based).

get-currency-code

added in 2.0.0

(get-currency-code currency-or-money)

JSR-354-ish: CurrencyUnit.getCurrencyCode().

get-default-fraction-digits

added in 2.0.0

(get-default-fraction-digits currency-or-money)

JSR-354-ish: CurrencyUnit.getDefaultFractionDigits().

Returns Bankster’s currency scale (decimal places) or -1 for auto-scaled.

get-default-rounding

added in 2.0.0

(get-default-rounding)

JSR-354-ish: Monetary.getDefaultRounding().

Returns a MonetaryOperator-like function (Money -> Money) that rescales a money amount to its currency’s nominal scale.

Uses io.randomseed.bankster.scale/*rounding-mode* when bound, otherwise defaults to io.randomseed.bankster.scale/ROUND_HALF_EVEN.

get-number

added in 2.0.0

(get-number money)

JSR-354-ish: MonetaryAmount.getNumber().

Returns the money amount as java.math.BigDecimal.

get-number-stripped

added in 2.0.0

(get-number-stripped money)

JSR-354-ish: MonetaryAmount.getNumberStripped().

Returns the money amount with trailing zeros stripped.

get-numeric-code

added in 2.0.0

(get-numeric-code currency-or-money)

JSR-354-ish: CurrencyUnit.getNumericCode().

Returns Bankster’s numeric-id (ISO 4217) or -1 when missing.

getCurrencies

getCurrency

getCurrencyCode

getDefaultFractionDigits

getDefaultRounding

getNumber

getNumberStripped

getNumericCode

is-equal-to

added in 2.0.0

(is-equal-to a b)

JSR-354-ish: MonetaryAmount.isEqualTo(MonetaryAmount).

Scale-insensitive comparison of amounts (currency must match).

is-greater-than

added in 2.0.0

(is-greater-than a b)

JSR-354-ish: MonetaryAmount.isGreaterThan(MonetaryAmount).

is-greater-than-or-equal-to

added in 2.0.0

(is-greater-than-or-equal-to a b)

JSR-354-ish: MonetaryAmount.isGreaterThanOrEqualTo(MonetaryAmount).

is-less-than

added in 2.0.0

(is-less-than a b)

JSR-354-ish: MonetaryAmount.isLessThan(MonetaryAmount).

is-less-than-or-equal-to

added in 2.0.0

(is-less-than-or-equal-to a b)

JSR-354-ish: MonetaryAmount.isLessThanOrEqualTo(MonetaryAmount).

is-negative

added in 2.0.0

(is-negative a)

JSR-354-ish: MonetaryAmount.isNegative().

is-negative-or-zero

added in 2.0.0

(is-negative-or-zero a)

JSR-354-ish: MonetaryAmount.isNegativeOrZero().

is-positive

added in 2.0.0

(is-positive a)

JSR-354-ish: MonetaryAmount.isPositive().

is-positive-or-zero

added in 2.0.0

(is-positive-or-zero a)

JSR-354-ish: MonetaryAmount.isPositiveOrZero().

is-zero

added in 2.0.0

(is-zero a)

JSR-354-ish: MonetaryAmount.isZero().

isEqualTo

isGreaterThan

isGreaterThanOrEqualTo

isLessThan

isLessThanOrEqualTo

isNegative

isNegativeOrZero

isPositive

isPositiveOrZero

isZero

map->MonetaryContext

(map->MonetaryContext m__8001__auto__)

Factory function for class io.randomseed.bankster.jsr_354.MonetaryContext, taking a map of keywords to field values.

multiply

added in 2.0.0

(multiply a multiplicand)

JSR-354-ish: MonetaryAmount.multiply(Number).

negate

added in 2.0.0

(negate a)

JSR-354-ish: MonetaryAmount.negate().

plus

added in 2.0.0

(plus a)

JSR-354-ish: MonetaryAmount.plus().

query

added in 2.0.0

(query amount monetary-query)

JSR-354-ish: MonetaryAmount.query(MonetaryQuery).

In Clojure, a MonetaryQuery is just a function (Money -> any).

remainder

added in 2.0.0

(remainder a divisor)(remainder a divisor rounding-mode)

JSR-354-ish: MonetaryAmount.remainder(Number) and MonetaryAmount.remainder(Number, RoundingMode).

signum

added in 2.0.0

(signum a)

JSR-354-ish: MonetaryAmount.signum().

strip-trailing-zeros

added in 2.0.0

(strip-trailing-zeros a)

JSR-354-ish: MonetaryAmount.stripTrailingZeros().

stripTrailingZeros

subtract

added in 2.0.0

(subtract a b)

JSR-354-ish: MonetaryAmount.subtract(MonetaryAmount).

with

added in 2.0.0

(with amount operator)

JSR-354-ish: MonetaryAmount.with(MonetaryOperator).

In Clojure, a MonetaryOperator is just a function (Money -> Money).

with-context

macro

(with-context ctx & body)

Applies a JSR-354-style context in a lexical scope.

In this Clojure-only compat layer, we interpret the context as inputs to dynamic Bankster runtime settings (registry and scaling/rounding), not as mutable state.

Uses (:bankster ctx) as an optional map of settings. Supported keys:

  • :registry -> io.randomseed.bankster.Registry (binds registry/*default*)
  • :rounding-mode -> java.math.RoundingMode or a value accepted by io.randomseed.bankster.scale/post-parse-rounding (binds scale/*rounding-mode*)
  • :rescale-each? -> boolean (binds scale/*each*)

Unspecified keys do not override current bindings. Keys may be present with nil values to explicitly clear a binding (e.g. set rounding-mode to nil).

withContext

macro

added in 2.0.0

(withContext ctx & body)

Alias for with-context.