Formatting and code cleanup

pull/14/head
Sam Bosley 13 years ago
parent 7249977f02
commit 1c8cf45b61

@ -138,8 +138,6 @@ public class TitleParser {
private static String removeIfParenthetical(Matcher m, String inputText) {
String s = m.group();
System.err.println("CHECKING: " + s);
System.err.println("Start char: " + s.charAt(0) + ", end char: " + s.charAt(s.length() - 1));
if (s.startsWith("(") && s.endsWith(")")) {
return inputText.substring(0, m.start()) + inputText.substring(m.end());
}
@ -173,7 +171,8 @@ public class TitleParser {
"(?i)(\\(|\\b)thu(rsday(\\)|\\b)|(\\)|\\.))",
"(?i)(\\(|\\b)fri(day(\\)|\\b)|(\\)|\\.))",
"(?i)(\\(|\\b)sat(urday(\\)|\\b)|(\\)|\\.))",
"(?i)(\\(|\\b)sun(day(\\)|\\b)|(\\)|\\.))" };
"(?i)(\\(|\\b)sun(day(\\)|\\b)|(\\)|\\.))"
};
for (String date : daysOfWeek){
Pattern pattern = Pattern.compile(date);
@ -199,7 +198,8 @@ public class TitleParser {
"(?i)\\b(sep(\\.|tember))(\\s(3[0-1]|[0-2]?[0-9])),?( (\\d{4}|\\d{2}))?",
"(?i)\\b(oct(\\.|ober))(\\s(3[0-1]|[0-2]?[0-9])),?( (\\d{4}|\\d{2}))?",
"(?i)\\b(nov(\\.|ember))(\\s(3[0-1]|[0-2]?[0-9])),?( (\\d{4}|\\d{2}))?",
"(?i)\\b(dec(\\.|ember))(\\s(3[0-1]|[0-2]?[0-9])),?( (\\d{4}|\\d{2}))?"};
"(?i)\\b(dec(\\.|ember))(\\s(3[0-1]|[0-2]?[0-9])),?( (\\d{4}|\\d{2}))?"
};
// m.group(1) = "month"
//m.group(4) = "day"
@ -215,14 +215,12 @@ public class TitleParser {
Calendar today = Calendar.getInstance();
if (m.group(5) != null) {
dateCal.set(Calendar.YEAR, Integer.parseInt(m.group(5).trim()));
}
else if (today.get(Calendar.MONTH) - dateCal.get(Calendar.MONTH) > 1){ //if more than a month in the past
} else if (today.get(Calendar.MONTH) - dateCal.get(Calendar.MONTH) > 1) { //if more than a month in the past
dateCal.set(Calendar.YEAR, dateCal.get(Calendar.YEAR)+1);
}
if (cal == null) {
cal = dateCal;
}
else{
} else{
cal.set(Calendar.DAY_OF_MONTH, dateCal.get(Calendar.DAY_OF_MONTH));
cal.set(Calendar.MONTH,dateCal.get(Calendar.MONTH) );
cal.set(Calendar.YEAR, dateCal.get(Calendar.YEAR));
@ -268,7 +266,8 @@ public class TitleParser {
dayTimes.put("(?i)\\bmidnight\\b", 0);
dayTimes.put("(?i)\\bnoon\\b", 12);
for (String dayTime: dayTimes.keySet()){
Set<String> keys = dayTimes.keySet();
for (String dayTime : keys) {
Pattern pattern = Pattern.compile(dayTime);
Matcher m = pattern.matcher(inputText);
if (m.find()) {
@ -279,8 +278,7 @@ public class TitleParser {
dayTimesCal.set(Calendar.HOUR, timeHour);
if (cal == null) {
cal = dayTimesCal;
}
else {
} else {
setCalendarToDefaultTime(cal);
cal.set(Calendar.HOUR, timeHour);
}
@ -324,8 +322,7 @@ public class TitleParser {
while (timeCal.getTime().getTime() < today.getTime().getTime()){
timeCal.set(Calendar.HOUR_OF_DAY, timeCal.get(Calendar.HOUR_OF_DAY)+12);
}
}
else { //if am/pm is provided and the time is in the past, set it to the next day. Military time included.
} else { //if am/pm is provided and the time is in the past, set it to the next day. Military time included.
if (timeCal.get(Calendar.HOUR) !=0 && (timeCal.getTime().getTime() < today.getTime().getTime())) {
timeCal.set(Calendar.DAY_OF_MONTH, timeCal.get(Calendar.DAY_OF_MONTH) + 1);
}
@ -336,8 +333,7 @@ public class TitleParser {
if (cal == null){
cal = timeCal;
}
else{
} else {
cal.set(Calendar.HOUR, timeCal.get(Calendar.HOUR));
cal.set(Calendar.MINUTE,timeCal.get(Calendar.MINUTE) );
cal.set(Calendar.SECOND, timeCal.get(Calendar.SECOND));

Loading…
Cancel
Save