better error message if there are many duplicate files

This commit is contained in:
hneemann 2018-06-22 21:22:58 +02:00
parent bcb9918811
commit fab441c2af
3 changed files with 11 additions and 1 deletions

View File

@ -692,8 +692,10 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
} }
private static final class PopulateMapVisitor implements Visitor { private static final class PopulateMapVisitor implements Visitor {
private static final int MAX_WARNING_ENTRIES = 15;
private final HashMap<String, LibraryNode> map; private final HashMap<String, LibraryNode> map;
private StringBuilder warningMessage; private StringBuilder warningMessage;
private int warningEntries = 0;
private PopulateMapVisitor(HashMap<String, LibraryNode> map) { private PopulateMapVisitor(HashMap<String, LibraryNode> map) {
this.map = map; this.map = map;
@ -716,13 +718,19 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
libraryNode.setUnique(false); // some of the duplicates point to the same file libraryNode.setUnique(false); // some of the duplicates point to the same file
if (warningMessage == null) if (warningMessage == null)
warningMessage = new StringBuilder(Lang.get("msg_duplicateLibraryFiles")); warningMessage = new StringBuilder(Lang.get("msg_duplicateLibraryFiles"));
warningMessage.append("\n\n").append(presentNode.getFile()).append("\n").append(libraryNode.getFile()); if (warningEntries <= MAX_WARNING_ENTRIES)
warningMessage.append("\n\n").append(presentNode.getFile()).append("\n").append(libraryNode.getFile());
warningEntries++;
} }
} }
} }
} }
private StringBuilder getWarningMessage() { private StringBuilder getWarningMessage() {
if (warningEntries >= MAX_WARNING_ENTRIES) {
warningMessage.append("\n\n").append(Lang.get("msg_and_N_More", warningEntries - MAX_WARNING_ENTRIES));
warningEntries = 0;
}
return warningMessage; return warningMessage;
} }
} }

View File

@ -1440,6 +1440,7 @@ eine &lt;a href=&quot;https://github.com/hneemann/[[name]]/issues/new?labels=enh
</string> </string>
<string name="msg_duplicateLibraryFiles">Es gibt mehrere Dateien mit identischen Dateinamen, welche nicht eindeutig <string name="msg_duplicateLibraryFiles">Es gibt mehrere Dateien mit identischen Dateinamen, welche nicht eindeutig
zugeordnet werden können! Betroffen sind:</string> zugeordnet werden können! Betroffen sind:</string>
<string name="msg_and_N_More">und {0} weitere.</string>
<string name="msg_fileNotImportedYet">Die Datei wurde noch nicht importiert.</string> <string name="msg_fileNotImportedYet">Die Datei wurde noch nicht importiert.</string>
<string name="msg_fileExists">Die Datei {0} existiert schon! Soll die Datei überschrieben werden?</string> <string name="msg_fileExists">Die Datei {0} existiert schon! Soll die Datei überschrieben werden?</string>
<string name="msg_isLocked">Die Bearbeitung der Schaltung ist gesperrt. Sie können die Sperrung unter <string name="msg_isLocked">Die Bearbeitung der Schaltung ist gesperrt. Sie können die Sperrung unter

View File

@ -1427,6 +1427,7 @@
</string> </string>
<string name="msg_duplicateLibraryFiles">There are several files with identical file names, which can not be <string name="msg_duplicateLibraryFiles">There are several files with identical file names, which can not be
uniquely assigned! Affected are:</string> uniquely assigned! Affected are:</string>
<string name="msg_and_N_More">and {0} more.</string>
<string name="msg_fileNotImportedYet">The file has not yet been imported.</string> <string name="msg_fileNotImportedYet">The file has not yet been imported.</string>
<string name="msg_fileExists">The file {0} already exists! Do you want to overwrite the file?</string> <string name="msg_fileExists">The file {0} already exists! Do you want to overwrite the file?</string>
<string name="msg_test_missingLines">(To many entries!)</string> <string name="msg_test_missingLines">(To many entries!)</string>