Java Code Examples for org.joda.money.CurrencyUnit#of()

The following examples show how to use org.joda.money.CurrencyUnit#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSingleColumnMoneyUserType.java    From jadira with Apache License 2.0 6 votes vote down vote up
@Override
public void applyConfiguration(SessionFactory sessionFactory) {

   	CurrencyUnitConfigured columnMapper = (CurrencyUnitConfigured) getColumnMapper();
   	if (currencyUnit == null) {

   		String currencyString = null;
		if (parameterValues != null) {
			currencyString = parameterValues.getProperty("currencyCode");
		}
		if (currencyString == null) {
			currencyString = ConfigurationHelper.getProperty("currencyCode");
		}
		if (currencyString != null) {

			currencyUnit = CurrencyUnit.of(currencyString);
		} else {
			throw new IllegalStateException(getClass().getSimpleName() + " requires currencyCode to be defined as a parameter, or the jadira.usertype.currencyCode Hibernate property to be defined");
		}
   	}
   	columnMapper.setCurrencyUnit(currencyUnit);
   }
 
Example 2
Source File: CurrencyUnitAdapter.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/** Parses a string into a {@link CurrencyUnit} object. */
@Override
public CurrencyUnit unmarshal(String currency) throws UnknownCurrencyException {
  try {
    return CurrencyUnit.of(nullToEmpty(currency).trim());
  } catch (IllegalArgumentException e) {
    throw new UnknownCurrencyException();
  }
}
 
Example 3
Source File: IntegerColumnCurrencyUnitMapper.java    From jadira with Apache License 2.0 5 votes vote down vote up
@Override
public CurrencyUnit fromNonNullString(String s) {
	try {
		return CurrencyUnit.ofNumericCode(s);
	} catch (IllegalCurrencyException e) {
		return CurrencyUnit.of(s);
	}
}
 
Example 4
Source File: MonetaryUtil.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
public static String formatUnit(BigDecimal unit, String currencyCode) {
    if (StringUtils.isEmpty(currencyCode)) {
        return "0";
    }

    var currencyUnit = CurrencyUnit.of(Objects.requireNonNull(currencyCode).toUpperCase(Locale.ENGLISH));
    return Objects.requireNonNull(unit).setScale(currencyUnit.getDecimalPlaces(), HALF_UP).toPlainString();
}
 
Example 5
Source File: MonetaryUtil.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
public static BigDecimal centsToUnit(long cents, String currencyCode) {
    if(cents == 0 || StringUtils.isEmpty(currencyCode)) {
        return BigDecimal.ZERO;
    }
    var currencyUnit = CurrencyUnit.of(currencyCode.toUpperCase(Locale.ENGLISH));
    int scale = currencyUnit.getDecimalPlaces();
    return new BigDecimal(cents).divide(BigDecimal.TEN.pow(scale), scale, HALF_UP);
}
 
Example 6
Source File: EventWithAdditionalInfo.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
public CurrencyDescriptor getCurrencyDescriptor() {
    if(event.isFreeOfCharge()) {
        return null;
    }
    var currencyUnit = CurrencyUnit.of(event.getCurrency());
    return new CurrencyDescriptor(currencyUnit.getCode(), currencyUnit.toCurrency().getDisplayName(), currencyUnit.getSymbol(), currencyUnit.getDecimalPlaces());
}
 
Example 7
Source File: ClosingAvailableBalance.java    From banking-swift-messages-java with MIT License 5 votes vote down vote up
public static ClosingAvailableBalance of(GeneralField field) throws FieldNotationParseException {
    Preconditions.checkArgument(field.getTag().equals(FIELD_TAG_64), "unexpected field tag '%s'", field.getTag());

    List<String> subFields = SWIFT_NOTATION.parse(field.getContent());

    DebitCreditMark debitCreditMark = DebitCreditMark.ofFieldValue(subFields.get(0));
    LocalDate entryDate = LocalDate.parse(subFields.get(1), ENTRY_DATE_FORMATTER);
    CurrencyUnit amountCurrency = CurrencyUnit.of(subFields.get(2));
    BigDecimal amountValue = SwiftDecimalFormatter.parse(subFields.get(3));
    BigMoney amount = BigMoney.of(amountCurrency, amountValue);

    return new ClosingAvailableBalance(entryDate, debitCreditMark, amount);
}
 
Example 8
Source File: CurrencyUnitTranslatorFactory.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Override
SimpleTranslator<CurrencyUnit, String> createTranslator() {
  return new SimpleTranslator<CurrencyUnit, String>(){
    @Override
    public CurrencyUnit loadValue(String datastoreValue) {
      return CurrencyUnit.of(datastoreValue);
    }

    @Override
    public String saveValue(CurrencyUnit pojoValue) {
      return pojoValue.toString();
    }};
}
 
Example 9
Source File: CurrencyToBillingConverter.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Override
Map.Entry<CurrencyUnit, BillingAccountEntry> convertToEntityMapEntry(
    Map.Entry<String, String> entry) {
  CurrencyUnit currencyUnit = CurrencyUnit.of(entry.getKey());
  BillingAccountEntry billingAccountEntry =
      new BillingAccountEntry(currencyUnit, entry.getValue());
  return Maps.immutableEntry(currencyUnit, billingAccountEntry);
}
 
