Skip to content

Commit

Permalink
Ensure dependencies using code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
simonharrer committed Apr 5, 2016
1 parent 8aabec3 commit 5bf418e
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/main/java/net/sf/jabref/model/entry/YearUtil.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package net.sf.jabref.model.entry;

import net.sf.jabref.logic.util.strings.StringUtil;

import java.util.Calendar;

public class YearUtil {

private static final int CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR);


/**
* Will convert a two digit year using the following scheme (describe at
* http://www.filemaker.com/help/02-Adding%20and%20view18.html):
Expand Down Expand Up @@ -44,8 +41,8 @@ static String toFourDigitYear(String year, int thisYear) {
return year;
}

Integer yearNumber = StringUtil.intValueOfWithNull(year);
if(yearNumber == null) {
Integer yearNumber = intValueOfWithNull(year);
if (yearNumber == null) {
return year;
}

Expand All @@ -61,22 +58,42 @@ private static int toFourDigitYearWithInts(String year, int thisYear) {
return 0;
}

Integer yearNumber = StringUtil.intValueOfWithNull(year);
if(yearNumber == null) {
Integer yearNumber = intValueOfWithNull(year);
if (yearNumber == null) {
return 0;
}

return new Year(thisYear).toFourDigitYear(yearNumber);
}

private static Integer intValueOfWithNull(String str) {
int idx = 0;
int end;
boolean sign = false;
char ch;

if ((str == null) || ((end = str.length()) == 0) || ((((ch = str.charAt(0)) < '0') || (ch > '9')) && (!(sign = ch == '-') || (++idx == end) || ((ch = str.charAt(idx)) < '0') || (ch > '9')))) {
return null;
}

int ival = 0;
for (; ; ival *= 10) {
ival += '0' - ch;
if (++idx == end) {
return sign ? ival : -ival;
}
if (((ch = str.charAt(idx)) < '0') || (ch > '9')) {
return null;
}
}
}

private static class Year {

private final int year;
private final int century;
private final int yearShort;


public Year(int year) {
this.year = year;
this.yearShort = this.year % 100;
Expand Down

0 comments on commit 5bf418e

Please sign in to comment.