All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dcutils.rpg.currency.Unit Maven / Gradle / Ivy

package dcutils.rpg.currency;

// Import Java JDK Classes
import java.util.Comparator;

/**
 * A Unit represents a single monetary type and its base value.
* I.e.: A Copper can only represent a single copper piece.
* If you need to represent multiple Copper pieces, use the Quantity class. * @see Quantity * @author dca */ public enum Unit implements Comparator { COPPER("Copper", 1), SILVER("Silver", COPPER.getBaseValue() * 100), GOLD("Gold", SILVER.getBaseValue() * 100); private String baseName; private int baseValue; private Unit(String name, int value) { baseName = name; baseValue = value; } // END constructor public String getBaseName() { return baseName; } // END getBaseName public int getBaseValue() { return baseValue; } // END getBaseValue @Override public String toString() { return String.format("%s (%d)", baseName, baseValue); } // END toString @Override public int compare(Unit lhs, Unit rhs) { if(null == lhs ^ null == rhs) return -1; else if(null == lhs && null == rhs) return 0; else return lhs.getBaseValue() - rhs.getBaseValue(); } // END compare } // END enum Unit




© 2015 - 2025 Weber Informatics LLC | Privacy Policy