From 4cfbeb826ab0ff68e525111fb1def3b9b394e9cb Mon Sep 17 00:00:00 2001 From: Mark Peters Date: Tue, 30 Sep 2014 11:39:40 -0500 Subject: [PATCH] Omaha #3629 Replacing matchElement() Change-Id: Ie8ae1347a1aeb99532e42c7a3af7d200cf4c3a1e Former-commit-id: 776420f2d97fc43b3ee9490c38f4430cd8dd773d [formerly 6a0703ad98a30bf514c46936d13662b3a4fbd471 [formerly 6d59eb314d0ae2c7dc4cfe4b6ce2604af7052f95] [formerly 776420f2d97fc43b3ee9490c38f4430cd8dd773d [formerly 6f898cc3d7f30651846847c5645ec26ac448ec83]]] Former-commit-id: 6a0703ad98a30bf514c46936d13662b3a4fbd471 [formerly 6d59eb314d0ae2c7dc4cfe4b6ce2604af7052f95] Former-commit-id: 6a0703ad98a30bf514c46936d13662b3a4fbd471 Former-commit-id: 17f328433b3f2827879159a3d9fedd88bd64db9c --- .../sfcobs/decoder/buoy/DRIBUSec1Decoder.java | 13 ++- .../sfcobs/decoder/buoy/DRIBUSec2Decoder.java | 16 ++-- .../sfcobs/decoder/buoy/DRIBUSec3Decoder.java | 14 ++-- .../sfcobs/decoder/buoy/DRIBUSec4Decoder.java | 17 ++-- .../decoder/buoy/DRIBUSynopticDecoder.java | 34 ++++++-- .../synoptic/AbstractSynopticDecoder.java | 7 ++ .../decoder/synoptic/CMANSynopticDecoder.java | 4 +- .../sfcobs/decoder/synoptic/ISynoptic.java | 39 ++++++--- .../decoder/synoptic/LandSynopticDecoder.java | 4 +- .../synoptic/MAROBSynopticDecoder.java | 4 +- .../synoptic/MobileSynopticDecoder.java | 16 +++- .../decoder/synoptic/SHIPSynopticDecoder.java | 9 +- .../decoder/synoptic/SynopticGroups.java | 9 +- .../decoder/synoptic/SynopticSec1Decoder.java | 24 +++--- .../decoder/synoptic/SynopticSec2Decoder.java | 12 ++- .../decoder/synoptic/SynopticSec3Decoder.java | 8 +- .../decoder/synoptic/SynopticSec4Decoder.java | 20 ++--- .../synoptic/regional/Sec5Block72Decoder.java | 11 +-- .../regional/Sec5MaritimeDecoder.java | 82 +++++++++++++------ .../sfcobs/decoder/TestSfcObsDecoders.java | 12 +-- 20 files changed, 219 insertions(+), 136 deletions(-) diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec1Decoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec1Decoder.java index 20eca51ceb..3cdc92a761 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec1Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec1Decoder.java @@ -47,6 +47,7 @@ import com.raytheon.uf.edex.decodertools.time.TimeTools; * 20071010 391 jkorman Initial coding. * Sep 18, 2014 3627 mapeters Updated deprecated {@link TimeTools} usage. * Sep 26, 2014 3629 mapeters Replaced static imports. + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} calls. * * * @@ -110,17 +111,13 @@ public class DRIBUSec1Decoder extends AbstractSectionDecoder { break; } - if (AbstractSfcObsDecoder.matchElement(element, - DRIBUSec2Decoder.SEC_2_PATTERN)) { + if (DRIBUSec2Decoder.SEC_2_PATTERN.matcher(element).find()) { break; - } else if (AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_3_LEAD)) { + } else if (ISynoptic.SEC_3_LEAD_PATTERN.matcher(element).find()) { break; - } else if (AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_4_LEAD)) { + } else if (ISynoptic.SEC_4_LEAD_PATTERN.matcher(element).find()) { break; - } else if (AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_5_LEAD)) { + } else if (ISynoptic.SEC_5_LEAD_PATTERN.matcher(element).find()) { break; } diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec2Decoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec2Decoder.java index 211819b1a6..573ebad3c1 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec2Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec2Decoder.java @@ -49,6 +49,8 @@ import com.raytheon.uf.edex.decodertools.core.IDecoderConstants; * ------------ ---------- ----------- -------------------------- * 20071010 391 jkorman Initial coding. * Sep 26, 2014 3629 mapeters Removed unused fields, replaced static imports. + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} + * calls, changed SEC_2_PATTERN from String to Pattern. * * * @@ -57,7 +59,7 @@ import com.raytheon.uf.edex.decodertools.core.IDecoderConstants; */ public class DRIBUSec2Decoder extends AbstractSectionDecoder { - public static final String SEC_2_PATTERN = "222[/0-9]{2}"; + public static final Pattern SEC_2_PATTERN = Pattern.compile("222[/0-9]{2}"); private DataItem seaTemp = null; @@ -84,7 +86,6 @@ public class DRIBUSec2Decoder extends AbstractSectionDecoder { * Thrown when an relevant error has occurred. */ public void decode(ReportParser reportParser) throws DecoderException { - Pattern sec2 = Pattern.compile(SEC_2_PATTERN); init(); if (reportParser == null) { // nothing to do. @@ -92,7 +93,7 @@ public class DRIBUSec2Decoder extends AbstractSectionDecoder { } String element = null; - if (reportParser.positionTo(sec2)) { + if (reportParser.positionTo(SEC_2_PATTERN)) { while (true) { // if we run out of data, exit. if (reportParser.next()) { @@ -103,14 +104,11 @@ public class DRIBUSec2Decoder extends AbstractSectionDecoder { break; } - if (AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_3_LEAD)) { + if (ISynoptic.SEC_3_LEAD_PATTERN.matcher(element).find()) { break; - } else if (AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_4_LEAD)) { + } else if (ISynoptic.SEC_4_LEAD_PATTERN.matcher(element).find()) { break; - } else if (AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_5_LEAD)) { + } else if (ISynoptic.SEC_5_LEAD_PATTERN.matcher(element).find()) { break; } diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec3Decoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec3Decoder.java index 56e66159ed..0c805fbc72 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec3Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec3Decoder.java @@ -19,15 +19,12 @@ **/ package com.raytheon.edex.plugin.sfcobs.decoder.buoy; -import static com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder.matchElement; -import static com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic.SEC_3_LEAD; -import static com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic.SEC_4_LEAD; -import static com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic.SEC_5_LEAD; - import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.ReportParser; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.AbstractSectionDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.AbstractSynopticDecoder; +import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; /** @@ -42,6 +39,7 @@ import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 20070928 391 jkorman Initial Coding. + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} calls. * * * @@ -73,7 +71,7 @@ public class DRIBUSec3Decoder extends AbstractSectionDecoder { return; } String element = null; - if (reportParser.positionTo(SEC_3_LEAD)) { + if (reportParser.positionTo(ISynoptic.SEC_3_LEAD_STRING)) { while (true) { // if we run out of data, exit. if (reportParser.next()) { @@ -84,9 +82,9 @@ public class DRIBUSec3Decoder extends AbstractSectionDecoder { break; } - if (matchElement(element, SEC_4_LEAD)) { + if (ISynoptic.SEC_4_LEAD_PATTERN.matcher(element).find()) { break; - } else if (matchElement(element, SEC_5_LEAD)) { + } else if (ISynoptic.SEC_5_LEAD_PATTERN.matcher(element).find()) { break; } diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec4Decoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec4Decoder.java index ed4b7b7530..58647cf849 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec4Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSec4Decoder.java @@ -19,15 +19,12 @@ **/ package com.raytheon.edex.plugin.sfcobs.decoder.buoy; -import static com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder.getInt; -import static com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder.matchElement; -import static com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic.SEC_4_LEAD; -import static com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic.SEC_5_LEAD; - import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.ReportParser; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.AbstractSectionDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.AbstractSynopticDecoder; +import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; /** @@ -41,6 +38,7 @@ import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 20071010 391 jkorman Initial coding. + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} calls. * * * @author jkorman @@ -77,7 +75,7 @@ public class DRIBUSec4Decoder extends AbstractSectionDecoder { return; } String element = null; - if (reportParser.positionTo(SEC_4_LEAD)) { + if (reportParser.positionTo(ISynoptic.SEC_4_LEAD_STRING)) { while (true) { // if we run out of data, exit. if (reportParser.next()) { @@ -88,13 +86,14 @@ public class DRIBUSec4Decoder extends AbstractSectionDecoder { break; } - if (matchElement(element, SEC_5_LEAD)) { + if (ISynoptic.SEC_5_LEAD_PATTERN.matcher(element).find()) { break; } if ("7".equals(element.substring(0, 1))) { - driftSpeed = getInt(element, 1, 3); - driftDirection = getInt(element, 3, 5); + driftSpeed = AbstractSfcObsDecoder.getInt(element, 1, 3); + driftDirection = AbstractSfcObsDecoder + .getInt(element, 3, 5); closeGroup(7); } diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSynopticDecoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSynopticDecoder.java index 8800b483dd..1aa6ea69a2 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSynopticDecoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/buoy/DRIBUSynopticDecoder.java @@ -19,7 +19,10 @@ **/ package com.raytheon.edex.plugin.sfcobs.decoder.buoy; +import java.util.regex.Pattern; + import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.AbstractSynopticDecoder; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; @@ -36,6 +39,9 @@ import com.raytheon.uf.common.pointdata.spatial.SurfaceObsLocation; * ------------ ---------- ----------- -------------------------- * 20070928 391 jkorman Initial Coding. * Jul 23, 2014 3410 bclement location changed to floats + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} + * calls, added Pattern constants. + * * * * @author jkorman @@ -47,6 +53,22 @@ public class DRIBUSynopticDecoder extends AbstractSynopticDecoder { // private Integer dateMM = null; // Month // private Integer dateJ = null; // Units digit of year // private Integer dategg = null; // Minutes + + private static final Pattern PATTERN_1357d5 = Pattern + .compile("[1357]\\d{5}"); + + private static final Pattern PATTERN_1357d4 = Pattern + .compile("[1357]\\d{4}/"); + + private static final Pattern PATTERN_1357d3 = Pattern + .compile("[1357]\\d{3}//"); + + private static final Pattern PATTERN_d6 = Pattern.compile("\\d{6}"); + + private static final Pattern PATTERN_d5 = Pattern.compile("\\d{5}/"); + + private static final Pattern PATTERN_d4 = Pattern.compile("\\d{4}//"); + private Float buoyLatitude = null; private Float buoyLongitude = null; @@ -184,14 +206,14 @@ public class DRIBUSynopticDecoder extends AbstractSynopticDecoder { String element = reportParser.getElement(); Integer lat = null; float divisor = 1000.0f; - if (matchElement(element, "[1357]\\d{5}")) { + if (PATTERN_1357d5.matcher(element).find()) { buoyQuadrant = getInt(element, 0, 1); lat = getInt(element, 1, 6); - } else if (matchElement(element, "[1357]\\d{4}/")) { + } else if (PATTERN_1357d4.matcher(element).find()) { buoyQuadrant = getInt(element, 0, 1); lat = getInt(element, 1, 5); divisor = 100.0f; - } else if (matchElement(element, "[1357]\\d{3}//")) { + } else if (PATTERN_1357d3.matcher(element).find()) { buoyQuadrant = getInt(element, 0, 1); lat = getInt(element, 1, 4); divisor = 10.0f; @@ -217,12 +239,12 @@ public class DRIBUSynopticDecoder extends AbstractSynopticDecoder { String element = reportParser.getElement(); Integer lon = null; float divisor = 1000.0f; - if (matchElement(element, "\\d{6}")) { + if (PATTERN_d6.matcher(element).find()) { lon = getInt(element, 0, 6); - } else if (matchElement(element, "\\d{5}/")) { + } else if (PATTERN_d5.matcher(element).find()) { lon = getInt(element, 0, 5); divisor = 100.0f; - } else if (matchElement(element, "\\d{4}//")) { + } else if (PATTERN_d4.matcher(element).find()) { lon = getInt(element, 0, 4); divisor = 10.0f; } diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/AbstractSynopticDecoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/AbstractSynopticDecoder.java index 0908c0f7d5..017f1e50fa 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/AbstractSynopticDecoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/AbstractSynopticDecoder.java @@ -23,6 +23,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.TimeZone; +import java.util.regex.Pattern; import com.raytheon.edex.exception.DecoderException; import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; @@ -47,6 +48,7 @@ import com.raytheon.uf.edex.decodertools.time.TimeTools; * ------------ ---------- ----------- -------------------------- * 20070928 391 jkorman Initial Coding. * May 14, 2014 2536 bclement removed TimeTools usage + * Sep 30, 2014 3629 mapeters Added LAT_PATTERN, LON_PATTERN. * * * @author jkorman @@ -54,6 +56,11 @@ import com.raytheon.uf.edex.decodertools.time.TimeTools; */ public abstract class AbstractSynopticDecoder extends AbstractSfcObsDecoder { + protected static final Pattern LAT_PATTERN = Pattern.compile("99\\d{3}"); + + protected static final Pattern LON_PATTERN = Pattern + .compile("[1357]((0\\d{3})|(1(([0-7]\\d{2})|(800))))"); + private static final int LINE_CUT_LENGTH = 58; private static final ArrayList wxAbrev = new ArrayList(); diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/CMANSynopticDecoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/CMANSynopticDecoder.java index d15889eed4..6eb7cde299 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/CMANSynopticDecoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/CMANSynopticDecoder.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.regional.Sec5MaritimeDecoder; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; @@ -45,6 +46,7 @@ import com.raytheon.uf.edex.pointdata.spatial.ObStationDao; * Dec 17, 2007 600 bphillip Added dao pool usage * 20080116 798 jkorman Changed logging levels. * Feb 27, 2013 1638 mschenke Moved ObStationDao to edex pointdata plugin + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} calls. * * * @author jkorman @@ -79,7 +81,7 @@ public class CMANSynopticDecoder extends LandSynopticDecoder { if (isValid) { reportParser.next(); element = reportParser.getElement(); - if (matchElement(element, ISynoptic.YYGGI_SUB_W)) { + if (ISynoptic.YYGGI_SUB_W.matcher(element).find()) { try { Integer month = getHeader().getMonth(); diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/ISynoptic.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/ISynoptic.java index 9098892d47..461775c328 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/ISynoptic.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/ISynoptic.java @@ -19,6 +19,8 @@ **/ package com.raytheon.edex.plugin.sfcobs.decoder.synoptic; +import java.util.regex.Pattern; + /** * * @@ -32,6 +34,7 @@ package com.raytheon.edex.plugin.sfcobs.decoder.synoptic; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 20070925 391 jkorman Initial Coding. + * Sep 30, 2014 3629 mapeters Changed constants to Patterns, added Pattern constants. * * * @author jkorman @@ -39,26 +42,40 @@ package com.raytheon.edex.plugin.sfcobs.decoder.synoptic; */ public interface ISynoptic { - public static final String GENERAL_GROUP = "[0-9/]{5}"; + public static final Pattern GENERAL_GROUP = Pattern + .compile("[0-9/]{5}"); - public static final String YYGGI_SUB_W = "([012]\\d{1}|3[01])[0-5]\\d{1}[/0134]"; + public static final Pattern YYGGI_SUB_W = Pattern + .compile("([012]\\d{1}|3[01])[0-5]\\d{1}[/0134]"); - public static final String SEC_1_IRIXHVV = "[0-4][0-7][0-9/](\\d{2}|//)"; + public static final Pattern SEC_1_IRIXHVV = Pattern + .compile("[0-4][0-7][0-9/](\\d{2}|//)"); - public static final String SEC_1_NDDFF = "([/0-9])(//|([012]\\d)|(3[0-6]))(//|\\d{2})"; + public static final Pattern SEC_1_NDDFF = Pattern + .compile("([/0-9])(//|([012]\\d)|(3[0-6]))(//|\\d{2})"); - public static final String SEC_1_TEMPDEW = "[0128](\\d{4} | ////)"; + public static final Pattern SEC_5_72_CTEMP = Pattern + .compile("1[01][0-9/]{2}"); - public static final String SEC_5_72_CTEMP = "1[01][0-9/]{2}"; + public static final Pattern SEC_5_72_CMAXMIN = Pattern + .compile("[01][0-9/]{2}[01][0-9/]{2}"); - public static final String SEC_5_72_CMAXMIN = "[01][0-9/]{2}[01][0-9/]{2}"; + public static final Pattern SEC_2_LEAD = Pattern + .compile("222[0-9/]{2}"); - public static final String SEC_2_LEAD = "222[0-9/]{2}"; + public static final String SEC_3_LEAD_STRING = "333"; - public static final String SEC_3_LEAD = "333"; + public static final Pattern SEC_3_LEAD_PATTERN = Pattern + .compile(SEC_3_LEAD_STRING); - public static final String SEC_4_LEAD = "444"; + public static final String SEC_4_LEAD_STRING = "444"; - public static final String SEC_5_LEAD = "555"; + public static final Pattern SEC_4_LEAD_PATTERN = Pattern + .compile(SEC_4_LEAD_STRING); + + public static final String SEC_5_LEAD_STRING = "555"; + + public static final Pattern SEC_5_LEAD_PATTERN = Pattern + .compile(SEC_5_LEAD_STRING); } diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/LandSynopticDecoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/LandSynopticDecoder.java index ef52f2ef9e..1aa43e9d50 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/LandSynopticDecoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/LandSynopticDecoder.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.regional.Sec5Block72Decoder; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; @@ -52,6 +53,7 @@ import com.raytheon.uf.edex.pointdata.spatial.ObStationDao; * Dec 17, 2007 600 bphillip Added dao pool usage * 20080116 798 jkorman Changed logging levels. * Feb 27, 2013 1638 mschenke Moved ObStationDao to edex pointdata plugin + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} calls. * * * @author jkorman @@ -88,7 +90,7 @@ public class LandSynopticDecoder extends AbstractSynopticDecoder { if (isValid) { reportParser.next(); element = reportParser.getElement(); - if (matchElement(element, ISynoptic.YYGGI_SUB_W)) { + if (ISynoptic.YYGGI_SUB_W.matcher(element).find()) { try { Integer month = getHeader().getMonth(); if (month != -1) { diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/MAROBSynopticDecoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/MAROBSynopticDecoder.java index 8609babf62..a3ace0a7fe 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/MAROBSynopticDecoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/MAROBSynopticDecoder.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; @@ -38,6 +39,7 @@ import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; * ------------ ---------- ----------- -------------------------- * 20071010 391 jkorman Initial coding. * 20071217 453 jkorman Added code to report MAROB report type. + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} calls. * * * @@ -77,7 +79,7 @@ public class MAROBSynopticDecoder extends SHIPSynopticDecoder { setReportIdentifier(reportParser.getElement()); reportParser.next(); element = reportParser.getElement(); - if (matchElement(element, ISynoptic.YYGGI_SUB_W)) { + if (ISynoptic.YYGGI_SUB_W.matcher(element).find()) { try { Integer month = getHeader().getMonth(); if (month != -1) { diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/MobileSynopticDecoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/MobileSynopticDecoder.java index 35856853e9..c393bf63a1 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/MobileSynopticDecoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/MobileSynopticDecoder.java @@ -19,10 +19,13 @@ **/ package com.raytheon.edex.plugin.sfcobs.decoder.synoptic; +import java.util.regex.Pattern; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; import com.raytheon.uf.common.pointdata.spatial.SurfaceObsLocation; @@ -40,6 +43,8 @@ import com.raytheon.uf.edex.decodertools.core.IDecoderConstants; * ------------ ---------- ----------- -------------------------- * 20070928 391 jkorman Initial Coding. * Jul 23, 2014 3410 bclement location changed to floats + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} + * calls, added ELEV_PATTERN. * * * @author jkorman @@ -47,6 +52,9 @@ import com.raytheon.uf.edex.decodertools.core.IDecoderConstants; */ public class MobileSynopticDecoder extends AbstractSynopticDecoder { + private static final Pattern ELEV_PATTERN = Pattern + .compile("[/0-9]{4}[1-8]"); + // The logger private Log logger = LogFactory.getLog(getClass()); @@ -92,7 +100,7 @@ public class MobileSynopticDecoder extends AbstractSynopticDecoder { setReportIdentifier(reportParser.getElement()); reportParser.next(); element = reportParser.getElement(); - if (matchElement(element, ISynoptic.YYGGI_SUB_W)) { + if (ISynoptic.YYGGI_SUB_W.matcher(element).find()) { try { Integer month = getHeader().getMonth(); if (month != -1) { @@ -171,7 +179,7 @@ public class MobileSynopticDecoder extends AbstractSynopticDecoder { reportParser.next(); String element = reportParser.getElement(); - if (matchElement(element, "99\\d{3}")) { + if (LAT_PATTERN.matcher(element).find()) { Integer lat = getInt(element, 2, 5); if (lat != null) { mobileLatitude = lat.floatValue() / 10.0f; @@ -190,7 +198,7 @@ public class MobileSynopticDecoder extends AbstractSynopticDecoder { reportParser.next(); String element = reportParser.getElement(); - if (matchElement(element, "[1357]((0\\d{3})|(1(([0-7]\\d{2})|(800))))")) { + if (LON_PATTERN.matcher(element).find()) { Integer lon = getInt(element, 2, 5); if (lon != null) { mobileLongitude = lon.floatValue() / 10.0f; @@ -257,7 +265,7 @@ public class MobileSynopticDecoder extends AbstractSynopticDecoder { reportParser.next(); String element = reportParser.getElement(); - if (matchElement(element, "[/0-9]{4}[1-8]")) { + if (ELEV_PATTERN.matcher(element).find()) { Integer elev = getInt(element, 0, 4); if (elev != null) { if (elev >= 0) { diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SHIPSynopticDecoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SHIPSynopticDecoder.java index 44cebfbca5..8d72febaab 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SHIPSynopticDecoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SHIPSynopticDecoder.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.regional.Sec5MaritimeDecoder; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; @@ -49,12 +50,14 @@ import com.raytheon.uf.edex.pointdata.spatial.ObStationDao; * 20120619 DR 14015 mporricelli Added elevation for fixed buoys * Feb 27, 2013 1638 mschenke Moved ObStationDao to edex pointdata plugin * Jul 23, 2014 3410 bclement location changed to floats + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} calls. * * * @author jkorman * @version 1.0 */ public class SHIPSynopticDecoder extends AbstractSynopticDecoder { + // The logger private Log logger = LogFactory.getLog(getClass()); @@ -123,7 +126,7 @@ public class SHIPSynopticDecoder extends AbstractSynopticDecoder { } reportParser.next(); element = reportParser.getElement(); - if (matchElement(element, ISynoptic.YYGGI_SUB_W)) { + if (ISynoptic.YYGGI_SUB_W.matcher(element).find()) { try { Integer month = getHeader().getMonth(); if (month != -1) { @@ -219,7 +222,7 @@ public class SHIPSynopticDecoder extends AbstractSynopticDecoder { reportParser.next(); String element = reportParser.getElement(); - if (matchElement(element, "99\\d{3}")) { + if (LAT_PATTERN.matcher(element).find()) { Integer lat = getInt(element, 2, 5); if ((lat != null) && (lat >= 0)) { shipLatitude = lat.floatValue() / 10.0f; @@ -237,7 +240,7 @@ public class SHIPSynopticDecoder extends AbstractSynopticDecoder { reportParser.next(); String element = reportParser.getElement(); - if (matchElement(element, "[1357]((0\\d{3})|(1(([0-7]\\d{2})|(800))))")) { + if (LON_PATTERN.matcher(element).find()) { Integer lon = getInt(element, 1, 5); if ((lon != null) && (lon >= 0)) { shipLongitude = lon.floatValue() / 10.0f; diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticGroups.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticGroups.java index 37e5c807a8..d365e18eec 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticGroups.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticGroups.java @@ -19,6 +19,8 @@ **/ package com.raytheon.edex.plugin.sfcobs.decoder.synoptic; +import java.util.regex.Pattern; + import javax.measure.converter.UnitConverter; import javax.measure.unit.SI; @@ -54,6 +56,9 @@ import com.raytheon.uf.edex.decodertools.core.IDecoderConstants; * 20071109 391 jkorman Factored out time constants. * Sep 18, 2014 #3627 mapeters Convert units using {@link UnitConverter}. * Sep 26, 2014 #3629 mapeters Replaced static imports. + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} + * calls, added HUMIDITY_PATTERN. + * * * * @author jkorman @@ -61,6 +66,8 @@ import com.raytheon.uf.edex.decodertools.core.IDecoderConstants; */ public class SynopticGroups { + private static final Pattern HUMIDITY_PATTERN = Pattern.compile("2\\d{4}"); + private static final int PREFIX_START = 0; private static final String RH_PREFIX = "29"; @@ -88,7 +95,7 @@ public class SynopticGroups { int lookingForSect) { DataItem decodedItem = null; - if (AbstractSfcObsDecoder.matchElement(groupData, "2\\d{4}")) { + if (HUMIDITY_PATTERN.matcher(groupData).find()) { Integer val = Integer.parseInt(groupData.substring(2, 5)); if ((val != null) && (val >= 0)) { if (lookingForSect == 1) { diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec1Decoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec1Decoder.java index 9e9acef975..7a349e3a15 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec1Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec1Decoder.java @@ -20,6 +20,7 @@ package com.raytheon.edex.plugin.sfcobs.decoder.synoptic; import java.util.Calendar; +import java.util.regex.Pattern; import com.raytheon.edex.exception.DecoderException; import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; @@ -48,6 +49,8 @@ import com.raytheon.uf.edex.decodertools.time.TimeTools; * Sep 18, 2014 #3627 mapeters Updated deprecated {@link TimeTools} usage, * removed unused lowCloudAmount field. * Sep 26, 2014 #3629 mapeters Replaced static imports. + * Sep 30, 2014 #3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} + * calls, added PATTERN_8094. * * * @@ -55,6 +58,9 @@ import com.raytheon.uf.edex.decodertools.time.TimeTools; * @version 1.0 */ public class SynopticSec1Decoder extends AbstractSectionDecoder { + + private static final Pattern PATTERN_8094 = Pattern.compile("8[/0-9]{4}"); + // The report observation hour - from 9 group private Integer obsTimeHour = null; @@ -144,8 +150,7 @@ public class SynopticSec1Decoder extends AbstractSectionDecoder { break; } if (!irix && !winds - && AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_1_IRIXHVV)) { + && ISynoptic.SEC_1_IRIXHVV.matcher(element).find()) { // iSubR = getInt(element, 0, 1); AbstractSfcObsDecoder.getInt(element, 0, 1); @@ -157,8 +162,7 @@ public class SynopticSec1Decoder extends AbstractSectionDecoder { irix = true; continue; } else if (!winds - && AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_1_NDDFF)) { + && ISynoptic.SEC_1_NDDFF.matcher(element).find()) { totalCloud = AbstractSfcObsDecoder.getInt(element, 0, 1); Integer temp = AbstractSfcObsDecoder.getInt(element, 1, 3); if ((temp != null) && (temp >= 0)) { @@ -186,14 +190,13 @@ public class SynopticSec1Decoder extends AbstractSectionDecoder { } continue; } else if (winds - && AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_2_LEAD)) { + && ISynoptic.SEC_2_LEAD.matcher(element).find()) { break; - } else if (ISynoptic.SEC_3_LEAD.equals(element)) { + } else if (ISynoptic.SEC_3_LEAD_STRING.equals(element)) { break; - } else if (ISynoptic.SEC_4_LEAD.equals(element)) { + } else if (ISynoptic.SEC_4_LEAD_STRING.equals(element)) { break; - } else if (ISynoptic.SEC_5_LEAD.equals(element)) { + } else if (ISynoptic.SEC_5_LEAD_STRING.equals(element)) { break; } else if ("80000".equals(element)) { break; @@ -253,8 +256,7 @@ public class SynopticSec1Decoder extends AbstractSectionDecoder { winds = true; } else if ("8".equals(element.substring(0, 1)) && doGroup(8)) { if (!winds - && AbstractSfcObsDecoder.matchElement(element, - "8[/0-9]{4}")) { + && PATTERN_8094.matcher(element).find()) { if ((lowCloudType = AbstractSfcObsDecoder.getInt(element, 2, 3)) < 0) { lowCloudType = null; diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec2Decoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec2Decoder.java index b5519d7a19..049723c252 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec2Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec2Decoder.java @@ -19,8 +19,6 @@ **/ package com.raytheon.edex.plugin.sfcobs.decoder.synoptic; -import java.util.regex.Pattern; - import com.raytheon.edex.exception.DecoderException; import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.DataItem; @@ -42,6 +40,7 @@ import com.raytheon.uf.edex.decodertools.core.IDecoderConstants; * 20071109 391 jkorman Added guard for short data. * 2013/8 757 T. Lee Checked missing wave height from ship report * Sep 26, 2014 3629 mapeters Replaced static imports. + * Sep 30, 2014 3629 mapeters Conformed to changes in {@link ISynoptic} constants. * * * @@ -108,13 +107,12 @@ public class SynopticSec2Decoder extends AbstractSectionDecoder { * Thrown when an relevant error has occurred. */ public void decode(ReportParser reportParser) throws DecoderException { - Pattern pattern = Pattern.compile(ISynoptic.SEC_2_LEAD); init(); if (reportParser == null) { // nothing to do. return; } - if (reportParser.positionTo(pattern)) { + if (reportParser.positionTo(ISynoptic.SEC_2_LEAD)) { String element = reportParser.getElement(); // need to decode the Ds vs data shipDirection = AbstractSfcObsDecoder.getInt(element, 3, 4); @@ -129,11 +127,11 @@ public class SynopticSec2Decoder extends AbstractSectionDecoder { break; } - if (ISynoptic.SEC_3_LEAD.equals(element)) { + if (ISynoptic.SEC_3_LEAD_STRING.equals(element)) { break; - } else if (ISynoptic.SEC_4_LEAD.equals(element)) { + } else if (ISynoptic.SEC_4_LEAD_STRING.equals(element)) { break; - } else if (ISynoptic.SEC_5_LEAD.equals(element)) { + } else if (ISynoptic.SEC_5_LEAD_STRING.equals(element)) { break; } else if ("80000".equals(element)) { break; diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec3Decoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec3Decoder.java index 22042794c0..6f629fc4bb 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec3Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec3Decoder.java @@ -59,7 +59,7 @@ import com.raytheon.uf.edex.decodertools.core.IDecoderConstants; * Sep 18, 2014 #3627 mapeters Convert units using {@link UnitConverter}, removed * unused duration field, made patterns constant. * Sep 26, 2014 #3629 mapeters Replaced static imports. - * + * Sep 30, 2014 #3629 mapeters Conformed to changes in ISynoptic constants. * * * @@ -129,7 +129,7 @@ public class SynopticSec3Decoder extends AbstractSectionDecoder { return; } String element = null; - if (reportParser.positionTo(ISynoptic.SEC_3_LEAD)) { + if (reportParser.positionTo(ISynoptic.SEC_3_LEAD_STRING)) { while (true) { // if we run out of data, exit. if (reportParser.next()) { @@ -139,9 +139,9 @@ public class SynopticSec3Decoder extends AbstractSectionDecoder { } else { break; } - if (ISynoptic.SEC_4_LEAD.equals(element)) { + if (ISynoptic.SEC_4_LEAD_STRING.equals(element)) { break; - } else if (ISynoptic.SEC_5_LEAD.equals(element)) { + } else if (ISynoptic.SEC_5_LEAD_STRING.equals(element)) { break; } else if ("80000".equals(element)) { break; diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec4Decoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec4Decoder.java index 71430bf524..565b5fc4ff 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec4Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/SynopticSec4Decoder.java @@ -19,12 +19,8 @@ **/ package com.raytheon.edex.plugin.sfcobs.decoder.synoptic; -import static com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder.getInt; -import static com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder.matchElement; -import static com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic.GENERAL_GROUP; -import static com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic.SEC_4_LEAD; - import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.ReportParser; import com.raytheon.uf.common.dataplugin.sfcobs.AncCloud; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; @@ -40,6 +36,7 @@ import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 20071010 391 jkorman Initial coding. + * Sep 30, 2014 3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} calls. * * * @author jkorman @@ -90,15 +87,16 @@ public class SynopticSec4Decoder extends AbstractSectionDecoder { // nothing to do. return; } - if (reportParser.positionTo(SEC_4_LEAD)) { + if (reportParser.positionTo(ISynoptic.SEC_4_LEAD_STRING)) { if (reportParser.next()) { String element = reportParser.getElement(); - if (matchElement(element, GENERAL_GROUP)) { - cloudAmount = getInt(element, 0, 1); - cloudGenus = getInt(element, 1, 2); - cloudAltitude = getInt(element, 2, 4); - cloudDescription = getInt(element, 4, 5); + if (ISynoptic.GENERAL_GROUP.matcher(element).find()) { + cloudAmount = AbstractSfcObsDecoder.getInt(element, 0, 1); + cloudGenus = AbstractSfcObsDecoder.getInt(element, 1, 2); + cloudAltitude = AbstractSfcObsDecoder.getInt(element, 2, 4); + cloudDescription = AbstractSfcObsDecoder.getInt(element, 4, + 5); } } } diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/regional/Sec5Block72Decoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/regional/Sec5Block72Decoder.java index c4444e625e..4dd6fe94b8 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/regional/Sec5Block72Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/regional/Sec5Block72Decoder.java @@ -47,6 +47,7 @@ import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; * 20071010 391 jkorman Initial coding. * Sep 18, 2014 #3627 mapeters Convert units using {@link UnitConverter}. * Sep 26, 2014 #3629 mapeters Replaced static imports. + * Sep 30, 2014 #3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} calls. * * * @@ -98,7 +99,7 @@ public class Sec5Block72Decoder extends SynopticSec5Decoder { // nothing to do. return; } - if (reportParser.positionTo(ISynoptic.SEC_5_LEAD)) { + if (reportParser.positionTo(ISynoptic.SEC_5_LEAD_STRING)) { String element = null; while (true) { @@ -111,8 +112,8 @@ public class Sec5Block72Decoder extends SynopticSec5Decoder { break; } if (isBlock72Data) { - if (AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_5_72_CTEMP)) { + if (ISynoptic.SEC_5_72_CTEMP.matcher(element) + .find()) { // City temperature. Double val = decodeFahrenheit(element.substring(1, 4)); if (val != null) { @@ -120,8 +121,8 @@ public class Sec5Block72Decoder extends SynopticSec5Decoder { cityTemperature.setDataValue(val); cityTemperature.setDataPeriod(0); } - } else if (AbstractSfcObsDecoder.matchElement(element, - ISynoptic.SEC_5_72_CMAXMIN)) { + } else if (ISynoptic.SEC_5_72_CMAXMIN.matcher( + element).find()) { // City maximum/minimum temperature. Double val = decodeFahrenheit(element.substring(0, 3)); if (val != null) { diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/regional/Sec5MaritimeDecoder.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/regional/Sec5MaritimeDecoder.java index e48cecace3..644b6761b1 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/regional/Sec5MaritimeDecoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/src/com/raytheon/edex/plugin/sfcobs/decoder/synoptic/regional/Sec5MaritimeDecoder.java @@ -19,20 +19,19 @@ **/ package com.raytheon.edex.plugin.sfcobs.decoder.synoptic.regional; -import static com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder.getInt; -import static com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder.matchElement; -import static com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic.SEC_5_LEAD; - import java.util.Arrays; import java.util.Calendar; +import java.util.regex.Pattern; import javax.measure.converter.UnitConverter; import javax.measure.unit.NonSI; import javax.measure.unit.SI; import com.raytheon.edex.exception.DecoderException; +import com.raytheon.edex.plugin.sfcobs.decoder.AbstractSfcObsDecoder; import com.raytheon.edex.plugin.sfcobs.decoder.ReportParser; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.AbstractSynopticDecoder; +import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.ISynoptic; import com.raytheon.edex.plugin.sfcobs.decoder.synoptic.SynopticSec5Decoder; import com.raytheon.uf.common.dataplugin.sfcobs.InterWinds; import com.raytheon.uf.common.dataplugin.sfcobs.ObsCommon; @@ -56,7 +55,9 @@ import com.raytheon.uf.edex.decodertools.time.TimeTools; * ------------ ---------- ----------- -------------------------- * 20071010 391 jkorman Initial coding. * Sep 18, 2014 #3627 mapeters Convert units using {@link UnitConverter}, - * updated deprecated {@link TimeTools} usage. + * updated deprecated {@link TimeTools} usage.\ + * Sep 30, 2014 #3629 mapeters Replaced {@link AbstractSfcObsDecoder#matchElement()} + * calls, added Pattern constants. * * * @@ -64,6 +65,25 @@ import com.raytheon.uf.edex.decodertools.time.TimeTools; * @version 1.0 */ public class Sec5MaritimeDecoder extends SynopticSec5Decoder { + + private static final Pattern WIND_SPEED_10_M = Pattern + .compile("11[/0-9]{3}"); + + private static final Pattern WIND_SPEED_20_M = Pattern + .compile("22[/0-9]{3}"); + + private static final Pattern PEAK_WIND_3 = Pattern.compile("3[/0-9]{4}"); + + private static final Pattern CMAN_PEAK_WIND_4 = Pattern.compile("4[/0-9]{5}"); + + private static final Pattern PEAK_WIND_4 = Pattern.compile("4[/0-9]{4}"); + + private static final Pattern CONT_WIND_SPEED = Pattern.compile("6[/0-9]{4}"); + + private static final Pattern CONT_WIND_SPEED_INTERNAL = Pattern + .compile("[/0-9]{6}"); + + private static final Pattern TIDE = Pattern.compile("TIDE[/0-9]{4}"); private static final UnitConverter knotsToMSec = NonSI.KNOT .getConverterTo(SI.METERS_PER_SECOND); @@ -118,7 +138,7 @@ public class Sec5MaritimeDecoder extends SynopticSec5Decoder { // nothing to do. return; } - if (reportParser.positionTo(SEC_5_LEAD)) { + if (reportParser.positionTo(ISynoptic.SEC_5_LEAD_STRING)) { String element = null; while (true) { @@ -130,51 +150,59 @@ public class Sec5MaritimeDecoder extends SynopticSec5Decoder { } else { break; } - if (doGroup(1) && matchElement(element, "11[/0-9]{3}")) { + if (doGroup(1) && WIND_SPEED_10_M.matcher(element).find()) { // extrapolated 10 meter wind speed - Integer temp = getInt(element, 2, 5); + Integer temp = AbstractSfcObsDecoder.getInt(element, 2, 5); if ((temp != null) && (temp >= 0)) { wind10mSpeed = temp.doubleValue() / 10.0; } closeGroup(1); - } else if (doGroup(2) && matchElement(element, "22[/0-9]{3}")) { + } else if (doGroup(2) + && WIND_SPEED_20_M.matcher(element).find()) { // extrapolated 20 meter wind speed - Integer temp = getInt(element, 2, 5); + Integer temp = AbstractSfcObsDecoder.getInt(element, 2, 5); if ((temp != null) && (temp >= 0)) { wind20mSpeed = temp.doubleValue() / 10.0; } closeGroup(2); - } else if (doGroup(3) && matchElement(element, "3[/0-9]{4}")) { + } else if (doGroup(3) && PEAK_WIND_3.matcher(element).find()) { // peak wind data time - pkWindTimeHour = getInt(element, 1, 3); - pkWindTimeMinute = getInt(element, 3, 5); + pkWindTimeHour = AbstractSfcObsDecoder + .getInt(element, 1, 3); + pkWindTimeMinute = AbstractSfcObsDecoder.getInt(element, 3, + 5); closeGroup(3); - } else if (doGroup(4) && matchElement(element, "4[/0-9]{5}")) { + } else if (doGroup(4) + && CMAN_PEAK_WIND_4.matcher(element).find()) { // peak wind data time from CMAN - pkWindDirection = getInt(element, 1, 3); + pkWindDirection = AbstractSfcObsDecoder.getInt(element, 1, + 3); if ((pkWindDirection != null) && (pkWindDirection >= 0)) { pkWindDirection *= 10; } - Integer spd = getInt(element, 3, 6); + Integer spd = AbstractSfcObsDecoder.getInt(element, 3, 6); if ((spd != null) && (spd >= 0)) { pkWindSpeed = spd.doubleValue(); } closeGroup(4); - } else if (doGroup(4) && matchElement(element, "4[/0-9]{4}")) { + } else if (doGroup(4) && PEAK_WIND_4.matcher(element).find()) { // peak wind data time - pkWindDirection = getInt(element, 1, 3); + pkWindDirection = AbstractSfcObsDecoder.getInt(element, 1, + 3); if ((pkWindDirection != null) && (pkWindDirection >= 0)) { pkWindDirection *= 10; } - Integer spd = getInt(element, 3, 5); + Integer spd = AbstractSfcObsDecoder.getInt(element, 3, 5); if ((spd != null) && (spd >= 0)) { pkWindSpeed = spd.doubleValue(); } closeGroup(4); - } else if (doGroup(6) && matchElement(element, "6[/0-9]{4}")) { + } else if (doGroup(6) + && CONT_WIND_SPEED.matcher(element).find()) { // Continuous wind speed data - windTimeHour = getInt(element, 1, 3); - windTimeMinute = getInt(element, 3, 5); + windTimeHour = AbstractSfcObsDecoder.getInt(element, 1, 3); + windTimeMinute = AbstractSfcObsDecoder + .getInt(element, 3, 5); windSpeeds = new Double[NUM_WINDS]; Arrays.fill(windSpeeds, new Double(-9999.0)); @@ -189,9 +217,11 @@ public class Sec5MaritimeDecoder extends SynopticSec5Decoder { } else { break; } - if (matchElement(element, "[/0-9]{6}")) { - Integer wd = getInt(element, 0, 3); - Integer ws = getInt(element, 3, 6); + if (CONT_WIND_SPEED_INTERNAL.matcher(element).find()) { + Integer wd = AbstractSfcObsDecoder.getInt(element, + 0, 3); + Integer ws = AbstractSfcObsDecoder.getInt(element, + 3, 6); if ((wd != null) && (wd >= 0)) { windDirs[i] = wd; } @@ -201,7 +231,7 @@ public class Sec5MaritimeDecoder extends SynopticSec5Decoder { } } closeGroup(6); - } else if (matchElement(element, "TIDE[/0-9]{4}")) { + } else if (TIDE.matcher(element).find()) { // Tidal data in feet. } diff --git a/edexOsgi/com.raytheon.edex.plugin.sfcobs/unittest/com/raytheon/edex/plugin/sfcobs/decoder/TestSfcObsDecoders.java b/edexOsgi/com.raytheon.edex.plugin.sfcobs/unittest/com/raytheon/edex/plugin/sfcobs/decoder/TestSfcObsDecoders.java index c3076d93be..54d7215192 100644 --- a/edexOsgi/com.raytheon.edex.plugin.sfcobs/unittest/com/raytheon/edex/plugin/sfcobs/decoder/TestSfcObsDecoders.java +++ b/edexOsgi/com.raytheon.edex.plugin.sfcobs/unittest/com/raytheon/edex/plugin/sfcobs/decoder/TestSfcObsDecoders.java @@ -180,12 +180,8 @@ public class TestSfcObsDecoders extends TestCase { true,true,true,false,false, }; - - Pattern p = Pattern.compile(ISynoptic.YYGGI_SUB_W); - - for(int i = 0;i < testData.length;i++) { - Matcher m = p.matcher(testData[i]); + Matcher m = ISynoptic.YYGGI_SUB_W.matcher(testData[i]); assertEquals(m.find(),testMatch[i]); } } @@ -202,12 +198,8 @@ public class TestSfcObsDecoders extends TestCase { true,true,true,true, }; - - Pattern p = Pattern.compile(ISynoptic.SEC_1_NDDFF); - - for(int i = 0;i < testData.length;i++) { - Matcher m = p.matcher(testData[i]); + Matcher m = ISynoptic.SEC_1_NDDFF.matcher(testData[i]); assertEquals(m.find(),testMatch[i]); } }