Example 10
Source File: ForwardAvailableBalance.java    From banking-swift-messages-java with MIT License 5 votes vote down vote up
public static ForwardAvailableBalance of(GeneralField field) throws FieldNotationParseException {
    Preconditions.checkArgument(field.getTag().equals(FIELD_TAG_65), "unexpected field tag '%s'", field.getTag());

    List<String> subFields = SWIFT_NOTATION.parse(field.getContent());

    DebitCreditMark debitCreditMark = DebitCreditMark.ofFieldValue(subFields.get(0));
    LocalDate entryDate = LocalDate.parse(subFields.get(1), DATE_FORMATTER);
    CurrencyUnit amountCurrency = CurrencyUnit.of(subFields.get(2));
    BigDecimal amountValue = SwiftDecimalFormatter.parse(subFields.get(3));

    BigMoney amount = BigMoney.of(amountCurrency, amountValue);

    return new ForwardAvailableBalance(entryDate, debitCreditMark, amount);
}
 
Example 11
Source File: OpeningBalance.java    From banking-swift-messages-java with MIT License 5 votes vote down vote up
public static OpeningBalance of(GeneralField field) throws FieldNotationParseException {
    Preconditions.checkArgument(field.getTag().equals(FIELD_TAG_60F) || field.getTag().equals(FIELD_TAG_60M), "unexpected field tag '%s'", field.getTag());
    Type type = field.getTag().equals(FIELD_TAG_60F) ? Type.OPENING : Type.INTERMEDIATE;

    List<String> subFields = SWIFT_NOTATION.parse(field.getContent());

    DebitCreditMark debitCreditMark = subFields.get(0) != null ? DebitCreditMark.ofFieldValue(subFields.get(0)) : null;
    LocalDate date = LocalDate.parse(subFields.get(1), DATE_FORMATTER);
    CurrencyUnit amountCurrency = CurrencyUnit.of(subFields.get(2));
    BigDecimal amountValue = SwiftDecimalFormatter.parse(subFields.get(3));
    BigMoney amount = BigMoney.of(amountCurrency, amountValue);

    return new OpeningBalance(type, date, debitCreditMark, amount);
}
 
Example 12
Source File: FloorLimitIndicator.java    From banking-swift-messages-java with MIT License 5 votes vote down vote up
public static FloorLimitIndicator of(GeneralField field) throws FieldNotationParseException {
    Preconditions.checkArgument(field.getTag().equals(FIELD_TAG_34F), "unexpected field tag '%s'", field.getTag());

    List<String> subFields = SWIFT_NOTATION.parse(field.getContent());

    CurrencyUnit amountCurrency = CurrencyUnit.of(subFields.get(0));
    DebitCreditMark debitCreditMark = subFields.get(1) != null ? DebitCreditMark.ofFieldValue(subFields.get(1)) : null;
    BigDecimal amountValue = SwiftDecimalFormatter.parse(subFields.get(2));
    BigMoney amount = BigMoney.of(amountCurrency, amountValue);

    return new FloorLimitIndicator(debitCreditMark, amount);
}
 
Example 13
Source File: ClosingBalance.java    From banking-swift-messages-java with MIT License 5 votes vote down vote up
public static ClosingBalance of(GeneralField field) throws FieldNotationParseException {
    Preconditions.checkArgument(field.getTag().equals(FIELD_TAG_62F) || field.getTag().equals(FIELD_TAG_62M), "unexpected field tag '%s'", field.getTag());
    Type type = field.getTag().equals(FIELD_TAG_62F) ? Type.CLOSING : Type.INTERMEDIATE;

    List<String> subFields = SWIFT_NOTATION.parse(field.getContent());

    DebitCreditMark debitCreditMark = DebitCreditMark.ofFieldValue(subFields.get(0));
    LocalDate date = LocalDate.parse(subFields.get(1), DATE_FORMATTER);
    CurrencyUnit amountCurrency = CurrencyUnit.of(subFields.get(2));
    BigDecimal amountValue = SwiftDecimalFormatter.parse(subFields.get(3));
    BigMoney amount = BigMoney.of(amountCurrency, amountValue);

    return new ClosingBalance(type, date, debitCreditMark, amount);
}
 
Example 14
Source File: TransactionSummary.java    From banking-swift-messages-java with MIT License 5 votes vote down vote up
public static TransactionSummary of(GeneralField field) throws FieldNotationParseException {
    Preconditions.checkArgument(field.getTag().equals(FIELD_TAG_90D) || field.getTag().equals(FIELD_TAG_90C), "unexpected field tag '%s'", field.getTag());
    DebitCreditMark type = field.getTag().equals(FIELD_TAG_90D) ? DebitCreditMark.DEBIT : DebitCreditMark.CREDIT;

    List<String> subFields = SWIFT_NOTATION.parse(field.getContent());

    int transactionCount = Integer.parseInt(subFields.get(0));
    CurrencyUnit amountCurrency = CurrencyUnit.of(subFields.get(1));
    BigDecimal amountValue = SwiftDecimalFormatter.parse(subFields.get(2));
    BigMoney amount = BigMoney.of(amountCurrency, amountValue);

    return new TransactionSummary(type, transactionCount, amount);
}
 
Example 15
Source File: CurrencyUnitConverter.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public CurrencyUnit convertToEntityAttribute(@Nullable String columnValue) {
  return (columnValue == null) ? null : CurrencyUnit.of(columnValue);
}
 
Example 16
Source File: KeyValueMapParameter.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
protected CurrencyUnit parseKey(String rawKey) {
  return CurrencyUnit.of(rawKey);
}
 
Example 17
Source File: MonetaryUtil.java    From alf.io with GNU General Public License v3.0 4 votes vote down vote up
public static BigDecimal fixScale(BigDecimal raw, String currencyCode) {
    var currencyUnit = CurrencyUnit.of(currencyCode.toUpperCase(Locale.ENGLISH));
    return raw.setScale(currencyUnit.getDecimalPlaces(), HALF_UP);
}
 
Example 18
Source File: StringColumnCurrencyUnitMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public CurrencyUnit fromNonNullValue(String s) {
    return CurrencyUnit.of(s);
}