Mercurial > dive4elements > river
changeset 5403:e1cd77ddcbc4
Generalize parsing of ids data string
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 25 Mar 2013 15:01:16 +0100 |
parents | 1564ca2cb224 |
children | 08262e0ce57a |
files | flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java |
diffstat | 1 files changed, 26 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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