# HG changeset patch # User Sascha L. Teichmann # Date 1304852842 0 # Node ID a92da0b3e8e78516f9da6a2c9e5e575b60616594 # Parent 88d5b02ff0c1e28883b425ff8c55ab623282b5c3 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 diff -r 88d5b02ff0c1 -r a92da0b3e8e7 flys-backend/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/importer/ImportRiver.java: diff -r 88d5b02ff0c1 -r a92da0b3e8e7 flys-backend/src/main/java/de/intevation/flys/importer/WstParser.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 uniqueColumnNames = + new HashSet(); 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; }