-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Implemented #1345 - cleanup ISSN * Fixed comments * Extracted ISSN class * Added tests for ISSN and ISBN
- Loading branch information
Showing
29 changed files
with
352 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/net/sf/jabref/logic/cleanup/ISSNCleanup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.sf.jabref.logic.cleanup; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import net.sf.jabref.logic.util.ISSN; | ||
import net.sf.jabref.model.FieldChange; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
import net.sf.jabref.model.entry.FieldName; | ||
|
||
|
||
public class ISSNCleanup implements CleanupJob { | ||
|
||
@Override | ||
public List<FieldChange> cleanup(BibEntry entry) { | ||
Optional<String> issnString = entry.getFieldOptional(FieldName.ISSN); | ||
if (!issnString.isPresent()) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
ISSN issn = new ISSN(issnString.get()); | ||
if (issn.isCanBeCleaned()) { | ||
String newValue = issn.getCleanedISSN(); | ||
FieldChange change = new FieldChange(entry, FieldName.ISSN, issnString.get(), newValue); | ||
entry.setField(FieldName.ISSN, newValue); | ||
return Collections.singletonList(change); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package net.sf.jabref.logic.util; | ||
|
||
import java.util.Objects; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class ISSN { | ||
|
||
private static final Pattern ISSN_PATTERN = Pattern.compile("^\\d{4}-\\d{3}[\\dxX]$"); | ||
private static final Pattern ISSN_PATTERN_NODASH = Pattern.compile("^(\\d{4})(\\d{3}[\\dxX])$"); | ||
|
||
private final String issnString; | ||
|
||
|
||
public ISSN(String issnString) { | ||
this.issnString = Objects.requireNonNull(issnString).trim(); | ||
} | ||
|
||
public boolean isValidFormat() { | ||
Matcher issnMatcher = ISSN_PATTERN.matcher(issnString); | ||
return (issnMatcher.matches()); | ||
} | ||
|
||
public boolean isCanBeCleaned() { | ||
Matcher issnNoDashMatcher = ISSN_PATTERN_NODASH.matcher(issnString); | ||
return (issnNoDashMatcher.matches()); | ||
} | ||
|
||
public String getCleanedISSN() { | ||
Matcher issnNoDashMatcher = ISSN_PATTERN_NODASH.matcher(issnString); | ||
if (issnNoDashMatcher.find()) { | ||
return issnNoDashMatcher.replaceFirst("$1-$2"); | ||
} | ||
return issnString; | ||
} | ||
|
||
public boolean isValidChecksum() { | ||
// Check that the control digit is correct, see e.g. https://en.wikipedia.org/wiki/International_Standard_Serial_Number | ||
int sum = 0; | ||
for (int pos = 0; pos <= 7; pos++) { | ||
char c = issnString.charAt(pos); | ||
if (pos != 4) { | ||
sum += (c - '0') * ((8 - pos) + (pos > 4 ? 1 : 0)); | ||
} | ||
} | ||
char control = issnString.charAt(8); | ||
if ((control == 'x') || (control == 'X')) { | ||
control = '9' + 1; | ||
} | ||
return (((((sum % 11) + control) - '0') == 11) || ((sum % 11) == 0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.