[Dive4elements-commits] [PATCH 3 of 5] Generalize parsing of ids data string
Wald Commits
scm-commit at wald.intevation.org
Mon Mar 25 15:39:18 CET 2013
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1364220076 -3600
# Node ID e1cd77ddcbc44ff4132a305e5bcee67f245da95b
# Parent 1564ca2cb224f64834500202363ba5871ce0ca69
Generalize parsing of ids data string
diff -r 1564ca2cb224 -r e1cd77ddcbc4 flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java Mon Mar 25 15:00:25 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java Mon Mar 25 15:01:16 2013 +0100
@@ -149,17 +149,16 @@
public int getRiverId() {
if (riverId == 0) {
- String ids = artifact.getDataAsString("ids");
- String[] parts = ids.split(";");
+ String rid = getIdPart(0);
try {
- riverId = Integer.parseInt(parts[0]);
+ riverId = Integer.parseInt(rid);
}
catch (NumberFormatException nfe) {
- logger.error("Cannot parse river id from '" + parts[0] + "'");
+ logger.error("Cannot parse river id from '" +
+ artifact.getDataAsString("ids") + "'");
}
}
-
return riverId;
}
@@ -178,18 +177,33 @@
*/
public String getName() {
if (name == null) {
- String ids = artifact.getDataAsString("ids");
-
- String parts[] = ids != null ? ids.split(";") : null;
-
- if (parts != null && parts.length >= 2) {
- name = parts[1];
- }
+ name = getIdPart(1);
}
return name;
}
+ /**
+ * Returns a part of the ID string. This method splits the
+ * 'ids' data string. It is expected, that the 'ids' string is
+ * seperated by ';'.
+ *
+ * @param number the position of the id data string
+ *
+ * @return the part of the id string at position number.
+ * Null if number was out of bounds.
+ */
+ public String getIdPart(int number) {
+ String ids = artifact.getDataAsString("ids");
+
+ String parts[] = ids != null ? ids.split(";") : null;
+
+ if (parts != null && parts.length >= number + 1) {
+ return parts[number];
+ }
+ return null;
+ }
+
/**
* Returns the name of the layer (returned by getName()) or the layer
More information about the Dive4elements-commits
mailing list