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 e0380b7
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) {

This comment has been minimized.

Copy link
@tobiasdiez

tobiasdiez Apr 5, 2016

Member

I really don't like this...I suspect moving YearUtil to logic is also not possible, right?

This comment has been minimized.

Copy link
@simonharrer

simonharrer Apr 5, 2016

Author Contributor

Nope, not possible. But I see no other solution except not to make this improvement.

This comment has been minimized.

Copy link
@tobiasdiez

tobiasdiez Apr 5, 2016

Member

Remove the distinction between model and logic? But I'm probably the only one which does not likes the model package...

This comment has been minimized.

Copy link
@simonharrer

simonharrer Apr 5, 2016

Author Contributor

Even if we would combine model and logic, we would have very bad dependency relations. By separating model and logic, they are simply revealed there.

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

3 comments on commit e0380b7

@Siedlerchr
Copy link
Member

Choose a reason for hiding this comment

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

I really don't like the YearUtil class at all and I think it is obsolete, or at least its self created logic is obsolete.
As with the new Java 8 Release, there haven been important changes made to the Date-Logic.
Especially the new DateFormatters. Why don't use them instead of manually trying to do Date Arithmetic`?
http://www.tutorialspoint.com/java8/java8_datetime_api.htm
And here:
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ofPattern-java.lang.String-

@simonharrer
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this Year arithmetic cannot be easily handled with Java 8 classes, but you are welcome to try it.

@Siedlerchr
Copy link
Member

Choose a reason for hiding this comment

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

I will look into that.

Please sign in to comment.