Package com.tuladb.currency
Class CurrencyCatalog
java.lang.Object
com.tuladb.currency.CurrencyCatalog
Reads the canonical ISO 4217 catalog shipped with tuladb-core
(
config/currencies.json) and optionally merges a deployment
override file. Provides alpha-3 / numeric / scale lookups for the
HTTP boundary; the engine itself stays integer-only.
This loader is intentionally stdlib-only — no Jackson or external JSON dependency — so the tuladb-sdk/java artifact can stay zero-dep. The parser handles the well-known flat-array-of-flat-objects format we control; it is not a general-purpose JSON parser.
Override semantics mirror the Python loader: an override file may add new currencies (e.g. crypto / internal tokens) or replace the scale/name of an existing canonical entry, but may not reassign a numeric code to a different alpha-3.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCurrencyCatalog(List<Currency> entries) Visible to tests; production code usesloadDefault(). -
Method Summary
Modifier and TypeMethodDescriptionall()longamountDecimalToInt(Object value, Object currency) DASH-6: convert a human decimal amount to integer minor units using the currency's scale.amountIntToDecimal(long minorUnits, Object currency) DASH-6: inverse for display.voidapplyOverride(Currency entry) code(int numeric) booleancontainsCode(String code) booleancontainsNumeric(int numeric) get(int numeric) static CurrencyCatalogstatic CurrencyCatalogLoad the catalog from the conventional location, applying anyTULADB_CURRENCY_OVERRIDEfile on top.intCoerce a request-supplied currency value to its integer numeric.intregistry()The registry set byuseRegistry(com.tuladb.currency.CurrencyScales), or null.intscale(int numeric) intintsize()useRegistry(CurrencyScales scales) Take amount scales from the engine's currency registry instead of this catalog's file.
-
Field Details
-
ENV_CORE_DIR
- See Also:
-
ENV_CATALOG
- See Also:
-
ENV_OVERRIDE
- See Also:
-
-
Constructor Details
-
CurrencyCatalog
Visible to tests; production code usesloadDefault().
-
-
Method Details
-
loadDefault
Load the catalog from the conventional location, applying anyTULADB_CURRENCY_OVERRIDEfile on top. -
load
-
applyOverride
-
get
-
get
-
numeric
-
code
-
scale
-
scale
public int scale(int numeric) -
useRegistry
Take amount scales from the engine's currency registry instead of this catalog's file. Once set,amountDecimalToInt(java.lang.Object, java.lang.Object)andamountIntToDecimal(long, java.lang.Object)use the REGISTERED scale (cached byscales); a currency the engine does not know is aCurrencyNotRegisteredException, never the file's guess, and a numeric missing from the file is accepted if the engine has it. Without a registry the file scale is used, which can disagree with the engine for any unit not in ISO 4217 (or registered with another scale).- Returns:
- this catalog
-
registry
The registry set byuseRegistry(com.tuladb.currency.CurrencyScales), or null. -
amountDecimalToInt
DASH-6: convert a human decimal amount to integer minor units using the currency's scale. Core stays integer-only; this is the boundary helper. Strings andBigDecimalfollow the shared contract (contracts/amount-vectors.json, seeAmounts.toMinor(String, int)): ASCIIdigits[.digits]only, never rounded, more fractional digits than the scale refused (trailing zeros included), int64 range. A refusal is anAmountFormatExceptioncarrying the contract's reason.Accepted:
Long/Integer(taken as-is in minor units),BigDecimal,Stringlike"12.50".Double/Floatare REJECTED outright (binary-rounding hazard); pass a string or BigDecimal.- Parameters:
value- user-supplied amountcurrency- alpha-3 code or numeric (passed throughnormalize(Object)) for scale lookup- Returns:
- integer minor units for the wire
-
amountIntToDecimal
DASH-6: inverse for display. Returns aBigDecimalat the currency's scale (e.g.BigDecimal("12.50")for USD whenminorUnits=1250). For the contract's string form useAmounts.formatMinor(long, int). -
containsNumeric
public boolean containsNumeric(int numeric) -
containsCode
-
size
public int size() -
all
-
normalize
Coerce a request-supplied currency value to its integer numeric. Alpha-3 strings are resolved via the catalog. Numerics (and numeric strings) are validated against the catalog as well — values not in the canonical list (or override) are rejected. Unknown values throwIllegalArgumentException.
-