1 changed files with 29 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||
|
package project.utils; |
||||
|
|
||||
|
public class DataCleaner { |
||||
|
public static String cleanText(String text) { |
||||
|
if (text == null) return ""; |
||||
|
return text.trim() |
||||
|
.replaceAll("<[^>]*>", "") |
||||
|
.replaceAll("\\s+", " ") |
||||
|
.replaceAll("[\\r\\n]", ""); |
||||
|
} |
||||
|
|
||||
|
public static double parseRating(String ratingStr) { |
||||
|
if (ratingStr == null || ratingStr.isEmpty()) return 0.0; |
||||
|
try { |
||||
|
return Double.parseDouble(ratingStr.trim()); |
||||
|
} catch (NumberFormatException e) { |
||||
|
return 0.0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static int parseYear(String yearStr) { |
||||
|
if (yearStr == null || yearStr.isEmpty()) return 0; |
||||
|
try { |
||||
|
return Integer.parseInt(yearStr.replaceAll("[^0-9]", "")); |
||||
|
} catch (NumberFormatException e) { |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue