Improved thread code

This commit is contained in:
Oleg Agafonov 2023-03-04 21:23:03 +04:00
parent 558eafce38
commit 1b54659c7d

View file

@ -25,6 +25,7 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
@ -288,7 +289,7 @@ public final class ManaSymbols {
// priority: SVG -> GIF
// gif remain for backward compatibility
int[] iconErrors = new int[2]; // 0 - svg, 1 - gif
AtomicIntegerArray iconErrors = new AtomicIntegerArray(2); // 0 - svg, 1 - gif
AtomicBoolean fileErrors = new AtomicBoolean(false);
Map<String, BufferedImage> sizedSymbols = new ConcurrentHashMap<>();
@ -313,7 +314,7 @@ public final class ManaSymbols {
// gif
if (image == null) {
iconErrors[0] += 1; // svg fail
iconErrors.incrementAndGet(0); // svg fail
file = getSymbolFileNameAsGIF(symbol, size);
if (file.exists()) {
@ -325,21 +326,21 @@ public final class ManaSymbols {
if (image != null) {
sizedSymbols.put(symbol, image);
} else {
iconErrors[1] += 1; // gif fail
iconErrors.incrementAndGet(1); // gif fail
fileErrors.set(true);
}
});
// total errors
String errorInfo = "";
if (iconErrors[0] > 0) {
errorInfo += "SVG fails - " + iconErrors[0];
if (iconErrors.get(0) > 0) {
errorInfo += "SVG fails - " + iconErrors.get(0);
}
if (iconErrors[1] > 0) {
if (iconErrors.get(1) > 0) {
if (!errorInfo.isEmpty()) {
errorInfo += ", ";
}
errorInfo += "GIF fails - " + iconErrors[1];
errorInfo += "GIF fails - " + iconErrors.get(1);
}
if (!errorInfo.isEmpty()) {