Skip to content

Commit fa630c3

Browse files
graycreateclaude
andauthored
refactor: improve node topic count parsing with better error handling (#115)
- Rename totalStr to totalCountRaw for better clarity - Add null/empty check before parsing - Use specific NumberFormatException instead of generic Exception - Add error logging for failed parsing attempts - Add descriptive comment explaining the field purpose This is a follow-up to PR #82, implementing improvements suggested by GitHub Copilot review. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 39f9b59 commit fa630c3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

app/src/main/java/me/ghui/v2er/network/bean/NodeTopicInfo.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import me.ghui.v2er.network.Constants;
1212
import me.ghui.v2er.util.UriUtils;
1313
import me.ghui.v2er.util.Utils;
14+
import me.ghui.v2er.util.L;
1415

1516
/**
1617
* Created by ghui on 27/05/2017.
@@ -21,7 +22,7 @@
2122
public class NodeTopicInfo extends BaseInfo {
2223

2324
@Pick("span.topic-count strong")
24-
public String totalStr;
25+
private String totalCountRaw; // Raw topic count string from HTML (may contain thousand separators)
2526
@Pick(value = "a[href*=favorite/] ", attr = Attrs.HREF)
2627
private String favoriteLink;
2728
@Pick("div.box div.cell:has(table)")
@@ -32,9 +33,16 @@ public void setItems(List<Item> items) {
3233
}
3334

3435
public int getTotal() {
36+
if (totalCountRaw == null || totalCountRaw.isEmpty()) {
37+
return 0;
38+
}
39+
3540
try {
36-
return Integer.parseInt(totalStr.replaceAll("[^0-9]", ""));
37-
} catch (Exception e) {
41+
// Remove thousand separators (commas) and any other non-numeric characters
42+
String cleanedNumber = totalCountRaw.replaceAll("[^0-9]", "");
43+
return Integer.parseInt(cleanedNumber);
44+
} catch (NumberFormatException e) {
45+
L.e("Failed to parse topic count: " + totalCountRaw + ", error: " + e.getMessage());
3846
return 0;
3947
}
4048
}
@@ -70,7 +78,7 @@ public String getOnce() {
7078
public String toString() {
7179
return "NodeTopicInfo{" +
7280
"favoriteLink=" + favoriteLink +
73-
",total=" + totalStr +
81+
",total=" + totalCountRaw +
7482
", items=" + items +
7583
'}';
7684
}

0 commit comments

Comments
 (0)