Cleanup - Map.getOrDefault and Map.computeIfAbsent

This commit is contained in:
Jetz
2024-08-10 12:48:52 -04:00
parent bdc890c32c
commit 4614c6c0c9
16 changed files with 22 additions and 77 deletions

View File

@@ -445,7 +445,7 @@ public class ImportSourceAnalyzer {
analyzeListedDir(root, ForgeConstants.CACHE_ICON_PICS_DIR, new ListedAnalyzer() {
@Override
public String map(final String filename) {
return iconFileNames.containsKey(filename) ? iconFileNames.get(filename) : null;
return iconFileNames.getOrDefault(filename, null);
}
@Override
@@ -617,7 +617,7 @@ public class ImportSourceAnalyzer {
analyzeListedDir(root, targetDir, new ListedAnalyzer() {
@Override
public String map(final String filename) {
return fileDb.containsKey(filename) ? fileDb.get(filename) : null;
return fileDb.getOrDefault(filename, null);
}
@Override

View File

@@ -826,11 +826,7 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel implem
@SuppressWarnings("unchecked")
public void addFilter(final ItemFilter<? extends T> filter) {
final Class<? extends ItemFilter<? extends T>> filterClass = (Class<? extends ItemFilter<? extends T>>) filter.getClass();
List<ItemFilter<? extends T>> classFilters = this.filters.get(filterClass);
if (classFilters == null) {
classFilters = new ArrayList<>();
this.filters.put(filterClass, classFilters);
}
List<ItemFilter<? extends T>> classFilters = this.filters.computeIfAbsent(filterClass, k -> new ArrayList<>());
if (classFilters.size() > 0) {
//if filter with the same class already exists, try to merge if allowed
//NOTE: can always use first filter for these checks since if

View File

@@ -44,7 +44,7 @@ class AsyncSoundRegistry {
}
public synchronized static int getNumIterations(String soundName) {
return soundsPlayed.containsKey(soundName) ? soundsPlayed.get(soundName) : 0;
return soundsPlayed.getOrDefault(soundName, 0);
}
}

View File

@@ -940,11 +940,7 @@ public class FSkin {
/** @return {@link java.awt.font} */
private static Font getFixedFont(final int size) {
Font fixedFont = fixedFonts.get(size);
if (fixedFont == null) {
fixedFont = new Font("Monospaced", Font.PLAIN, size);
fixedFonts.put(size, fixedFont);
}
Font fixedFont = fixedFonts.computeIfAbsent(size, s -> new Font("Monospaced", Font.PLAIN, s));
return fixedFont;
}