Mercurial > dive4elements > river
changeset 495:a92da0b3e8e7
Importer: make column names in WST files unique by appending (1), (2) and so on in case of collision
flys-backend/trunk@1849 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 08 May 2011 11:07:22 +0000 |
parents | 88d5b02ff0c1 |
children | 4f2d8980415f |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java |
diffstat | 2 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Fri May 06 15:15:04 2011 +0000 +++ b/flys-backend/ChangeLog Sun May 08 11:07:22 2011 +0000 @@ -1,3 +1,9 @@ +2011-05-05 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/importer/WstParser.java: + There are wst files where column names are not unique. + Make them unique by appending (1), (2) and so on. + 2011-05-05 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/importer/ImportRiver.java:
--- a/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java Fri May 06 15:15:04 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java Sun May 08 11:07:22 2011 +0000 @@ -208,6 +208,8 @@ if (firstAbfluesse != null) { if (!columnHeaderChecked) { int unknownCount = 0; + HashSet<String> uniqueColumnNames = + new HashSet<String>(); for (int i = 0; i < lsBezeichner.length; ++i) { if (lsBezeichner[i] == null || lsBezeichner[i].length() == 0) { @@ -221,7 +223,14 @@ lsBezeichner[i] = "Q="+format(q); } } - wst.getColumn(i).setName(lsBezeichner[i]); + String candidate = lsBezeichner[i]; + int collision = 1; + while (!uniqueColumnNames.add(candidate)) { + candidate = lsBezeichner[i] + + " (" + collision + ")"; + ++collision; + } + wst.getColumn(i).setName(candidate); } columnHeaderChecked = true; }