Class Money<T extends Money<T>>

java.lang.Object
com.truebubo.maniflow.money.CurrencyTypes.Money<T>
Type Parameters:
T - Currency itself. Used for making operation only between the same currency
Direct Known Subclasses:
CZK, EUR, GBP, USD

public abstract sealed class Money<T extends Money<T>> extends Object permits CZK, EUR, GBP, USD
Holds the value of money
  • Constructor Details

    • Money

      protected Money(@NonNull BigDecimal amount, @NonNull CurrencyDesignation designation)
      Creates money
      Parameters:
      amount - Amount compared to base
      designation - 3 letter code of currency
  • Method Details

    • designation

      public final CurrencyDesignation designation()
      Gets currency designation of money held
      Returns:
      designation
    • to

      public final <ToCurrency extends Money<ToCurrency>> ToCurrency to(@NonNull ToCurrency toCurrencyInstance) throws ConversionFailedException
      Converts to another currency
      Type Parameters:
      ToCurrency - Currency types we wish to convert to
      Parameters:
      toCurrencyInstance - Instance of the currency we want to make this to
      Returns:
      this converted to another currency
      Throws:
      ConversionFailedException - Could not be converted
    • amount

      @NonNull public final BigDecimal amount()
      Amount compared to base of currency
      Returns:
      amount
    • toString

      @NonNull public final String toString()
      Overrides:
      toString in class Object
    • make

      public abstract T make(BigDecimal amount)
      Used to force children to give us their instance
      Parameters:
      amount - How much of a currency do we own
      Returns:
      Money in given currency
    • add

      public final T add(@NonNull T other)
      Adds another money with given currency
      Parameters:
      other - Other money
      Returns:
      money with combined amounts
    • multiply

      public final T multiply(@NonNull BigDecimal multiplier)
      Multiplies amount by a scalar
      Parameters:
      multiplier - Multiplied by this value
      Returns:
      Increased value by scalar
    • multiply

      public final T multiply(long multiplier)
      Multiplies amount by a scalar
      Parameters:
      multiplier - Multiplied by this value
      Returns:
      Increased value by scalar
    • multiply

      public final T multiply(double multiplier)
      Multiplies amount by a scalar
      Parameters:
      multiplier - Multiplied by this value
      Returns:
      Increased value by scalar