-
-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Labels
Description
My target is to create "custom" units for electricity prices: €/MWh and c/kWh. I added following classes:
public class CurrencyDimension implements Dimension, Serializable { // Copied from BaseUnit because its final ?!?
// The symbol is '¤'
}
public class Money extends AbstractNumberQuantity<Money> { // Copied from NumberQuantity because its final ?!?
// Uses BigDecimal as a value.
@Override
public String toString() {
// Workaround for tech.units.indriya.format.SimpleUnitFormat$DefaultFormat.format(SimpleUnitFormat.java:907)
return getValue() + " " + getUnit();
}
}
public class CurrencyUnit extends AbstractUnit<Money> { // Again it would be nice to extend BaseUnit
public final @NonNull Currency currency; // Internally uses java.util.Currency
@Override
public String toString() {
// Workaround for tech.units.indriya.format.SimpleUnitFormat$DefaultFormat.format(SimpleUnitFormat.java:907)
return getSymbol();
}
}
public class CurrencyCentUnit extends CurrencyUnit { // Symbol is 'c' and name is currency display name + " cent".
private final CurrencyUnit baseUnit;
}
public class Monetary extends AbstractSystemOfUnits { } // This seems to be optionalWhen i try to print quantity i get error:
java.lang.IllegalArgumentException: Cannot format given Object as a Unit
at tech.units.indriya.format.SimpleUnitFormat$DefaultFormat.format(SimpleUnitFormat.java:907)
That is because my class isn't AlternateUnit or ProductUnit.
- Can you support standard Unit and Quantity interfaces?
- Can create another system of units and combine those different systems with this library? I think I should. Or should I fork this and do the modifications.
- And what benefits you get by marking all classes final?
I'm not planning to do currency exchanges (although its possible use some service). Just playing on same currency and combining to SI system.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
📋 Backlog