From: Niki Roo Date: Fri, 12 Apr 2019 07:35:01 +0000 (+0200) Subject: search: small code cleanup X-Git-Tag: fanfix-3.0.0~131 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=74a4396114e66c029534ecb76c6e0f43a0402d3e;p=fanfix.git search: small code cleanup --- diff --git a/src/be/nikiroo/fanfix/reader/cli/CliReader.java b/src/be/nikiroo/fanfix/reader/cli/CliReader.java index 22d11cb..89eb3ac 100644 --- a/src/be/nikiroo/fanfix/reader/cli/CliReader.java +++ b/src/be/nikiroo/fanfix/reader/cli/CliReader.java @@ -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++; } } diff --git a/src/be/nikiroo/fanfix/searchable/Fanfiction.java b/src/be/nikiroo/fanfix/searchable/Fanfiction.java index 6814e63..28c0d1b 100644 --- a/src/be/nikiroo/fanfix/searchable/Fanfiction.java +++ b/src/be/nikiroo/fanfix/searchable/Fanfiction.java @@ -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 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