From bc539440c671d68b676cc9dbe5374185e7a52a26 Mon Sep 17 00:00:00 2001 From: Jonathan Sanchez Date: Thu, 18 Oct 2012 11:32:01 -0500 Subject: [PATCH] Issue #1126 Fixed refactor bugs. Former-commit-id: a35330587c2f519b807dfb674fb3dfd6cfd077c9 [formerly a326889adcf798c217da2cda313adc4cc97eb528] [formerly 4cf0b68aa264d73f7f0573d6d6cf97ae602bdafa] [formerly d1bf86e2fe429cc1ebed937a242ba4f5e2c96032 [formerly 4cf0b68aa264d73f7f0573d6d6cf97ae602bdafa [formerly eb95e6227b229cc8d627b4ac24254c2f2c2e3023]]] Former-commit-id: d1bf86e2fe429cc1ebed937a242ba4f5e2c96032 Former-commit-id: 33d730411f9d212a0a9bb0a922c358e16605d846 [formerly 86e07328db57a6b3626f798c0f98d1c34b915931] Former-commit-id: c2f01b17a19622cd1d77cea6c45314d4434bb8de --- .../warngen/text/AbstractLockingBehavior.java | 7 +++++-- .../viz/warngen/text/ICommonPatterns.java | 8 +++---- .../raytheon/viz/warngen/text/WrapUtil.java | 5 +++++ .../viz/warngen/util/FollowUpUtil.java | 21 +++++++------------ 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/AbstractLockingBehavior.java b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/AbstractLockingBehavior.java index 09ee425781..174fb80d0a 100644 --- a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/AbstractLockingBehavior.java +++ b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/AbstractLockingBehavior.java @@ -42,7 +42,8 @@ import com.raytheon.viz.warngen.gis.AffectedAreas; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Sep 24, 2012 15322 jsanchez Initial creation + * Sep 24, 2012 15332 jsanchez Initial creation + * Oct 18, 2012 15332 jsanchez Updated the find method. * * * @@ -177,6 +178,8 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns { * Locks the list of area names. */ private void areaNames() { + Pattern listOfAreaNamePtrn = Pattern.compile(listOfAreaName + newline, + Pattern.MULTILINE); find(listOfAreaNamePtrn.matcher(text)); } @@ -186,7 +189,7 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns { * @param m */ protected void find(Matcher m) { - if (m.find()) { + while (m.find()) { String group = m.group(); // If line already starts with a LOCK_END, the LOCK_END is removed // and the line just adds to the LOCK_END at the end. diff --git a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/ICommonPatterns.java b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/ICommonPatterns.java index 19e0c73761..233810cd35 100644 --- a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/ICommonPatterns.java +++ b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/ICommonPatterns.java @@ -30,7 +30,8 @@ import java.util.regex.Pattern; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Sep 24, 2012 15322 jsanchez Initial creation + * Sep 24, 2012 15332 jsanchez Initial creation + * Oct 18, 2012 15332 jsanchez Replaced listOfAreaNamesPtrn with String pattern. * * * @@ -53,9 +54,8 @@ public interface ICommonPatterns { // LOCK_END can be added at the start of the line if a previous line has // been locked. - public static Pattern listOfAreaNamePtrn = Pattern.compile("^((" + LOCK_END - + "){0,1}(((\\w+\\s{1})+\\w{2}-)*((\\w+\\s{1})+\\w{2}-))" + newline - + ")", Pattern.MULTILINE); + public static final String listOfAreaName = "^((" + LOCK_END + + "){0,1}(((\\w+\\s{1})+\\w{2}-)*((\\w+\\s{1})+\\w{2}-)))"; // LOCK_END should not be found at the beginning of a first bullet since the // previous line should be blank. diff --git a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/WrapUtil.java b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/WrapUtil.java index aa6e2378c5..e07566bf3a 100644 --- a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/WrapUtil.java +++ b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/text/WrapUtil.java @@ -32,6 +32,7 @@ import java.util.regex.Pattern; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Sep 24, 2012 15322 jsanchez Initial creation + * Oct 19, 2012 15332 jsanchez Created a local pattern listOfAreaNamesPtrn. * * * @@ -69,6 +70,10 @@ public class WrapUtil implements ICommonPatterns { // ugc pattern private static final Pattern ugcPtrn = Pattern.compile(ugc); + // list of areas pattern + private static final Pattern listOfAreaNamePtrn = Pattern + .compile(listOfAreaName); + /** * Wraps the text independent of being locked before or after. * diff --git a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/util/FollowUpUtil.java b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/util/FollowUpUtil.java index 1912098865..600c60c2de 100644 --- a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/util/FollowUpUtil.java +++ b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/util/FollowUpUtil.java @@ -27,6 +27,7 @@ import com.raytheon.viz.warngen.text.ICommonPatterns; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jul 22, 2008 #1284 bwoodle Initial creation + * Oct 18, 2012 15332 jsanchez Fixed refactor bugs. * * * @@ -165,26 +166,18 @@ public class FollowUpUtil { */ public static ArrayList canceledAreasFromText( String originalText) { - boolean ugcdone = false; boolean namedone = false; boolean insideHeadline = false; - String ugcLine = ""; + String ugcLine = getUgcLineCanFromText(originalText); String namesLine = ""; String headline = ""; - Pattern ugcPtrn = Pattern.compile(ICommonPatterns.ugc); + Pattern listOfAreaNamePtrn = Pattern + .compile(ICommonPatterns.listOfAreaName); for (String line : originalText.trim().split("\n")) { if (line.contains("TEST") || line.trim().length() == 0) { continue; } - Matcher m = ugcPtrn.matcher(line); - if (!ugcdone && m.find()) { - ugcLine += m.group(); - continue; - } else if (ugcLine.length() > 0) { - ugcdone = true; - } - - m = ICommonPatterns.listOfAreaNamePtrn.matcher(line); + Matcher m = listOfAreaNamePtrn.matcher(line); if (!namedone && m.find()) { namesLine += m.group(); continue; @@ -221,7 +214,6 @@ public class FollowUpUtil { AffectedAreas affectedArea = new AffectedAreas(); String ugc = ugcs[i].trim(); if (ugc.length() == 6) { - stateAbbreviation = ugc.substring(0, 2); if (ugc.charAt(2) == 'Z') { areaNotation = "ZONE"; areasNotation = "ZONES"; @@ -235,6 +227,7 @@ public class FollowUpUtil { if (i < names.length) { name = names[i].substring(0, names[i].length() - 3); + stateAbbreviation = names[i].substring(names[i].length() - 2); } if (name != null) { @@ -268,7 +261,7 @@ public class FollowUpUtil { public static String getUgcLineCanFromText(String originalText) { String ugcLine = ""; Pattern ugcPtrn = Pattern.compile(ICommonPatterns.ugc); - for (String line : originalText.trim().split("\n")) { + for (String line : originalText.replaceAll("\r", "").trim().split("\n")) { Matcher m = ugcPtrn.matcher(line); if (m.find()) { ugcLine += line;