From e0380b795f649afaf6cd708abc5bf2680c8a01c0 Mon Sep 17 00:00:00 2001 From: Simon Harrer Date: Tue, 5 Apr 2016 20:13:32 +0200 Subject: [PATCH] Ensure dependencies using code duplication --- .../net/sf/jabref/model/entry/YearUtil.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/sf/jabref/model/entry/YearUtil.java b/src/main/java/net/sf/jabref/model/entry/YearUtil.java index bbabb534a12..23e1f3da1de 100644 --- a/src/main/java/net/sf/jabref/model/entry/YearUtil.java +++ b/src/main/java/net/sf/jabref/model/entry/YearUtil.java @@ -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): @@ -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; } @@ -61,14 +58,35 @@ 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 { @@ -76,7 +94,6 @@ private static class Year { private final int century; private final int yearShort; - public Year(int year) { this.year = year; this.yearShort = this.year % 100;