From d0fb6a9b6582738e5b92b50d8d1977aad403b184 Mon Sep 17 00:00:00 2001 From: N7ghtm4r3 Date: Tue, 12 Jul 2022 20:27:56 +0200 Subject: [PATCH] Remap coins.json for CryptocurrencyTool Add ScientificNotationParser tool --- .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .idea/uiDesigner.xml | 124 ++++++++++++++++++ .idea/workspace.xml | 18 ++- .../apimanager/Manager/APIRequest.java | 2 +- .../Tools/Formatters/NumberFormatter.java | 35 ----- .../Formatters/ScientificNotationParser.java | 67 ++++++++++ .../Tools/Trading/TradingTools.java | 8 +- 7 files changed, 209 insertions(+), 45 deletions(-) create mode 100644 .idea/uiDesigner.xml delete mode 100644 src/main/java/com/tecknobit/apimanager/Tools/Formatters/NumberFormatter.java create mode 100644 src/main/java/com/tecknobit/apimanager/Tools/Formatters/ScientificNotationParser.java diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index bbc931199e7adfaf60e516ca934d74c7a123df6f..0b3d6a203592ee54a126f79a413763f084b08c54 100644 GIT binary patch literal 17 VcmZQ>)6joi^x^Fz1~6cE1^_y$1xEk? literal 17 VcmZQ>)6joi^x^Fz1~6dL1OPgY1uOsn diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9fe953c..d2ce610 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,12 +5,13 @@ - + + - - - + + + diff --git a/src/main/java/com/tecknobit/apimanager/Manager/APIRequest.java b/src/main/java/com/tecknobit/apimanager/Manager/APIRequest.java index a15ff3f..eafff37 100644 --- a/src/main/java/com/tecknobit/apimanager/Manager/APIRequest.java +++ b/src/main/java/com/tecknobit/apimanager/Manager/APIRequest.java @@ -391,7 +391,7 @@ public T getJSONErrorResponse() { /** Method to get JSON object of response of request, already red, without read again {@link HttpURLConnection}'s stream * @param response: success response or errorResponse * @return response of request formatted as {@link JSONObject} or {@link JSONArray} object - * @throws JSONException if is not a JSON format response and return response as {@link String} + * @throws JSONException if is not a JSON sNotationParse response and return response as {@link String} * **/ private T getJSONResponseObject(String response){ try { diff --git a/src/main/java/com/tecknobit/apimanager/Tools/Formatters/NumberFormatter.java b/src/main/java/com/tecknobit/apimanager/Tools/Formatters/NumberFormatter.java deleted file mode 100644 index 3b3358f..0000000 --- a/src/main/java/com/tecknobit/apimanager/Tools/Formatters/NumberFormatter.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.tecknobit.apimanager.Tools.Formatters; - -import static java.lang.String.valueOf; - -public abstract class NumberFormatter { - - public static String format(T value, boolean numericFormat){ - if(value == null) - throw new IllegalArgumentException("Value cannot be null"); - if(!(value instanceof Integer)) { - final String[] valueDetails = valueOf(value).split("\\."); - System.out.println(valueDetails[0].length()); - System.out.println("a" + valueDetails[1]); - return format(valueDetails[0].length(), valueDetails[1].length(), value, numericFormat); - } - return valueOf(value); - } - - public static String format(int integers, int decimals, T value, boolean numericFormat){ - if(integers < 0) - throw new IllegalArgumentException("Integers digits value must be positive"); - if(decimals < 0) - throw new IllegalArgumentException("Decimals digits value must be positive"); - if(value == null) - throw new IllegalArgumentException("Value cannot be null"); - if(!(value instanceof Integer)) { - String formattedNumber = String.format("%"+ integers + "." + decimals + "f", value); - if(numericFormat) - return formattedNumber.replace(",", "."); - return formattedNumber; - } - return valueOf(value); - } - -} diff --git a/src/main/java/com/tecknobit/apimanager/Tools/Formatters/ScientificNotationParser.java b/src/main/java/com/tecknobit/apimanager/Tools/Formatters/ScientificNotationParser.java new file mode 100644 index 0000000..3771e8f --- /dev/null +++ b/src/main/java/com/tecknobit/apimanager/Tools/Formatters/ScientificNotationParser.java @@ -0,0 +1,67 @@ +package com.tecknobit.apimanager.Tools.Formatters; + +import static java.lang.Integer.parseInt; +import static java.lang.String.valueOf; + +/** + * The {@code ScientificNotationParser} class is a useful class tool to get a numeric value without scientific notation + * @author Tecknobit N7ghtm4r3 + * **/ + +public abstract class ScientificNotationParser { + + /** Method to parse a numeric value and format without scientific notation + * @param value: value to fetch without scientific notation + * @return value as {@link String} (es.) 9.2221111228E-6 -> 0.0000092221111228 + * **/ + public static String sNotationParse(Number value){ + if(value == null) + throw new IllegalArgumentException("Value cannot be null"); + if(!(value instanceof Integer)) { + String number = valueOf(value); + if(number.contains("E")) { + int zeroCounter = parseInt(number.split("-")[1]); + return "0." + "0".repeat(zeroCounter - 1) + "" + valueOf((double)value * Math.pow(10, zeroCounter)) + .replace(".", ""); + }else { + int integers = number.split("\\.")[0].length(); + return sNotationParse(integers, (((number.length()) - integers) - 1), value); + } + } + return valueOf(value); + } + + /** Method to parse a numeric value and format without scientific notation + * @param decimals: number of digits after comma + * @param value: value to fetch without scientific notation + * @return value as {@link String} (es.) 9.2221111228E-6 -> 0.0000092221111228 + * **/ + public static String sNotationParse(int decimals, Number value){ + if(decimals < 0) + throw new IllegalArgumentException("Decimals digits value must be positive"); + if(value == null) + throw new IllegalArgumentException("Value cannot be null"); + if(!(value instanceof Integer)) + return String.format("%." + decimals + "f", value).replace(",", "."); + return valueOf(value); + } + + /** Method to parse a numeric value and format without scientific notation + * @param integers: number of digits before comma + * @param decimals: number of digits after comma + * @param value: value to fetch without scientific notation + * @return value as {@link String} (es.) 9.2221111228E-6 -> 0.0000092221111228 + * **/ + public static String sNotationParse(int integers, int decimals, Number value){ + if(integers < 0) + throw new IllegalArgumentException("Integers digits value must be positive"); + if(decimals < 0) + throw new IllegalArgumentException("Decimals digits value must be positive"); + if(value == null) + throw new IllegalArgumentException("Value cannot be null"); + if(!(value instanceof Integer)) + return String.format("%"+ integers + "." + decimals + "f", value).replace(",", "."); + return valueOf(value); + } + +} diff --git a/src/main/java/com/tecknobit/apimanager/Tools/Trading/TradingTools.java b/src/main/java/com/tecknobit/apimanager/Tools/Trading/TradingTools.java index 8b8177a..22b7314 100644 --- a/src/main/java/com/tecknobit/apimanager/Tools/Trading/TradingTools.java +++ b/src/main/java/com/tecknobit/apimanager/Tools/Trading/TradingTools.java @@ -58,8 +58,8 @@ public String textualizeAssetPercent(double startValue, double lastValue, int de return textualizeAssetPercent(computeAssetPercent(startValue, lastValue, decimalDigits)); } - /** Method to format percent between two values and textualize it - * @param percent: value to format + /** Method to sNotationParse percent between two values and textualize it + * @param percent: value to sNotationParse * @return percent value formatted es. +8% or -8% as {@link String} * **/ public String textualizeAssetPercent(double percent){ @@ -71,8 +71,8 @@ else if(percent < 0) return "=" + percent + "%"; } - /** Method to format percent between two values and textualize it - * @param percent: value to format + /** Method to sNotationParse percent between two values and textualize it + * @param percent: value to sNotationParse * @param decimalDigits: number of digits to round final value * @return percent value formatted es. +8% or -8% as {@link String} * **/