Omaha #4441 and #4442 Fix WarnGen QC and locking issues with mixed case.

Change-Id: I95705831aa37e0774b09a0d2acee42c86d361368

Former-commit-id: ac3c7983f3c287cad4e0f38b0231b64ad69a60a6
This commit is contained in:
Ron Anderson 2015-06-02 11:55:06 -05:00
parent cb8e59c56f
commit 15dfb5afef
13 changed files with 363 additions and 287 deletions

View file

@ -20,9 +20,7 @@
package com.raytheon.viz.texteditor.dialogs;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@ -38,6 +36,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.viz.core.mode.CAVEMode;
import com.raytheon.viz.texteditor.Activator;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
/**
@ -57,6 +56,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* added to CaveSWTDialog.
* 17 Sep 2013 #2384 lvenable Fixed memory leak and utilized the disposed()
* method.
* May 29, 2015 #4441 randerso Fixed loading of images
*
* </pre>
*
@ -120,36 +120,29 @@ public class WarnGenConfirmationDlg extends CaveSWTDialog {
private void createImage(Composite mainComposite) {
InputStream is = null;
String imagePath = null;
try {
ClassLoader cl = WarnGenConfirmationDlg.class.getClassLoader();
if (mode.equals(CAVEMode.OPERATIONAL)) {
// add Live image
is = cl.getResourceAsStream(IMAGE_OPERATIONAL);
imagePath = IMAGE_OPERATIONAL;
} else if (mode.equals(CAVEMode.TEST)) {
// add Test image
is = cl.getResourceAsStream(IMAGE_TEST);
imagePath = IMAGE_TEST;
} else if (mode.equals(CAVEMode.PRACTICE)) {
// add Practice image
is = cl.getResourceAsStream(IMAGE_PRACTICE);
imagePath = IMAGE_PRACTICE;
} else {
// unknown
is = cl.getResourceAsStream(IMAGE_OPERATIONAL);
imagePath = IMAGE_OPERATIONAL;
}
stopSign = new Image(mainComposite.getDisplay(), is);
ImageDescriptor id = Activator.imageDescriptorFromPlugin(
Activator.PLUGIN_ID, imagePath);
stopSign = id.createImage(mainComposite.getDisplay());
Label stopSignLbl = new Label(mainComposite, 0);
stopSignLbl.setImage(stopSign);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
} finally {
try {
is.close();
} catch (IOException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
}
}

View file

@ -36,7 +36,8 @@ import java.util.regex.Pattern;
* May 1, 2013 15893 mgamazaychikov Changed listOfAreaNamePtrn.
* Feb 26, 2014 16386 Qinglu Lin Updated listOfAreaNamePtrn to handle issue caused by
* hyphens in county name, and that by "'" and "/" as well.
*
* May 29, 2015 4441 randerso Made bullet patterns case insensitive
*
* </pre>
*
* @version 1.0
@ -61,14 +62,17 @@ public interface IQCCheck {
public static final Pattern listOfAreaNamePtrn = Pattern
.compile("^([\\w\\s\\.'/]*-)");
public static final Pattern firstBulletPtrn = Pattern
.compile("\\*\\s(.*)\\s(WARNING|ADVISORY)(\\sFOR(.*)|...)");
public static final Pattern firstBulletPtrn = Pattern.compile(
"\\*\\s(.*)\\s(WARNING|ADVISORY)(\\sFOR(.*)|...)",
Pattern.CASE_INSENSITIVE);
public static final Pattern secondBulletPtrn = Pattern
.compile("\\*\\sUNTIL\\s(\\d{1,2})(\\d{2})\\s(AM|PM)\\s(\\w{3,4})");
public static final Pattern secondBulletPtrn = Pattern.compile(
"\\*\\sUNTIL\\s(\\d{1,2})(\\d{2})\\s(AM|PM)\\s(\\w{3,4})",
Pattern.CASE_INSENSITIVE);
public static final Pattern thirdBulletPtrn = Pattern
.compile("\\*\\sAT\\s(\\d{1,2})(\\d{2})\\s(AM|PM)\\s(\\w{3,4})(.*)");
public static final Pattern thirdBulletPtrn = Pattern.compile(
"\\*\\sAT\\s(\\d{1,2})(\\d{2})\\s(AM|PM)\\s(\\w{3,4})(.*)",
Pattern.CASE_INSENSITIVE);
public static final Pattern latLonPtrn = Pattern
.compile("LAT...LON+(\\s\\d{3,4}\\s\\d{3,5}){1,}");

View file

@ -25,6 +25,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -41,7 +42,7 @@ import com.raytheon.viz.texteditor.util.VtecObject;
import com.raytheon.viz.texteditor.util.VtecUtil;
/**
* TODO Add Description
* QC text segment
*
* <pre>
*
@ -52,15 +53,16 @@ import com.raytheon.viz.texteditor.util.VtecUtil;
* Initial creation
* 25 AUG 2011 10719 rferrel Changed ugcPtrn to handle multi-line UGCs
* 01 SEP 2011 10764 rferrel Allow multiple bullet types for given Vtec.
* 20 JUL 2012 15003 mgamazaychikov Allow standalone MWS have no headline
* Add vtec to checkHeadline signature
* 20 JUL 2012 15006 mgamazaychikov Do not perform search for a list of
* county/zones names in the MWS segment heading.
* 20 JUL 2012 15003 mgamazaychikov Allow standalone MWS have no headline
* Add vtec to checkHeadline signature
* 20 JUL 2012 15006 mgamazaychikov Do not perform search for a list of
* county/zones names in the MWS segment heading.
* 07 NOV 2012 15003 mgamazaychikov Do not perform QC check on standalone MWS headline.
* 21 MAY 2013 16200 Qinglu Lin Prevent countyOrZoneCounter from being increased for a line
* that has no word County/Parish/Municipality in it.
* 13 MAY 2014 17177 Qinglu Lin Updated runQC().
* 15 SEP 2014 529 mgamazaychikov Create firstBulletImmediateCauseQCExclusions list and add IC to it.
* 15 SEP 2014 529 mgamazaychikov Create firstBulletImmediateCauseQCExclusions list and add IC to it.
* 29 MAY 2015 4441 randerso Fixed QC to work with mixed case
*
* </pre>
*
@ -88,11 +90,16 @@ public class TextSegmentCheck implements IQCCheck {
}
}
// List of immediate causes to be excluded from quality control check in the first bullet
private static List<String> firstBulletImmediateCauseQCExclusions = Arrays.asList("ER", "MC", "UU", "IC");
// List of immediate causes to be excluded from quality control check in the
// first bullet
private static List<String> firstBulletImmediateCauseQCExclusions = Arrays
.asList("ER", "MC", "UU", "IC");
@Override
public String runQC(String header, String body, String nnn) {
header = header.toUpperCase();
body = body.toUpperCase();
int countyOrZoneCounter = 0;
int ugcLength = 0;
int czmType = 1;
@ -131,22 +138,17 @@ public class TextSegmentCheck implements IQCCheck {
}
Set<String> countyParishMunicipality = new HashSet<String>();
for (String countyType : QualityControl
.getCountyTypeMap().values()) {
for (Entry<String, String> entry : QualityControl.getCountyTypeMap()
.entrySet()) {
String key = entry.getKey();
String countyType = entry.getValue();
if (countyType.length() > 1) {
countyParishMunicipality.add(countyType.trim());
} else {
countyParishMunicipality.add(countyType.trim().toUpperCase());
} else if (key.length() > 1) {
countyParishMunicipality.add(key.toUpperCase());
}
}
}
}
for (String key : QualityControl.getCountyTypeMap().keySet()) {
if (QualityControl.getCountyTypeMap()
.get(key).length() <= 1) {
if (key.length() > 1) {
countyParishMunicipality.add(key);
}
}
}
countyParishMunicipality.remove("AK");
countyParishMunicipality.remove("DC");
countyParishMunicipality.add("CITY");
@ -163,7 +165,7 @@ public class TextSegmentCheck implements IQCCheck {
if (line.equals("$$")) {
if (ugc.length() == 0 && vtec == null) {
if ((ugc.length() == 0) && (vtec == null)) {
errorMsg.append("Badly placed segment end.\n");
return errorMsg.toString();
}
@ -173,14 +175,14 @@ public class TextSegmentCheck implements IQCCheck {
ugc = "";
/*
* DR15003 - Add vtec to signature ias n order
* to distinguish between standalone
* and followup MWS a check of VTEC is needed.
* DR15003 - Add vtec to signature ias n order to distinguish
* between standalone and followup MWS a check of VTEC is
* needed.
*/
errorMsg.append(checkHeadline(headline, nnn, vtec));
headline = "";
if (segmentCount > 1
if ((segmentCount > 1)
&& !QualityControl.segmentedNNN.contains(nnn)) {
errorMsg.append("Segments exist in unsegmented product.\n");
}
@ -200,11 +202,11 @@ public class TextSegmentCheck implements IQCCheck {
if (ugc.matches("\\w{2}[CZ]\\d{3}[->].*") == false) {
errorMsg.append("First UGC does not specify a zone or county.\n");
}
if (ugc.length() > 2 && ugc.charAt(2) == 'C') {
if ((ugc.length() > 2) && (ugc.charAt(2) == 'C')) {
++countyZoneCnt;
countyBased = true;
}
if (ugc.length() > 2 && ugc.charAt(2) == 'Z') {
if ((ugc.length() > 2) && (ugc.charAt(2) == 'Z')) {
++countyZoneCnt;
}
@ -264,15 +266,14 @@ public class TextSegmentCheck implements IQCCheck {
if (expectNamesList) {
m = listOfAreaNamePtrn.matcher(line);
/*
* DR15006 - MWS does not have the list of
* marine zones names in the segment heading,
* so skip the check for MWS
* DR15006 - MWS does not have the list of marine zones names in
* the segment heading, so skip the check for MWS
*/
if ( !nnn.equalsIgnoreCase("MWS")) {
if (!m.find()) {
if (!nnn.equalsIgnoreCase("MWS")) {
if (!m.find()) {
errorMsg.append("List of county/zone names missing.\n");
}
}
}
expectNamesList = false;
continue;
}
@ -297,7 +298,7 @@ public class TextSegmentCheck implements IQCCheck {
}
// third bullet
if (line.startsWith("*") && nb == 3) {
if (line.startsWith("*") && (nb == 3)) {
m = thirdBulletPtrn.matcher(line);
if (!line.substring(0, 5).equals("* AT ")) {
errorMsg.append("Event bullet does not start with '* AT '\n.");
@ -309,9 +310,10 @@ public class TextSegmentCheck implements IQCCheck {
}
// second bullet
if (line.startsWith("*") && nb == 2) {
if (line.startsWith("*") && (nb == 2)) {
m = secondBulletPtrn.matcher(line);
if (m.find() || line.contains("* UNTIL NOON") || line.contains("* UNTIL MIDNIGHT")) {
if (m.find() || line.contains("* UNTIL NOON")
|| line.contains("* UNTIL MIDNIGHT")) {
secondBulletFound = true;
insideFirstBullet = false;
continue;
@ -360,14 +362,14 @@ public class TextSegmentCheck implements IQCCheck {
&& !secondBulletFound
&& (line.contains("AREA...")
|| line.contains("AREAS...") || line
.contains("AREA WAS..."))) {
.contains("AREA WAS..."))) {
insideFirstBullet = true;
continue;
}
}
if (insideFirstBullet) {
if (ic != null
if ((ic != null)
&& !firstBulletImmediateCauseQCExclusions.contains(ic)
&& checkIC) {
boolean validIC = false;
@ -391,7 +393,7 @@ public class TextSegmentCheck implements IQCCheck {
}
if (czmType == 3) {
if (line != null && line.trim().startsWith("INCLUDING ")) {
if ((line != null) && line.trim().startsWith("INCLUDING ")) {
insideFirstBullet = false; // stop adding counties/zones
continue;
}
@ -402,7 +404,7 @@ public class TextSegmentCheck implements IQCCheck {
}
boolean invalidCountyOrZone = true;
if (ugc.length() > 2 && ugc.charAt(2) == 'Z') {
if ((ugc.length() > 2) && (ugc.charAt(2) == 'Z')) {
// zones do not use countyTypes
if (line.contains(" IN ")) {
invalidCountyOrZone = false;
@ -412,16 +414,18 @@ public class TextSegmentCheck implements IQCCheck {
.keySet()) {
if (line.contains(state)
&& line.contains(QualityControl
.getCountyTypeMap().get(state))) {
.getCountyTypeMap().get(state)
.toUpperCase())) {
invalidCountyOrZone = false;
}
}
if (invalidCountyOrZone) {
for (String countyType : QualityControl
.getCountyTypeMap().values()) {
if (countyType.trim().length() > 0
if ((countyType.trim().length() > 0)
&& line.contains(" "
+ countyType.trim())) {
+ countyType.trim()
.toUpperCase())) {
invalidCountyOrZone = false;
break;
}
@ -436,7 +440,7 @@ public class TextSegmentCheck implements IQCCheck {
int cpmCounter = 0;
Iterator<String> iter = countyParishMunicipality.iterator();
while(iter.hasNext()) {
while (iter.hasNext()) {
if (line.contains(iter.next())) {
break;
} else {
@ -482,8 +486,9 @@ public class TextSegmentCheck implements IQCCheck {
if (ugcLength == 0) {
errorMsg.append("No UGC text was found\n");
} else if (nb > 0 && (czmType == 1 || (czmType == 2 && countyBased))
&& ugcLength != countyOrZoneCounter) {
} else if ((nb > 0)
&& ((czmType == 1) || ((czmType == 2) && countyBased))
&& (ugcLength != countyOrZoneCounter)) {
// DR 11060 - Don't count zone areas for hydro products
errorMsg.append(ugcLength).append(" UGCs while ")
.append(countyOrZoneCounter)
@ -516,13 +521,13 @@ public class TextSegmentCheck implements IQCCheck {
pairs++;
double lat = Double.parseDouble(m.group(1));
double lon = Double.parseDouble(m.group(2));
if (lat > 9000 || lon > 18000) {
if ((lat > 9000) || (lon > 18000)) {
errorMsg += "Data error in the LAT...LON line.\n";
return errorMsg;
}
}
if (pairs <= 2 || pairs > 20) {
if ((pairs <= 2) || (pairs > 20)) {
errorMsg += "LAT...LON line missing or malformed.\n";
}
@ -546,13 +551,12 @@ public class TextSegmentCheck implements IQCCheck {
return errorMsg;
}
/*
* DR15003: no headline QC on standalone MWS.
* To distinguish between standalone and follow up MWS
* the VTEC check is performed as standalone MWS
* do not contain VTEC
* DR15003: no headline QC on standalone MWS. To distinguish between
* standalone and follow up MWS the VTEC check is performed as
* standalone MWS do not contain VTEC
*/
if (nnn.equals("MWS") && vtec == null) {
return "";
if (nnn.equals("MWS") && (vtec == null)) {
return "";
}
if (headline.length() == 0) {

View file

@ -57,13 +57,39 @@ import com.raytheon.viz.warngen.gis.AffectedAreas;
* Apr 29, 2014 3033 jsanchez Moved patterns into ICommonPatterns
* May 1, 2014 DR 16627 Qinglu Lin Added hasStateAbbrev(), isOtherType(), lockListOfNames(), and updated lock().
* May 13, 2014 DR 17177 Qinglu Lin Updated secondBullet().
* May 29, 2015 4442 randerso Fixed WarnGen text locking to work with mixed case
*
* </pre>
*
* @author jsanchez
* @version 1.0
*/
abstract public class AbstractLockingBehavior implements ICommonPatterns {
abstract public class AbstractLockingBehavior {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(AbstractLockingBehavior.class);
protected static String warningType = "(FLOOD ADVISORY)|(FLOOD WARNING)|(FLOOD STATEMENT)"
+ "|(SEVERE WEATHER STATEMENT)|(EXTREME WIND WARNING)|(FIRE WARNING)"
+ "|(FLASH FLOOD WARNING)|(FLASH FLOOD STATEMENT)|(SEVERE THUNDERSTORM WARNING)"
+ "|(TORNADO WARNING)|(MARINE WEATHER STATEMENT)|(SHORT TERM FORECAST)"
+ "|(SPECIAL WEATHER STATEMENT)|(SPECIAL MARINE WARNING)";
private static Pattern ugcPtrn = Pattern.compile(WarnGenPatterns.ugc
+ WarnGenPatterns.NEWLINE, Pattern.MULTILINE);
private static Pattern listOfAreaNamePtrn = Pattern.compile(
WarnGenPatterns.listOfAreaName + WarnGenPatterns.NEWLINE,
Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
private static Pattern startMND = Pattern
.compile("(BULLETIN - IMMEDIATE BROADCAST REQUESTED)|(BULLETIN - EAS ACTIVATION REQUESTED)|"
+ warningType);
private static Pattern stateAbbrevPtrn = Pattern.compile(
WarnGenPatterns.listOfAreaName + WarnGenPatterns.NEWLINE,
Pattern.MULTILINE);
private static Pattern immediateCausePtrn = null;
/**
* Sorts in reverse order the areas based on the length of the name.
@ -86,19 +112,6 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
protected String text;
protected static final String REPLACEMENT = LOCK_START + "$0" + LOCK_END;
protected String warningType = "(FLOOD ADVISORY)|(FLOOD WARNING)|(FLOOD STATEMENT)"
+ "|(SEVERE WEATHER STATEMENT)|(EXTREME WIND WARNING)|(FIRE WARNING)"
+ "|(FLASH FLOOD WARNING)|(FLASH FLOOD STATEMENT)|(SEVERE THUNDERSTORM WARNING)"
+ "|(TORNADO WARNING)|(MARINE WEATHER STATEMENT)|(SHORT TERM FORECAST)"
+ "|(SPECIAL WEATHER STATEMENT)|(SPECIAL MARINE WARNING)";
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(AbstractLockingBehavior.class);
private static Pattern immediateCausePtrn = null;
protected WarningAction action = null;
/**
@ -166,10 +179,11 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
* Locks the header before the first bullet.
*/
private void header() {
// LOCK_END should not be found at the beginning since the previous line
// ICommonPatterns.LOCK_END should not be found at the beginning since
// the previous line
// should be blank.
find(header.matcher(text));
find(WarnGenPatterns.header.matcher(text));
}
/**
@ -205,8 +219,9 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
// immediate cause
m = immediateCausePtrn.matcher(line);
if (m.find()) {
String i = line.replace(line, LOCK_START + line
+ LOCK_END);
String i = line.replace(line,
WarnGenPatterns.LOCK_START + line
+ WarnGenPatterns.LOCK_END);
firstBulletText = firstBulletText.replace(line, i);
continue;
}
@ -216,29 +231,31 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
String name = affectedArea.getName();
String areaNotation = affectedArea.getAreaNotation();
String parentRegion = affectedArea.getParentRegion();
if (name != null && name.trim().length() != 0
&& line.contains(name.toUpperCase())) {
name = name.toUpperCase();
if ((name != null) && (name.trim().length() != 0)
&& line.contains(name)) {
String t = line;
if (!hasBeenLocked(line, name)) {
t = t.replace(name, LOCK_START + name + LOCK_END);
t = t.replace(name, WarnGenPatterns.LOCK_START
+ name + WarnGenPatterns.LOCK_END);
}
if (areaNotation != null
&& areaNotation.trim().length() != 0) {
areaNotation = areaNotation.toUpperCase();
if (!hasBeenLocked(line, areaNotation.toUpperCase())) {
t = t.replace(areaNotation, LOCK_START
+ areaNotation + LOCK_END);
if ((areaNotation != null)
&& (areaNotation.trim().length() != 0)) {
if (!hasBeenLocked(line, areaNotation)) {
t = t.replace(areaNotation,
WarnGenPatterns.LOCK_START
+ areaNotation
+ WarnGenPatterns.LOCK_END);
}
}
if (parentRegion != null
&& parentRegion.trim().length() != 0) {
parentRegion = parentRegion.toUpperCase();
if ((parentRegion != null)
&& (parentRegion.trim().length() != 0)) {
if (!hasBeenLocked(line, parentRegion)) {
t = t.replace(parentRegion, LOCK_START
+ parentRegion + LOCK_END);
t = t.replace(parentRegion,
WarnGenPatterns.LOCK_START
+ parentRegion
+ WarnGenPatterns.LOCK_END);
}
}
@ -251,8 +268,8 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
}
}
firstBulletText = firstBulletText.replaceAll(firstBullet, LOCK_START
+ "$0" + LOCK_END);
Matcher m = WarnGenPatterns.firstBulletPtrn.matcher(firstBulletText);
firstBulletText = m.replaceAll(WarnGenPatterns.REPLACEMENT);
this.text = text.replace(text.substring(start, end), firstBulletText);
}
@ -261,18 +278,19 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
* Locks the second bullet.
*/
private void secondBullet() {
find(secondBulletPtrn.matcher(text));
find(WarnGenPatterns.secondBulletPtrn.matcher(text));
}
/**
* Set the immediateCausePtrn with the info in immediateCause.text.
*/
private static Pattern getImmediateCausesPtrn() {
private Pattern getImmediateCausesPtrn() {
String filename = "immediateCause.txt";
StringBuffer pattern = new StringBuffer();
try {
String immediateCause = WarnFileUtil.convertFileContentsToString(filename, null, null);
String immediateCause = WarnFileUtil.convertFileContentsToString(
filename, null, null);
pattern.append("(.*)(A DAM BREAK");
for (String ic : immediateCause.split("\n")) {
String[] parts = ic.split("\\\\");
@ -318,7 +336,6 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
* Locks the UGC line or FIPS line.
*/
private void ugc() {
Pattern ugcPtrn = Pattern.compile(ugc + NEWLINE, Pattern.MULTILINE);
find(ugcPtrn.matcher(text));
}
@ -326,22 +343,20 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
* Locks the HTEC line.
*/
private void htec() {
find(htecPtrn.matcher(text));
find(WarnGenPatterns.htecPtrn.matcher(text));
}
/**
* Locks the VTEC line.
*/
private void vtec() {
find(vtecPtrn.matcher(text));
find(WarnGenPatterns.vtecPtrn.matcher(text));
}
/**
* Locks the list of area names.
*/
private void areaNames() {
Pattern listOfAreaNamePtrn = Pattern.compile(listOfAreaName + NEWLINE,
Pattern.MULTILINE);
find(listOfAreaNamePtrn.matcher(text));
}
@ -353,13 +368,16 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
protected void find(Matcher m) {
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.
if (group.startsWith(LOCK_END)) {
// If line already starts with a ICommonPatterns.LOCK_END, the
// ICommonPatterns.LOCK_END is removed
// and the line just adds to the ICommonPatterns.LOCK_END at the
// end.
if (group.startsWith(WarnGenPatterns.LOCK_END)) {
this.text = text.replace(group,
group.substring(LOCK_END.length()) + LOCK_END);
group.substring(WarnGenPatterns.LOCK_END.length())
+ WarnGenPatterns.LOCK_END);
} else {
this.text = m.replaceAll(LOCK_START + "$0" + LOCK_END);
this.text = m.replaceAll(WarnGenPatterns.REPLACEMENT);
}
}
}
@ -371,26 +389,21 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
int start = -1;
int end = -1;
StringBuffer mnd = new StringBuffer(
"(BULLETIN - IMMEDIATE BROADCAST REQUESTED)|(BULLETIN - EAS ACTIVATION REQUESTED)|"
+ warningType);
Pattern startMND = Pattern.compile(mnd.toString());
Matcher m = startMND.matcher(text);
if (m.find()) {
start = m.start();
}
m = datePtrn.matcher(text);
m = WarnGenPatterns.datePtrn.matcher(text);
if (m.find()) {
end = m.start();
}
if (start != -1 && end != -1 && start < end) {
if ((start != -1) && (end != -1) && (start < end)) {
String substring = text.substring(start, end);
// There should be only one instance of an MND Header block
this.text = text.replace(substring, LOCK_START + substring
+ LOCK_END);
this.text = text.replace(substring, WarnGenPatterns.LOCK_START
+ substring + WarnGenPatterns.LOCK_END);
}
}
@ -398,14 +411,14 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
* Locks the date.
*/
private void date() {
find(datePtrn.matcher(text));
find(WarnGenPatterns.datePtrn.matcher(text));
}
/**
* Locks the TIME...MOT...LINE (Can be multiple lines).
*/
private void tml() {
find(tmlPtrn.matcher(text));
find(WarnGenPatterns.tmlPtrn.matcher(text));
}
/**
@ -413,27 +426,28 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
*/
private void latLon() {
find(latLonPtrn.matcher(text));
find(WarnGenPatterns.latLonPtrn.matcher(text));
}
/**
* Locks the Call To Action header and the segment tags.
*/
private void callToActions() {
find(cta.matcher(text));
find(WarnGenPatterns.cta.matcher(text));
}
/**
* Locks the test messages.
*/
private void testMessages() {
find(testPtrn.matcher(text));
find(WarnGenPatterns.testPtrn.matcher(text));
}
private void clean() {
// where a lock close and lock open are only separated by whitespace
// remove the close and open to join the two locked areas
text = text.replaceAll("</L>([\\s\\n\\r]*)<L>", "$1");
text = text.replaceAll(WarnGenPatterns.LOCK_END + "([\\s\\n\\r]*)"
+ WarnGenPatterns.LOCK_START, "$1");
}
/**
@ -444,20 +458,23 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
*/
protected boolean isMarineProduct() {
VtecObject vtecObj = VtecUtil.parseMessage(text);
boolean marineProduct = vtecObj != null
&& vtecObj.getPhenomena() != null
boolean marineProduct = (vtecObj != null)
&& (vtecObj.getPhenomena() != null)
&& vtecObj.getPhenomena().equals("MA");
return marineProduct;
}
/**
* Tests if the LOCK_START count matches the LOCK_END count.
* Tests if the ICommonPatterns.LOCK_START count matches the
* ICommonPatterns.LOCK_END count.
*
* @return
*/
public static boolean validate(String modified) {
int startCount = StringUtils.countMatches(modified, LOCK_START);
int endCount = StringUtils.countMatches(modified, LOCK_END);
int startCount = StringUtils.countMatches(modified,
WarnGenPatterns.LOCK_START);
int endCount = StringUtils.countMatches(modified,
WarnGenPatterns.LOCK_END);
return startCount == endCount;
}
@ -471,17 +488,19 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
protected boolean hasBeenLocked(String line, String name) {
int index = line.indexOf(name);
if (index != -1) {
int startBefore = line.lastIndexOf(LOCK_START, index);
int endBefore = line.lastIndexOf(LOCK_END, index);
int startAfter = line.indexOf(LOCK_START, index);
int endAfter = line.indexOf(LOCK_END, index);
int startBefore = line.lastIndexOf(WarnGenPatterns.LOCK_START,
index);
int endBefore = line.lastIndexOf(WarnGenPatterns.LOCK_END, index);
int startAfter = line.indexOf(WarnGenPatterns.LOCK_START, index);
int endAfter = line.indexOf(WarnGenPatterns.LOCK_END, index);
if (startBefore != -1 && endAfter != -1 && startBefore < endAfter) {
if (startAfter != -1 && startAfter < endAfter
&& startAfter > startBefore) {
if ((startBefore != -1) && (endAfter != -1)
&& (startBefore < endAfter)) {
if ((startAfter != -1) && (startAfter < endAfter)
&& (startAfter > startBefore)) {
return false;
} else if (endBefore != -1 && endBefore > startBefore
&& endBefore < endAfter) {
} else if ((endBefore != -1) && (endBefore > startBefore)
&& (endBefore < endAfter)) {
return false;
}
@ -496,8 +515,6 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
* Check out if warning text has state abbreviations, e.g., " MD".
*/
private boolean hasStateAbbrev() {
Pattern stateAbbrevPtrn = Pattern.compile(listOfAreaName + NEWLINE,
Pattern.MULTILINE);
Matcher m = stateAbbrevPtrn.matcher(this.text);
if (m.find()) {
return true;
@ -510,28 +527,28 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
* Check out if pil of the product is SPS or NOW.
*/
public boolean isDesiredPil() {
String[] type = {"SPS", "NOW"};
String[] type = { "SPS", "NOW" };
int index = text.indexOf("000000") + 8;
String pilAndCWA = text.substring(index, index + 6);
for (String s: type) {
for (String s : type) {
if (pilAndCWA.contains(s)) {
return true;
}
}
}
return false;
}
/**
* Locks the list of area names in which state abbreviations, e.g., " MD",
* Locks the list of area names in which state abbreviations, e.g., " MD",
* are not included.
*/
private void lockListOfNames() {
String[] timePattern = {" AM ", " PM ", "NOON", "MIDNIGHT"};
String[] timePattern = { " AM ", " PM ", "NOON", "MIDNIGHT" };
String text1 = "";
int indexOfDash = text.indexOf('-');
String text2 = text.substring(indexOfDash, text.length() - 1);
int indexOfTimePattern;
for (String s: timePattern) {
for (String s : timePattern) {
indexOfTimePattern = text2.indexOf(s);
if (indexOfTimePattern != -1) {
text1 = text2.substring(0, indexOfTimePattern);
@ -540,11 +557,14 @@ abstract public class AbstractLockingBehavior implements ICommonPatterns {
}
int index1, index2;
if (text1.length() > 0) {
index1 = text1.indexOf("</L>");
index1 = text1.indexOf(WarnGenPatterns.LOCK_END);
index2 = text1.lastIndexOf("-");
text2 = text1.substring(index1 + 4, index2 + 1);
index1 = text.indexOf(text2);
text = text.substring(0, index1) + "<L>" + text2 + "</L>"
text = text.substring(0, index1)
+ WarnGenPatterns.LOCK_START
+ text2
+ WarnGenPatterns.LOCK_END
+ text.substring(index1 + text2.length(), text.length() - 1);
}
}

View file

@ -25,7 +25,6 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.raytheon.uf.common.dataplugin.warning.WarningRecord.WarningAction;
import com.raytheon.viz.warngen.gis.AffectedAreas;
/**
@ -41,6 +40,7 @@ import com.raytheon.viz.warngen.gis.AffectedAreas;
* Jan 8, 2013 15664 Qinglu Lin Updated body().
* Mar 13, 2013 15892 D. Friedman Fix headline locking. Do not
* lock "AND" or "FOR".
* May 29, 2015 4442 randerso Fixed WarnGen text locking to work with mixed case
*
* </pre>
*
@ -48,13 +48,39 @@ import com.raytheon.viz.warngen.gis.AffectedAreas;
* @version 1.0
*/
public class FollowUpLockingBehavior extends AbstractLockingBehavior {
private static Pattern headlinePtrn = Pattern
.compile(
"^\\.\\.\\.(AN?|THE) (.*) (WARNING|ADVISORY) .*(REMAINS|EXPIRE|CANCELLED).*(\\.\\.\\.)$",
Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
private static Pattern expirePtrn = Pattern
.compile(
"(HAS BEEN ALLOWED TO EXPIRE)|(WILL BE ALLOWED TO EXPIRE)|(WILL EXPIRE)|(HAS EXPIRED)|EXPIRED",
Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
private static Pattern timePtrn = Pattern.compile(
"AT \\d{3,4} (AM|PM) \\w{3,4}", Pattern.MULTILINE
| Pattern.CASE_INSENSITIVE);
private static Pattern remainsPtrn = Pattern.compile(
"REMAINS IN EFFECT UNTIL \\d{3,4} (AM|PM) \\w{3,4}",
Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
private static Pattern canceledPtrn = Pattern.compile(
"(IS|(HAS BEEN)) CANCELLED", Pattern.MULTILINE
| Pattern.CASE_INSENSITIVE);
private static Pattern warningPtrn = Pattern.compile(
"(AN?|THE)( [\\w\\s]*?)(" + warningType + ")", Pattern.MULTILINE
| Pattern.CASE_INSENSITIVE);
/**
* Locks the appropriate text of the body of an initial warning.
*/
@Override
public void body() {
headlines();
super.body();
headlines();
super.body();
}
/**
@ -64,10 +90,6 @@ public class FollowUpLockingBehavior extends AbstractLockingBehavior {
private void headlines() {
// LOCK_END should not be found at the beginning since the previous line
// should be blank.
Pattern headlinePtrn = Pattern
.compile(
"^\\.\\.\\.(AN?|THE) (.*) (WARNING|ADVISORY) .*(REMAINS|EXPIRE|CANCELLED).*(\\.\\.\\.)$",
Pattern.MULTILINE);
Matcher m = headlinePtrn.matcher(text);
while (m.find()) {
@ -84,12 +106,12 @@ public class FollowUpLockingBehavior extends AbstractLockingBehavior {
* Locks the expired text.
*/
private String expired(String followupHeadline) {
// Based on the templates, the expired text is for the affected areas
// not the canceled areas.
String expire = "(HAS BEEN ALLOWED TO EXPIRE)|(WILL BE ALLOWED TO EXPIRE)|(WILL EXPIRE)|(HAS EXPIRED)|EXPIRED";
String time = "AT \\d{3,4} (AM|PM) \\w{3,4}";
return followupHeadline.replaceAll(expire, REPLACEMENT).replaceAll(
time, REPLACEMENT);
Matcher m = expirePtrn.matcher(followupHeadline);
followupHeadline = m.replaceAll(WarnGenPatterns.REPLACEMENT);
m = timePtrn.matcher(followupHeadline);
followupHeadline = m.replaceAll(WarnGenPatterns.REPLACEMENT);
return followupHeadline;
}
/**
@ -99,9 +121,9 @@ public class FollowUpLockingBehavior extends AbstractLockingBehavior {
* @return
*/
private String remainsInEffect(String followupHeadline) {
return followupHeadline.replaceFirst(
"REMAINS IN EFFECT UNTIL \\d{3,4} (AM|PM) \\w{3,4}", LOCK_START
+ "$0" + LOCK_END);
Matcher m = remainsPtrn.matcher(followupHeadline);
followupHeadline = m.replaceFirst(WarnGenPatterns.REPLACEMENT);
return followupHeadline;
}
/**
@ -111,8 +133,9 @@ public class FollowUpLockingBehavior extends AbstractLockingBehavior {
* @return
*/
private String canceled(String canceledHeadline) {
return canceledHeadline.replaceAll("(IS|(HAS BEEN)) CANCELLED",
REPLACEMENT);
Matcher m = canceledPtrn.matcher(canceledHeadline);
canceledHeadline = m.replaceAll(WarnGenPatterns.REPLACEMENT);
return canceledHeadline;
}
/**
@ -127,19 +150,19 @@ public class FollowUpLockingBehavior extends AbstractLockingBehavior {
Set<String> names = new HashSet<String>();
for (AffectedAreas affectedArea : affectedAreas) {
if (affectedArea.getAreaNotation() != null
&& affectedArea.getAreaNotation().trim().length() != 0) {
notations.add(affectedArea.getAreaNotation().toUpperCase());
if ((affectedArea.getAreaNotation() != null)
&& (affectedArea.getAreaNotation().trim().length() != 0)) {
notations.add(affectedArea.getAreaNotation());
}
if (affectedArea.getAreasNotation() != null
&& affectedArea.getAreasNotation().trim().length() != 0) {
notations.add(affectedArea.getAreasNotation().toUpperCase());
if ((affectedArea.getAreasNotation() != null)
&& (affectedArea.getAreasNotation().trim().length() != 0)) {
notations.add(affectedArea.getAreasNotation());
}
if (affectedArea.getName() != null
&& affectedArea.getName().trim().length() != 0) {
names.add(affectedArea.getName().toUpperCase());
if ((affectedArea.getName() != null)
&& (affectedArea.getName().trim().length() != 0)) {
names.add(affectedArea.getName());
}
}
@ -150,8 +173,9 @@ public class FollowUpLockingBehavior extends AbstractLockingBehavior {
while (iterator1.hasNext()) {
String notation = iterator1.next();
if (!hasBeenLocked(headline, notation)) {
headline = headline.replace(notation, LOCK_START + notation
+ LOCK_END);
headline = headline.replace(notation,
WarnGenPatterns.LOCK_START + notation
+ WarnGenPatterns.LOCK_END);
}
}
@ -159,13 +183,15 @@ public class FollowUpLockingBehavior extends AbstractLockingBehavior {
while (iterator2.hasNext()) {
String name = iterator2.next();
if (!hasBeenLocked(headline, name)) {
headline = headline.replace(name, LOCK_START + name
+ LOCK_END);
headline = headline.replace(name,
WarnGenPatterns.LOCK_START + name
+ WarnGenPatterns.LOCK_END);
}
}
} else {
// The full headline of a marine product should be locked.
headline = LOCK_START + headline + LOCK_END;
headline = WarnGenPatterns.LOCK_START + headline
+ WarnGenPatterns.LOCK_END;
}
return headline;
@ -179,16 +205,19 @@ public class FollowUpLockingBehavior extends AbstractLockingBehavior {
*/
private String keywords(String headline) {
// Locking the start of a head line (...)
headline = headline.replaceFirst("^\\.\\.\\.", LOCK_START + "$0"
+ LOCK_END);
headline = headline.replaceFirst("^\\.\\.\\.",
WarnGenPatterns.REPLACEMENT);
// Locking the end of a head line (...)
if (headline.endsWith("...")) {
headline = headline.substring(0, headline.length() - 3)
+ LOCK_START + "..." + LOCK_END;
+ WarnGenPatterns.LOCK_START + "..."
+ WarnGenPatterns.LOCK_END;
}
// Locks warning type (i.e. SEVERE THUNDERSTORM)
headline = headline.replaceAll("(AN?|THE)( [\\w\\s]*?)(" + warningType + ")",
LOCK_START + "$1" + LOCK_END + "$2" + LOCK_START + "$3" + LOCK_END);
Matcher m = warningPtrn.matcher(headline);
headline = m.replaceAll(WarnGenPatterns.LOCK_START + "$1"
+ WarnGenPatterns.LOCK_END + "$2" + WarnGenPatterns.LOCK_START
+ "$3" + WarnGenPatterns.LOCK_END);
return headline;
}

View file

@ -41,12 +41,14 @@ import java.util.regex.Pattern;
* Apr 29, 2014 3033 jsanchez Added more patterns.
* May 1, 2014 DR 16627 Qinglu Lin Roll back the changes to listOfAreaName on January 6, 2014.
* May 13, 2014 DR 17177 Qinglu Lin Updated secondBullet().
* May 29, 2015 4441 randerso Made patterns case insensitive where necessary
* Renamed and changed from interface to class
* </pre>
*
* @author jsanchez
* @version 1.0
*/
public interface ICommonPatterns {
public class WarnGenPatterns {
/** Start tag for locking */
public static final String LOCK_START = "<L>";
@ -54,6 +56,8 @@ public interface ICommonPatterns {
/** End tag for locking */
public static final String LOCK_END = "</L>";
public static final String REPLACEMENT = LOCK_START + "$0" + LOCK_END;
public static final String NEWLINE = "\\n";
// LOCK_END should not be found at the beginning since the previous line
@ -68,8 +72,9 @@ public interface ICommonPatterns {
// LOCK_END should not be found at the beginning of a first bullet since the
// previous line should be blank.
public static final String firstBullet = "^(\\* (.*) (WARNING|ADVISORY)( FOR(.*)|\\.\\.\\.)"
+ NEWLINE + ")";
public static final Pattern firstBulletPtrn = Pattern
.compile("^(\\* (.*) (WARNING|ADVISORY)( FOR(.*)|\\.\\.\\.)"
+ NEWLINE + ")", Pattern.CASE_INSENSITIVE);
// LOCK_END can be added at the start of the line if a previous line has
// been locked.
@ -82,7 +87,8 @@ public interface ICommonPatterns {
public static final Pattern header = Pattern.compile(
"^((THE NATIONAL WEATHER SERVICE IN .{1,} HAS (ISSUED A|EXTENDED THE))"
+ NEWLINE + ")$", Pattern.MULTILINE);
+ NEWLINE + ")$", Pattern.MULTILINE
| Pattern.CASE_INSENSITIVE);
/*
* LOCK_END should not be found at the beginning since the previous line
@ -90,7 +96,8 @@ public interface ICommonPatterns {
public static final Pattern secondBulletPtrn = Pattern
.compile(
"\\* UNTIL (\\d{3,4} (AM|PM)|NOON|MIDNIGHT) \\w{3,4}( \\w{6,9}){0,1}(\\/(\\d{3,4} (AM|PM)|NOON|MIDNIGHT) \\w{3,4}( \\w{6,9}){0,1}\\/){0,1}"
+ NEWLINE, Pattern.MULTILINE);
+ NEWLINE, Pattern.MULTILINE
| Pattern.CASE_INSENSITIVE);
public static final Pattern htecPtrn = Pattern
.compile(

View file

@ -113,9 +113,8 @@ public class WarningTextHandler {
String[] seperatedLines = text.replaceAll("\r", "").trim().split("\n");
boolean blankLine = false;
for (String line : seperatedLines) {
if (line.replace(AbstractLockingBehavior.LOCK_START, "")
.replace(AbstractLockingBehavior.LOCK_END, "").trim()
.length() > 0) {
if (line.replace(WarnGenPatterns.LOCK_START, "")
.replace(WarnGenPatterns.LOCK_END, "").trim().length() > 0) {
sb.append(line + "\n");
blankLine = false;
} else if (blankLine == false) {

View file

@ -20,7 +20,6 @@
package com.raytheon.viz.warngen.text;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.raytheon.uf.common.dataplugin.warning.WarningRecord.WarningAction;
@ -34,7 +33,8 @@ import com.raytheon.uf.common.dataplugin.warning.WarningRecord.WarningAction;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 24, 2012 15322 jsanchez Initial creation
* Sep 24, 2012 15322 jsanchez Initial creation
* Jun 02, 2015 4441 randerso Made first bullet regex case insensitive
*
* </pre>
*
@ -69,14 +69,12 @@ public class WarningTextHandlerFactory {
}
private static boolean isInitialWarning(WarningAction action, String text) {
if (action == WarningAction.NEW || action == WarningAction.EXT) {
if ((action == WarningAction.NEW) || (action == WarningAction.EXT)) {
return true;
} else if (action == WarningAction.COR) {
// TODO Need a better solution not to include the text in the
// factory.
Pattern firstBulletPtrn = Pattern
.compile(InitialLockingBehavior.firstBullet);
Matcher m = firstBulletPtrn.matcher(text);
Matcher m = WarnGenPatterns.firstBulletPtrn.matcher(text);
return m.find();
}

View file

@ -40,7 +40,7 @@ import java.util.regex.Pattern;
* @author jsanchez
* @version 1.0
*/
public class WrapUtil implements ICommonPatterns {
public class WrapUtil {
/** Maximum width of a warning */
private static final int MAX_WIDTH = 69;
@ -50,19 +50,24 @@ public class WrapUtil implements ICommonPatterns {
private static final String BULLET_START = "* ";
// Guess at the amount of extra characters added by wrapping
private static final int WRAP_COUNT_GUESS = 16 * 3; // *3 for bullet indent + \n
private static final int WRAP_COUNT_GUESS = 16 * 3; // *3 for bullet indent
// + \n
private static final String DELIM_GROUP = "\0";
private static final String[] NORMAL_DELIMS = { " ", "...", DELIM_GROUP, "-" };
private static final String[] NORMAL_DELIMS = { " ", "...", DELIM_GROUP,
"-" };
private static final String[] AREA_DELIMS = { "-", "...", DELIM_GROUP, " " };
private static final String[] UGC_DELIMS = AREA_DELIMS;
// ugc pattern
private static final Pattern ugcPtrn = Pattern.compile(ugc);
private static final Pattern ugcPtrn = Pattern.compile(WarnGenPatterns.ugc);
// list of areas pattern
private static final Pattern listOfAreaNamePtrn = Pattern
.compile(listOfAreaName);
.compile(WarnGenPatterns.listOfAreaName);
/**
* Wraps the text independent of being locked before or after.
@ -78,7 +83,8 @@ public class WrapUtil implements ICommonPatterns {
String[] lines = text.split("\n");
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
String unlocked = line.replaceAll(LOCK_START + "|" + LOCK_END, "");
String unlocked = line.replaceAll(WarnGenPatterns.LOCK_START + "|"
+ WarnGenPatterns.LOCK_END, "");
if (unlocked.trim().length() == 0) { // BLANK LINE
inBullet = false;
@ -93,7 +99,7 @@ public class WrapUtil implements ICommonPatterns {
// Add indenting if the template didn't account for it yet.
int add = wasInBullet && !unlocked.startsWith(INDENT) ? INDENT
.length() : 0;
if (unlocked.length() <= MAX_WIDTH - add) { // LESS THAN MAX
if (unlocked.length() <= (MAX_WIDTH - add)) { // LESS THAN MAX
if (add > 0) {
sb.append(INDENT);
}
@ -104,7 +110,7 @@ public class WrapUtil implements ICommonPatterns {
}
sb.append(addLine);
if (i != lines.length - 1) {
if (i != (lines.length - 1)) {
sb.append("\n");
}
}
@ -138,7 +144,8 @@ public class WrapUtil implements ICommonPatterns {
* @param maxLength
* @return
*/
public static String wrapLongLine(String line, boolean inBullet, String[] delims, int maxLength) {
public static String wrapLongLine(String line, boolean inBullet,
String[] delims, int maxLength) {
StringBuilder sb = new StringBuilder(line.length() + WRAP_COUNT_GUESS);
int start = 0;
int allowLength = maxLength;
@ -152,7 +159,7 @@ public class WrapUtil implements ICommonPatterns {
char[] cb = new char[2];
int i = indexIgnoringLockMarkers(line, start, 0);
int o = 0;
while (i < line.length() && o < 2) {
while ((i < line.length()) && (o < 2)) {
cb[o++] = line.charAt(i);
i = indexIgnoringLockMarkers(line, i, 1);
}
@ -188,15 +195,17 @@ public class WrapUtil implements ICommonPatterns {
int bestP = -1;
for (String delim : delims) {
if (delim == DELIM_GROUP) {
if (bestDelim != null)
if (bestDelim != null) {
break;
}
continue;
}
int backup = " ".equals(delim) ? 0 : delim.length();
int p = !failed ? line.lastIndexOf(delim, limit - backup)
: line.indexOf(delim, limit - backup);
if (p >= start && (bestDelim == null
|| !failed ? p > bestP : p < bestP)) {
if ((p >= start)
&& ((bestDelim == null) || !failed ? p > bestP
: p < bestP)) {
bestDelim = delim;
bestP = p;
}
@ -212,7 +221,7 @@ public class WrapUtil implements ICommonPatterns {
if (inBullet) {
allowLength = maxLength - INDENT.length();
}
} else if (! failed) {
} else if (!failed) {
/*
* Failed to wrap before the margin. Try again, wrapping the
* line after the margin, but still as close to it as possible.
@ -268,20 +277,23 @@ public class WrapUtil implements ICommonPatterns {
* of characters in text past start.
* @return
*/
private static int indexIgnoringLockMarkers(String text, int start, int count) {
private static int indexIgnoringLockMarkers(String text, int start,
int count) {
int i = start;
do {
if (text.startsWith(LOCK_START, i))
i += LOCK_START.length();
else if (text.startsWith(LOCK_END, i))
i += LOCK_END.length();
else if (count > 0) {
if (i >= text.length())
if (text.startsWith(WarnGenPatterns.LOCK_START, i)) {
i += WarnGenPatterns.LOCK_START.length();
} else if (text.startsWith(WarnGenPatterns.LOCK_END, i)) {
i += WarnGenPatterns.LOCK_END.length();
} else if (count > 0) {
if (i >= text.length()) {
break;
}
++i;
--count;
} else
} else {
break;
}
} while (true);
return i;
}
@ -290,21 +302,25 @@ public class WrapUtil implements ICommonPatterns {
* Append text.substring(start, end) to sb, removing any trailing
* whitespace. The trailing whitespace may have have embedded lock marks.
*/
private static void appendRTrim(String text, int start, int end, StringBuilder sb) {
private static void appendRTrim(String text, int start, int end,
StringBuilder sb) {
int sbStart = sb.length();
sb.append(text, start, end);
int i = sb.length();
while (i > sbStart) {
if (Character.isWhitespace(sb.charAt(i - 1))) {
sb.deleteCharAt(--i);
} else if (i - sbStart >= LOCK_START.length() &&
LOCK_START.equals(sb.substring(i - LOCK_START.length(), i))) {
i -= LOCK_START.length();
} else if (i - sbStart >= LOCK_END.length() &&
LOCK_END.equals(sb.substring(i - LOCK_END.length(), i))) {
i -= LOCK_END.length();
} else
} else if (((i - sbStart) >= WarnGenPatterns.LOCK_START.length())
&& WarnGenPatterns.LOCK_START.equals(sb.substring(i
- WarnGenPatterns.LOCK_START.length(), i))) {
i -= WarnGenPatterns.LOCK_START.length();
} else if (((i - sbStart) >= WarnGenPatterns.LOCK_END.length())
&& WarnGenPatterns.LOCK_END.equals(sb.substring(i
- WarnGenPatterns.LOCK_END.length(), i))) {
i -= WarnGenPatterns.LOCK_END.length();
} else {
break;
}
}
}
@ -324,27 +340,30 @@ public class WrapUtil implements ICommonPatterns {
* @return The index in text at which processing for the next line should
* begin.
*/
private static int splitEndOfLine(String text, int start, boolean inBullet, StringBuilder sb) {
private static int splitEndOfLine(String text, int start, boolean inBullet,
StringBuilder sb) {
int goodBreak = start;
int i = start;
while (i < text.length()) {
if (Character.isWhitespace(text.charAt(i))) {
++i;
} else if (text.startsWith(LOCK_START, i)) {
} else if (text.startsWith(WarnGenPatterns.LOCK_START, i)) {
goodBreak = i;
i += LOCK_START.length();
i += WarnGenPatterns.LOCK_START.length();
break;
} else if (text.startsWith(LOCK_END, i)) {
i += LOCK_END.length();
} else if (text.startsWith(WarnGenPatterns.LOCK_END, i)) {
i += WarnGenPatterns.LOCK_END.length();
goodBreak = i;
break;
} else
} else {
break;
}
}
if (i >= text.length())
if (i >= text.length()) {
goodBreak = i;
}
if (goodBreak >= start) {
appendRTrim(text, start, goodBreak, sb);
}

View file

@ -51,6 +51,7 @@ import com.raytheon.uf.viz.core.exception.VizException;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 15, 2007 chammack Initial Creation.
* Jun 02, 2016 4442 randerso Remove upper case conversion
*
* </pre>
*
@ -84,13 +85,13 @@ public class Abbreviation {
String line = bufferedReader.readLine();
String[] tokens = line.split("\\\\");
if (tokens[0].trim().equalsIgnoreCase(DEFAULT)) {
this.defaultAbbrev = tokens[1].trim().toUpperCase();
this.defaultAbbrev = tokens[1].trim();
} else if (tokens[0].trim().equalsIgnoreCase(DEFAULT_PLURAL)) {
this.defaultPluralAbbrev = tokens[1].trim().toUpperCase();
this.defaultPluralAbbrev = tokens[1].trim();
} else {
this.abbreviationMap.put(tokens[0].trim().toUpperCase(),
tokens.length < 2 || tokens[1] == null ? ""
: tokens[1].trim().toUpperCase());
this.abbreviationMap.put(tokens[0].trim(),
(tokens.length < 2) || (tokens[1] == null) ? ""
: tokens[1].trim());
}
}
} catch (Exception e) {
@ -98,14 +99,16 @@ public class Abbreviation {
} finally {
try {
if (bufferedReader != null)
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e1) {
// ignore
}
try {
if (fileReader != null)
if (fileReader != null) {
fileReader.close();
}
} catch (IOException e) {
// ignore
}
@ -114,7 +117,7 @@ public class Abbreviation {
public String translate(String abbreviation) {
String str = this.abbreviationMap.get(abbreviation.toUpperCase());
if (str == null && this.defaultAbbrev != null) {
if ((str == null) && (this.defaultAbbrev != null)) {
return abbreviation.endsWith(PLURAL_SUFFIX) ? this.defaultPluralAbbrev
: this.defaultAbbrev;
}

View file

@ -16,7 +16,7 @@ import com.raytheon.uf.common.time.SimulatedTime;
import com.raytheon.uf.common.time.TimeRange;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.viz.warngen.gis.AffectedAreas;
import com.raytheon.viz.warngen.text.ICommonPatterns;
import com.raytheon.viz.warngen.text.WarnGenPatterns;
/**
* This utility will provide methods for determining what followup products are
@ -176,7 +176,7 @@ public class FollowUpUtil {
String namesLine = "";
String headline = "";
Pattern listOfAreaNamePtrn = Pattern
.compile(ICommonPatterns.listOfAreaName);
.compile(WarnGenPatterns.listOfAreaName);
String[] splitLines = originalText.trim().split("\n");
for (String line : splitLines) {
if (line.contains("TEST") || line.trim().length() == 0) {
@ -282,7 +282,7 @@ public class FollowUpUtil {
public static String getUgcLineCanFromText(String originalText) {
String ugcLine = "";
Pattern ugcPtrn = Pattern.compile(ICommonPatterns.ugc);
Pattern ugcPtrn = Pattern.compile(WarnGenPatterns.ugc);
for (String line : originalText.replaceAll("\r", "").trim().split("\n")) {
Matcher m = ugcPtrn.matcher(line);
if (m.find()) {

View file

@ -1,23 +1,23 @@
LA \ PARISH
LOUISIANA \ PARISH
LA+ \ PARISHES
LOUISIANA+ \ PARISHES
LA \ Parish
Louisiana \ Parish
LA+ \ Parishes
Louisiana+ \ Parishes
DC \
DISTRICT OF COLUMBIA \
District of Columbia \
DC+ \
DISTRICT OF COLUMBIA+ \
District of Columbia+ \
AK \
ALASKA \
Alaska \
AK+ \
ALASKA+ \
PR \ MUNICIPALITY
PUERTO RICO \ MUNICIPALITY
PR+ \ MUNICIPALITIES
PUERTO RICO+ \ MUNICIPALITIES
Alaska+ \
PR \ Municipality
Puerto Rico \ Municipality
PR+ \ Municipalities
Puerto Rico+ \ Municipalities
GU \
GUAM \
Guam \
GU+ \
GUAM+ \
DEFAULT+ \ COUNTIES
DEFAULT \ COUNTY
CITY \
Guam+ \
DEFAULT+ \ Counties
DEFAULT \ County
City \

View file

@ -91,7 +91,7 @@ public class StdTextSeparator extends WMOMessageSeparator {
String product_id = TextDBStaticData.getProductId(ispanId);
// check whether to exclude from decoding for storage
if (product_id != null
if ((product_id != null)
&& TextDBStaticData.isExcluded(product_id.toString())) {
logger.debug("NCF_ENTRY " + product_id.toString() + " is skipped");
return;
@ -172,8 +172,8 @@ public class StdTextSeparator extends WMOMessageSeparator {
// if no product_id is found, use ispanId to store and assign
// a dummy to product_id so that such products can still be stored
// during the AFOS to AWIPS transition.
if (parsedMsg.length() > 6 && parsedMsg.charAt(6) != '\r'
&& parsedMsg.charAt(6) != '\n') {
if ((parsedMsg.length() > 6) && (parsedMsg.charAt(6) != '\r')
&& (parsedMsg.charAt(6) != '\n')) {
nnnxxx = "NONAWIPS";
} else {
nnnxxx = parsedMsg.substring(0, (parsedMsg.length() > 6 ? 6