Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incrementa validacoes para o campo year #5710

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/logic/integrity/YearChecker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.logic.integrity;

import java.util.Calendar;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;
Expand All @@ -23,6 +24,10 @@ public class YearChecker implements ValueChecker {
*/
@Override
public Optional<String> checkValue(String value) {
char [] C_value = value.toCharArray();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char[] seems to be very old school.

Calendar cal = Calendar.getInstance();
int ActualYear = cal.get(Calendar.YEAR);

if (StringUtil.isBlank(value)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the first statement in the method

return Optional.empty();
}
Expand All @@ -35,6 +40,14 @@ public Optional<String> checkValue(String value) {
return Optional.of(Localization.lang("last four nonpunctuation characters should be numerals"));
}

if(!Character.isDigit(C_value[0])){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you use Eclipse or IntelliJ? In IntelliJ, we have custom format rules: https://github.com/JabRef/jabref/wiki/Guidelines-for-setting-up-a-local-workspace#intellij. Maybe, we generate the Eclipse rules also at gradlew eclipse (see https://github.com/JabRef/jabref/wiki/Guidelines-for-setting-up-a-local-workspace#set-up-eclipse)

return Optional.of(Localization.lang("First character should be numeral"));
}

if(ActualYear < Integer.parseInt(value)) {
return Optional.of(Localization.lang("Year should be smaller or equal then actual year"));
}

return Optional.empty();
}
}