Class Price
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull Priceadd(double amount) Adds an amount to this Price's amount.@NotNull PriceAdds a Price's amount to this Price's amount.int@NotNull PriceConverts this Price to another Price with Economy.static @Nullable Pricedeserialize(@Nullable Map<String, Object> serial) Deserializes a Map into a Price.booleandoubleFetches the Price amount.@Nullable EconomyFetches the Price's Economy.charFetches the Price's Symbol.doubleMultiplies the amount by the economy's conversion scale (1 if economy is null).inthashCode()void@NotNull Priceremove(double amount) Removes this amount from this Price's current amount.@NotNull PriceRemoves a Price's amount from this Price's amount.@NotNull PricesetAmount(double amount) Sets the current Price amount.@NotNull PricesetEconomy(@Nullable Economy econ) Sets the current Price's Economy.toString()void
-
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
Constructs a Price.- Parameters:
econ- Economy to useamount- Price Amount- Throws:
IllegalArgumentException- if amount is not positive
-
Price
Constructs a Price from a Map Entry.- Parameters:
entry- Map Entry
-
-
Method Details
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
getAmount
public double getAmount()Fetches the Price amount.- Returns:
- Price Amount
-
setAmount
Sets the current Price amount.- Parameters:
amount- Price Amount- Returns:
- this Price, for chaining
- Throws:
IllegalArgumentException- if amount is not positive
-
getEconomy
Fetches the Price's Economy.- Returns:
- Price's Economy
-
setEconomy
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
Adds an amount to this Price's amount.- Parameters:
amount- Amount to add- Returns:
- this Price, for chaining
-
add
Adds a Price's amount to this Price's amount.- Parameters:
price- Price to add- Returns:
- this Price, for chaining
-
remove
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
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
-
hashCode
public int hashCode() -
toString
-
serialize
- Specified by:
serializein interfaceConfigurationSerializable
-
deserialize
@Nullable public static @Nullable Price deserialize(@Nullable @Nullable Map<String, Object> serial) throws IllegalArgumentExceptionDeserializes a Map into a Price.- Parameters:
serial- Serialization fromserialize()- Returns:
- Deserialized Price
- Throws:
IllegalArgumentException- if an argument is malformed or missing
-
compareTo
- Specified by:
compareToin interfaceComparable<Price>
-