Removed duplicate Integer parsing code

master
Evan Harris 5 years ago
parent 4a1493e474
commit a44cad0c5b
No known key found for this signature in database
GPG Key ID: FF3BD4DA59FF9EDC
  1. 48
      airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java

@ -219,42 +219,27 @@ public class JaudiotaggerParser extends MetaDataParser {
* track numbers on the form "4/12". * track numbers on the form "4/12".
*/ */
private Integer parseTrackNumber(String trackNumber) { private Integer parseTrackNumber(String trackNumber) {
if (trackNumber == null) { return parseIntegerPattern(trackNumber, TRACK_NUMBER_PATTERN);
return null;
} }
Integer result = null; private Integer parseYear(String year) {
return parseIntegerPattern(year, YEAR_NUMBER_PATTERN);
try {
result = Integer.valueOf(trackNumber);
} catch (NumberFormatException x) {
Matcher matcher = TRACK_NUMBER_PATTERN.matcher(trackNumber);
if (matcher.matches()) {
try {
result = Integer.valueOf(matcher.group(1));
} catch (NumberFormatException e) {
return null;
}
}
}
if (Integer.valueOf(0).equals(result)) {
return null;
}
return result;
} }
private Integer parseYear(String year) { private Integer parseIntegerPattern(String str, Pattern pattern) {
if (year == null) { if (str == null) {
return null; return null;
} }
Integer result = null; Integer result = null;
try { try {
result = Integer.valueOf(year); result = Integer.valueOf(str);
} catch (NumberFormatException x) { } catch (NumberFormatException x) {
Matcher matcher = YEAR_NUMBER_PATTERN.matcher(year); if (pattern == null) {
return null;
}
Matcher matcher = pattern.matcher(str);
if (matcher.matches()) { if (matcher.matches()) {
try { try {
result = Integer.valueOf(matcher.group(1)); result = Integer.valueOf(matcher.group(1));
@ -272,18 +257,7 @@ public class JaudiotaggerParser extends MetaDataParser {
private Integer parseInteger(String s) { private Integer parseInteger(String s) {
s = StringUtils.trimToNull(s); s = StringUtils.trimToNull(s);
if (s == null) { return parseIntegerPattern(s, null);
return null;
}
try {
Integer result = Integer.valueOf(s);
if (Integer.valueOf(0).equals(result)) {
return null;
}
return result;
} catch (NumberFormatException x) {
return null;
}
} }
/** /**

Loading…
Cancel
Save