Java style names in TitleParser.java

pull/14/head
Sam Bosley 12 years ago
parent 69997500ea
commit 62db6794ef

@ -80,15 +80,15 @@ public class TitleParser {
} }
//helper method for priorityHelper. converts the string to a Task Importance //helper method for priorityHelper. converts the string to a Task Importance
private static int str_to_priority(String priority_str) { private static int strToPriority(String priorityStr) {
if (priority_str!=null) if (priorityStr!=null)
priority_str.toLowerCase().trim(); priorityStr.toLowerCase().trim();
int priority = Task.IMPORTANCE_DO_OR_DIE; int priority = Task.IMPORTANCE_DO_OR_DIE;
if ("0".equals(priority_str) || "!0".equals(priority_str) || "least".equals(priority_str) || "lowest".equals(priority_str)) if ("0".equals(priorityStr) || "!0".equals(priorityStr) || "least".equals(priorityStr) || "lowest".equals(priorityStr))
priority = Task.IMPORTANCE_NONE; priority = Task.IMPORTANCE_NONE;
if ("!".equals(priority_str) || "!1".equals(priority_str) || "bang".equals(priority_str) || "1".equals(priority_str) || "low".equals(priority_str)) if ("!".equals(priorityStr) || "!1".equals(priorityStr) || "bang".equals(priorityStr) || "1".equals(priorityStr) || "low".equals(priorityStr))
priority = Task.IMPORTANCE_SHOULD_DO; priority = Task.IMPORTANCE_SHOULD_DO;
if ("!!".equals(priority_str) || "!2".equals(priority_str) || "bang bang".equals(priority_str) || "2".equals(priority_str) || "high".equals(priority_str)) if ("!!".equals(priorityStr) || "!2".equals(priorityStr) || "bang bang".equals(priorityStr) || "2".equals(priorityStr) || "high".equals(priorityStr))
priority = Task.IMPORTANCE_MUST_DO; priority = Task.IMPORTANCE_MUST_DO;
return priority; return priority;
} }
@ -110,7 +110,7 @@ public class TitleParser {
Matcher m = importancePattern.matcher(inputText); Matcher m = importancePattern.matcher(inputText);
if(m.find()) { if(m.find()) {
result = true; result = true;
task.setValue(Task.IMPORTANCE, str_to_priority(m.group(2).trim())); task.setValue(Task.IMPORTANCE, strToPriority(m.group(2).trim()));
int start = m.start() == 0 ? 0 : m.start() + 1; int start = m.start() == 0 ? 0 : m.start() + 1;
inputText = inputText.substring(0, start) + inputText.substring(m.end()); inputText = inputText.substring(0, start) + inputText.substring(m.end());
@ -123,12 +123,12 @@ public class TitleParser {
} }
//helper for dayHelper. Converts am/pm to an int 0/1. //helper for dayHelper. Converts am/pm to an int 0/1.
private static int ampm_to_number(String am_pm_string) { private static int ampmToNumber(String amPmString) {
int time = Calendar.PM; int time = Calendar.PM;
if (am_pm_string == null){ if (amPmString == null){
return time; return time;
} }
String text = am_pm_string.toLowerCase().trim(); String text = amPmString.toLowerCase().trim();
if (text.equals ("am") || text.equals ("a.m") || text.equals("a")) if (text.equals ("am") || text.equals ("a.m") || text.equals("a"))
time = Calendar.AM; time = Calendar.AM;
if (text.equals ("pm") || text.equals ("p.m") || text.equals("p")) if (text.equals ("pm") || text.equals ("p.m") || text.equals("p"))
@ -146,7 +146,7 @@ public class TitleParser {
String inputText = task.getValue(Task.TITLE); String inputText = task.getValue(Task.TITLE);
Calendar cal = null; Calendar cal = null;
Boolean containsSpecificTime = false; Boolean containsSpecificTime = false;
String[] days_of_week = { String[] daysOfWeek = {
"(?i)\\b(today)\\b", "(?i)\\b(today)\\b",
"(?i)\\b(tomorrow)\\b", "(?i)\\b(tomorrow)\\b",
"(?i)\\b(mon(day\\b|\\.))", "(?i)\\b(mon(day\\b|\\.))",
@ -157,7 +157,7 @@ public class TitleParser {
"(?i)\\b(sat(urday\\b|\\.))", "(?i)\\b(sat(urday\\b|\\.))",
"(?i)\\b(sun(day\\b|\\.))" }; "(?i)\\b(sun(day\\b|\\.))" };
for (String date : days_of_week){ for (String date : daysOfWeek){
Pattern pattern = Pattern.compile(date); Pattern pattern = Pattern.compile(date);
Matcher m = pattern.matcher(inputText); Matcher m = pattern.matcher(inputText);
if (m.find()) { if (m.find()) {
@ -298,7 +298,7 @@ public class TitleParser {
else else
timeCal.set(Calendar.MINUTE, 0); timeCal.set(Calendar.MINUTE, 0);
if (Integer.parseInt(m.group(2)) <= 12) if (Integer.parseInt(m.group(2)) <= 12)
timeCal.set(Calendar.AM_PM, ampm_to_number(m.group(4))); timeCal.set(Calendar.AM_PM, ampmToNumber(m.group(4)));
//sets it to the next occurrence of that hour if no am/pm is provided. doesn't include military time //sets it to the next occurrence of that hour if no am/pm is provided. doesn't include military time
if ( Integer.parseInt(m.group(2))<= 12 && (m.group(4)==null || (m.group(4).trim()).equals(""))) { if ( Integer.parseInt(m.group(2))<= 12 && (m.group(4)==null || (m.group(4).trim()).equals(""))) {
@ -328,7 +328,7 @@ public class TitleParser {
} }
} }
if( cal!= null ){ //if at least one of the above has been called, write to task. else do nothing. if(cal!= null) { //if at least one of the above has been called, write to task. else do nothing.
if (containsSpecificTime) { if (containsSpecificTime) {
task.setValue(Task.DUE_DATE, Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, cal.getTime().getTime())); task.setValue(Task.DUE_DATE, Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, cal.getTime().getTime()));
} else { } else {
@ -396,27 +396,27 @@ public class TitleParser {
//helper method for repeatHelper. //helper method for repeatHelper.
private static int findInterval(String inputText) { private static int findInterval(String inputText) {
HashMap<String,Integer> words_to_num = new HashMap<String, Integer>(); HashMap<String,Integer> wordsToNum = new HashMap<String, Integer>();
String[] words = new String[] { String[] words = new String[] {
"one", "two", "three", "four", "five", "six", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven", "twelve" "seven", "eight", "nine", "ten", "eleven", "twelve"
}; };
for(int i = 0; i < words.length; i++) { for(int i = 0; i < words.length; i++) {
words_to_num.put(words[i], i+1); wordsToNum.put(words[i], i+1);
words_to_num.put(Integer.toString(i + 1), i + 1); wordsToNum.put(Integer.toString(i + 1), i + 1);
} }
words_to_num.put("other" , 2); wordsToNum.put("other" , 2);
Pattern pattern = Pattern.compile("(?i)\\bevery (\\w*)\\b"); Pattern pattern = Pattern.compile("(?i)\\bevery (\\w*)\\b");
int interval = 1; int interval = 1;
Matcher m = pattern.matcher(inputText); Matcher m = pattern.matcher(inputText);
if (m.find() && m.group(1)!=null){ if (m.find() && m.group(1)!=null){
String interval_str = m.group(1); String intervalStr = m.group(1);
if (words_to_num.containsKey(interval_str)) if (wordsToNum.containsKey(intervalStr))
interval = words_to_num.get(interval_str); interval = wordsToNum.get(intervalStr);
else { else {
try { try {
interval = Integer.parseInt(interval_str); interval = Integer.parseInt(intervalStr);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// Ah well // Ah well
} }

Loading…
Cancel
Save