java.lang.Object
us.teaminceptus.novaconomy.api.util.Price
All Implemented Interfaces:
Externalizable, Serializable, Comparable<Price>, ConfigurationSerializable

public final class Price extends Object implements ConfigurationSerializable, Comparable<Price>, Externalizable
Utility Class for creating a Price with an Economy
See Also:
  • Constructor Details

    • Price

      public Price()
      Constructs a Price with an amount of 1.
    • Price

      public Price(double amount)
      Constructs a Price with a null economy.
      Parameters:
      amount - Amount of money
    • Price

      public Price(@Nullable @Nullable Economy econ, double amount) throws IllegalArgumentException
      Constructs a Price.
      Parameters:
      econ - Economy to use
      amount - Price Amount
      Throws:
      IllegalArgumentException - if amount is not positive
    • Price

      public Price(@NotNull Map.Entry<Economy,Double> entry)
      Constructs a Price from a Map Entry.
      Parameters:
      entry - Map Entry
  • Method Details

    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • getAmount

      public double getAmount()
      Fetches the Price amount.
      Returns:
      Price Amount
    • setAmount

      @NotNull public @NotNull Price setAmount(double amount) throws IllegalArgumentException
      Sets the current Price amount.
      Parameters:
      amount - Price Amount
      Returns:
      this Price, for chaining
      Throws:
      IllegalArgumentException - if amount is not positive
    • getEconomy

      @Nullable public @Nullable Economy getEconomy()
      Fetches the Price's Economy.
      Returns:
      Price's Economy
    • setEconomy

      @NotNull public @NotNull Price setEconomy(@Nullable @Nullable Economy econ)
      Sets the current Price's Economy.
      Parameters:
      econ - Price Economy
      Returns:
      this Price, for chaining
    • convertTo

      @NotNull public @NotNull Price convertTo(@NotNull @NotNull Economy econ) throws IllegalArgumentException
      Converts this Price to another Price with Economy.
      Parameters:
      econ - Economy to use
      Returns:
      Converted Price with amount converted to Economy
      Throws:
      IllegalArgumentException - if economy is null
    • add

      @NotNull public @NotNull Price add(double amount)
      Adds an amount to this Price's amount.
      Parameters:
      amount - Amount to add
      Returns:
      this Price, for chaining
    • add

      @NotNull public @NotNull Price add(@Nullable @Nullable Price price)
      Adds a Price's amount to this Price's amount.
      Parameters:
      price - Price to add
      Returns:
      this Price, for chaining
    • remove

      @NotNull public @NotNull Price remove(@Nullable @Nullable Price price)
      Removes a Price's amount from this Price's amount.
      Parameters:
      price - Price to remove
      Returns:
      this Price, for chaining
    • getPriceSymbol

      public char getPriceSymbol()
      Fetches the Price's Symbol.
      Returns:
      Price Symbol
    • remove

      @NotNull public @NotNull Price remove(double amount)
      Removes this amount from this Price's current amount.
      Parameters:
      amount - Amount to remove
      Returns:
      this Price, for chaining
    • getRealAmount

      public double getRealAmount()
      Multiplies the amount by the economy's conversion scale (1 if economy is null).
      Returns:
      Real Amount, factoring in the economy's conversion scale
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • serialize

      public Map<String,Object> serialize()
      Specified by:
      serialize in interface ConfigurationSerializable
    • deserialize

      @Nullable public static @Nullable Price deserialize(@Nullable @Nullable Map<String,Object> serial) throws IllegalArgumentException
      Deserializes a Map into a Price.
      Parameters:
      serial - Serialization from serialize()
      Returns:
      Deserialized Price
      Throws:
      IllegalArgumentException - if an argument is malformed or missing
    • compareTo

      public int compareTo(@NotNull @NotNull Price r)
      Specified by:
      compareTo in interface Comparable<Price>