X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fjson%2Fv1_15%2FParsedQuantity.java;h=7ce1d12d3816efc5f1bc0a8b9906a7e1748105ee;hb=d6d15ebf2287b3e9d7c213241367ef053e971e60;hp=898d59741a22cf53e774a8b9f15f977f5ce4371f;hpb=54002a662d97289a739d3cdb9888bbab58a8064f;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java index 898d5974..7ce1d12d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2020 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -20,39 +20,21 @@ package net.ktnx.mobileledger.json.v1_15; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) -public class ParsedQuantity { - private long decimalMantissa; - private int decimalPlaces; - public ParsedQuantity() { - } - public ParsedQuantity(String input) { - parseString(input); - } - public long getDecimalMantissa() { - return decimalMantissa; - } - public void setDecimalMantissa(long decimalMantissa) { - this.decimalMantissa = decimalMantissa; - } - public int getDecimalPlaces() { - return decimalPlaces; - } - public void setDecimalPlaces(int decimalPlaces) { - this.decimalPlaces = decimalPlaces; +public class ParsedQuantity extends net.ktnx.mobileledger.json.v1_14.ParsedQuantity { + private float floatingPoint; + private boolean floatingPointSet = false; + public float getFloatingPoint() { + if (!floatingPointSet) + throw new IllegalStateException("floatingPoint is not set"); + return floatingPoint; + } + public void setFloatingPoint(float floatingPoint) { + this.floatingPoint = floatingPoint; + floatingPointSet = true; } public float asFloat() { + if (floatingPointSet) + return floatingPoint; return (float) (decimalMantissa * Math.pow(10, -decimalPlaces)); } - public void parseString(String input) { - int pointPos = input.indexOf('.'); - if (pointPos >= 0) { - String integral = input.replace(".", ""); - decimalMantissa = Long.valueOf(integral); - decimalPlaces = input.length() - pointPos - 1; - } - else { - decimalMantissa = Long.valueOf(input); - decimalPlaces = 0; - } - } }