From 84d331a57e7ed8e4d3e002f7bf3baea7f8b0a3cf Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 18 Apr 2014 18:38:16 +0200 Subject: [PATCH] Replaced GeoRSSUtils#trimWhitespace by Strings#trimToEmpty --- .../feed/module/georss/GMLParser.java | 17 ++++-------- .../feed/module/georss/GeoRSSUtils.java | 27 ------------------- .../feed/module/georss/SimpleParser.java | 11 +++----- 3 files changed, 9 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/rometools/feed/module/georss/GMLParser.java b/src/main/java/org/rometools/feed/module/georss/GMLParser.java index 97581be..d51d0b1 100644 --- a/src/main/java/org/rometools/feed/module/georss/GMLParser.java +++ b/src/main/java/org/rometools/feed/module/georss/GMLParser.java @@ -29,6 +29,7 @@ import org.rometools.feed.module.georss.geometries.Polygon; import org.rometools.feed.module.georss.geometries.Position; import org.rometools.feed.module.georss.geometries.PositionList; +import com.rometools.utils.Strings; import com.sun.syndication.feed.module.Module; import com.sun.syndication.io.ModuleParser; @@ -41,19 +42,11 @@ import com.sun.syndication.io.ModuleParser; */ public class GMLParser implements ModuleParser { - /* - * (non-Javadoc) - * @see com.sun.syndication.io.ModuleParser#getNamespaceUri() - */ @Override public String getNamespaceUri() { return GeoRSSModule.GEORSS_GEORSS_URI; } - /* - * (non-Javadoc) - * @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element) - */ @Override public Module parse(final Element element, final Locale locale) { final Module geoRssModule = parseGML(element); @@ -62,7 +55,7 @@ public class GMLParser implements ModuleParser { private static PositionList parsePosList(final Element element) { final String coordinates = element.getText(); - final String[] coord = GeoRSSUtils.trimWhitespace(coordinates).split(" "); + final String[] coord = Strings.trimToEmpty(coordinates).split(" "); final PositionList posList = new PositionList(); for (int i = 0; i < coord.length; i += 2) { posList.add(Double.parseDouble(coord[i]), Double.parseDouble(coord[i + 1])); @@ -82,7 +75,7 @@ public class GMLParser implements ModuleParser { if (posElement != null) { geoRSSModule = new GMLModuleImpl(); final String coordinates = posElement.getText(); - final String[] coord = GeoRSSUtils.trimWhitespace(coordinates).split(" "); + final String[] coord = Strings.trimToEmpty(coordinates).split(" "); final Position pos = new Position(Double.parseDouble(coord[0]), Double.parseDouble(coord[1])); geoRSSModule.setGeometry(new Point(pos)); } @@ -140,9 +133,9 @@ public class GMLParser implements ModuleParser { if (lowerElement != null && upperElement != null) { geoRSSModule = new GMLModuleImpl(); final String lowerCoordinates = lowerElement.getText(); - final String[] lowerCoord = GeoRSSUtils.trimWhitespace(lowerCoordinates).split(" "); + final String[] lowerCoord = Strings.trimToEmpty(lowerCoordinates).split(" "); final String upperCoordinates = upperElement.getText(); - final String[] upperCoord = GeoRSSUtils.trimWhitespace(upperCoordinates).split(" "); + final String[] upperCoord = Strings.trimToEmpty(upperCoordinates).split(" "); final Envelope envelope = new Envelope(Double.parseDouble(lowerCoord[0]), Double.parseDouble(lowerCoord[1]), Double.parseDouble(upperCoord[0]), Double.parseDouble(upperCoord[1])); geoRSSModule.setGeometry(envelope); diff --git a/src/main/java/org/rometools/feed/module/georss/GeoRSSUtils.java b/src/main/java/org/rometools/feed/module/georss/GeoRSSUtils.java index 22f57e3..c4ed256 100644 --- a/src/main/java/org/rometools/feed/module/georss/GeoRSSUtils.java +++ b/src/main/java/org/rometools/feed/module/georss/GeoRSSUtils.java @@ -28,33 +28,6 @@ import com.sun.syndication.feed.synd.SyndFeed; */ public class GeoRSSUtils { - static String trimWhitespace(final String in) { - if (in == null) { - return ""; - } - final StringBuffer strbuf = new StringBuffer(); - int i = 0; - for (; i < in.length() && Character.isWhitespace(in.charAt(i)); ++i) { - ; - } - - boolean wasWhite = false; - for (; i < in.length(); ++i) { - final char ch = in.charAt(i); - if (Character.isWhitespace(ch)) { - wasWhite = true; - } else { - if (wasWhite) { - strbuf.append(' '); - } - strbuf.append(ch); - wasWhite = false; - } - - } - return strbuf.toString(); - } - /** * This convenience method checks whether there is any geoRss Element and will return it (georss simple or W3GGeo). * diff --git a/src/main/java/org/rometools/feed/module/georss/SimpleParser.java b/src/main/java/org/rometools/feed/module/georss/SimpleParser.java index 5150f78..eb40460 100644 --- a/src/main/java/org/rometools/feed/module/georss/SimpleParser.java +++ b/src/main/java/org/rometools/feed/module/georss/SimpleParser.java @@ -27,6 +27,7 @@ import org.rometools.feed.module.georss.geometries.Polygon; import org.rometools.feed.module.georss.geometries.Position; import org.rometools.feed.module.georss.geometries.PositionList; +import com.rometools.utils.Strings; import com.sun.syndication.feed.module.Module; import com.sun.syndication.io.ModuleParser; @@ -50,7 +51,7 @@ public class SimpleParser implements ModuleParser { private static PositionList parsePosList(final Element element) { final String coordinates = element.getText(); - final String[] coord = GeoRSSUtils.trimWhitespace(coordinates).split(" "); + final String[] coord = Strings.trimToEmpty(coordinates).split(" "); final PositionList posList = new PositionList(); for (int i = 0; i < coord.length; i += 2) { posList.add(Double.parseDouble(coord[i]), Double.parseDouble(coord[i + 1])); @@ -58,10 +59,6 @@ public class SimpleParser implements ModuleParser { return posList; } - /* - * (non-Javadoc) - * @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element) - */ @Override public Module parse(final Element element, final Locale locale) { final Module geoRssModule = parseSimple(element); @@ -78,7 +75,7 @@ public class SimpleParser implements ModuleParser { final Element whereElement = element.getChild("where", GeoRSSModule.SIMPLE_NS); if (pointElement != null) { geoRSSModule = new SimpleModuleImpl(); - final String coordinates = GeoRSSUtils.trimWhitespace(pointElement.getText()); + final String coordinates = Strings.trimToEmpty(pointElement.getText()); if (!"".equals(coordinates)) { final String[] coord = coordinates.split(" "); final Position pos = new Position(Double.parseDouble(coord[0]), Double.parseDouble(coord[1])); @@ -97,7 +94,7 @@ public class SimpleParser implements ModuleParser { } else if (boxElement != null) { geoRSSModule = new SimpleModuleImpl(); final String coordinates = boxElement.getText(); - final String[] coord = GeoRSSUtils.trimWhitespace(coordinates).split(" "); + final String[] coord = Strings.trimToEmpty(coordinates).split(" "); final Envelope envelope = new Envelope(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]), Double.parseDouble(coord[2]), Double.parseDouble(coord[3])); geoRSSModule.setGeometry(envelope);