search: small code cleanup
authorNiki Roo <niki@nikiroo.be>
Fri, 12 Apr 2019 07:35:01 +0000 (09:35 +0200)
committerNiki Roo <niki@nikiroo.be>
Fri, 12 Apr 2019 07:35:01 +0000 (09:35 +0200)
src/be/nikiroo/fanfix/reader/cli/CliReader.java
src/be/nikiroo/fanfix/searchable/Fanfiction.java

index 22d11cbdfbbb87f9f41b28844d8317087070af1b..89eb3ac034b0ef1c9e5d338d6528a7050a200eac 100644 (file)
@@ -14,6 +14,7 @@ import be.nikiroo.fanfix.reader.BasicReader;
 import be.nikiroo.fanfix.searchable.BasicSearchable;
 import be.nikiroo.fanfix.searchable.SearchableTag;
 import be.nikiroo.fanfix.supported.SupportType;
+import be.nikiroo.utils.StringUtils;
 
 /**
  * Command line {@link Story} reader.
@@ -215,11 +216,18 @@ class CliReader extends BasicReader {
                                                for (SearchableTag subtag : subtags) {
                                                        String total = "";
                                                        if (subtag.getCount() > 0) {
-                                                               // TODO: use StringUtils fromNumber
-                                                               total = " (" + subtag.getCount() + ")";
+                                                               total = StringUtils.formatNumber(subtag
+                                                                               .getCount());
                                                        }
-                                                       System.out.println(i + ": " + subtag.getName()
-                                                                       + total);
+
+                                                       if (total.isEmpty()) {
+                                                               System.out.println(String.format("%d: %s", i,
+                                                                               subtag.getName()));
+                                                       } else {
+                                                               System.out.println(String.format("%d: %s (%s)",
+                                                                               i, subtag.getName(), total));
+                                                       }
+
                                                        i++;
                                                }
                                        }
index 6814e63648ba933d7c199fe115a8c64fabae747d..28c0d1be02613d8840f67ce55426ea7c71c98ad8 100644 (file)
@@ -126,11 +126,11 @@ class Fanfiction extends BasicSearchable {
                                                                nr = nr.substring(0, nr.length() - 1);
                                                        }
                                                        nr = nr.trim();
-                                                       
-                                                       //TODO: fix toNumber/fromNumber
+
+                                                       // TODO: fix toNumber/fromNumber
                                                        nr = nr.replaceAll("\\.[0-9]*", "");
-                                                       
-                                                       subtag.setCount(toNumber(nr));
+
+                                                       subtag.setCount(StringUtils.toNumber(nr));
                                                }
                                        }
                                }
@@ -140,33 +140,6 @@ class Fanfiction extends BasicSearchable {
                tag.setComplete(true);
        }
 
-       /**
-        * @deprecated use {@link StringUtils} when updated
-        */
-       @Deprecated
-       private static long toNumber(String value) {
-               // TODO: use StringUtils instead after update
-               long count = 0l;
-               if (value != null) {
-                       try {
-                               if (value.toLowerCase().endsWith("m")) {
-                                       count = Long.parseLong(value.substring(0,
-                                                       value.length() - 1).trim());
-                                       count *= 1000000;
-                               } else if (value.toLowerCase().endsWith("k")) {
-                                       count = Long.parseLong(value.substring(0,
-                                                       value.length() - 1).trim());
-                                       count *= 1000;
-                               } else {
-                                       count = Long.parseLong(value);
-                               }
-                       } catch (NumberFormatException pe) {
-                       }
-               }
-
-               return count;
-       }
-
        @Override
        public List<MetaData> search(String search) throws IOException {
                String encoded = URLEncoder.encode(search.toLowerCase(), "utf-8");
@@ -190,7 +163,7 @@ class Fanfiction extends BasicSearchable {
                                        url += "&p=" + page;
                                }
                        }
-                       
+
                        Document doc = load(url, false);
 
                        // Update the pages number if needed