Let's use unique field names

This commit is contained in:
rusefillc 2024-05-27 11:08:25 -04:00
parent 2698a8fb30
commit bd90ce8019
1 changed files with 11 additions and 2 deletions

View File

@ -35,6 +35,7 @@ public class DbcFile {
DbcPacket currentPacket = null; DbcPacket currentPacket = null;
String line; String line;
int lineIndex = -1; int lineIndex = -1;
Set<String> fieldNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
lineIndex++; lineIndex++;
line = line.trim(); line = line.trim();
@ -72,11 +73,19 @@ public class DbcFile {
} else if (line.startsWith("SG_")) { } else if (line.startsWith("SG_")) {
DbcField field = DbcField.parseField(currentPacket, line); DbcField field;
try {
field = DbcField.parseField(currentPacket, line);
} catch (Throwable e) {
throw new IllegalStateException("During [" + line + "]", e);
}
if (debugEnabled) if (debugEnabled)
System.out.println("Found " + field); System.out.println("Found " + field);
if (field != null) if (field != null) {
if (!fieldNames.add(field.getName()))
throw new IllegalArgumentException("Let's use unique field names: " + field.getName());
currentPacket.add(field); currentPacket.add(field);
}
} else { } else {
// skipping useless line // skipping useless line