From 8581225da84234737b6585f126aed33ff897a05b Mon Sep 17 00:00:00 2001 From: mezz Date: Wed, 28 Jun 2017 00:14:10 -0700 Subject: [PATCH] Use java 8 collection functions --- .../client/model/ForgeBlockStateV1.java | 11 ++----- .../client/model/ModelLoader.java | 8 +---- .../client/model/MultiLayerModel.java | 15 ++-------- .../common/BiomeDictionary.java | 8 +---- .../common/ForgeModContainer.java | 9 +----- .../capabilities/CapabilityManager.java | 7 +---- .../common/config/ConfigManager.java | 12 ++------ .../common/crafting/CraftingHelper.java | 6 ++-- .../common/util/CompoundDataFixer.java | 8 +---- .../common/util/FakePlayerFactory.java | 10 +------ .../minecraftforge/common/util/ModFixs.java | 8 +---- .../deobf/FMLDeobfuscatingRemapper.java | 7 +---- .../common/event/FMLModIdMappingEvent.java | 6 ++-- .../fml/common/eventhandler/EventBus.java | 7 +---- .../fml/common/registry/EntityRegistry.java | 11 +------ .../minecraftforge/oredict/OreDictionary.java | 7 +---- .../registries/ForgeRegistry.java | 10 +++---- .../minecraftforge/registries/GameData.java | 30 +++++++++---------- .../server/ForgeTimeTracker.java | 7 +---- 19 files changed, 45 insertions(+), 142 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/ForgeBlockStateV1.java b/src/main/java/net/minecraftforge/client/model/ForgeBlockStateV1.java index 22c6ac574..dfde59b2f 100644 --- a/src/main/java/net/minecraftforge/client/model/ForgeBlockStateV1.java +++ b/src/main/java/net/minecraftforge/client/model/ForgeBlockStateV1.java @@ -46,6 +46,7 @@ import net.minecraftforge.common.model.IModelState; import net.minecraftforge.common.model.TRSRTransformation; import net.minecraftforge.fml.common.FMLLog; +import java.util.Objects; import java.util.Optional; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableMap; @@ -169,15 +170,7 @@ public class ForgeBlockStateV1 extends Marker } } - Iterator> iter = v.submodels.values().iterator(); - - while (iter.hasNext()) - { - List submodel = iter.next(); - - if (submodel == null) - iter.remove(); - } + v.submodels.values().removeIf(Objects::isNull); if (v.textures != null) { diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoader.java b/src/main/java/net/minecraftforge/client/model/ModelLoader.java index e3c9d06f5..05c6e770d 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoader.java @@ -645,13 +645,7 @@ public final class ModelLoader extends ModelBakery //Remove any faces that use a null texture, this is for performance reasons, also allows some cool layering stuff. for (BlockPart part : newModel.getElements()) { - Iterator> itr = part.mapFaces.entrySet().iterator(); - while (itr.hasNext()) - { - Entry entry = itr.next(); - if (removed.contains(entry.getValue().texture)) - itr.remove(); - } + part.mapFaces.entrySet().removeIf(entry -> removed.contains(entry.getValue().texture)); } return new VanillaModelWrapper(location, newModel, uvlock, animation); diff --git a/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java b/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java index 9e61cca77..5d4505977 100644 --- a/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java +++ b/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java @@ -138,14 +138,7 @@ public final class MultiLayerModel implements IModel this.models = models; this.cameraTransforms = cameraTransforms; this.missing = missing; - if(models.containsKey(Optional.empty())) - { - base = models.get(Optional.empty()); - } - else - { - base = missing; - } + base = models.getOrDefault(Optional.empty(), missing); ImmutableMap.Builder, ImmutableList> quadBuilder = ImmutableMap.builder(); quadBuilder.put(Optional.empty(), buildQuads(models, Optional.empty())); for(EnumFacing side: EnumFacing.values()) @@ -174,13 +167,9 @@ public final class MultiLayerModel implements IModel { return quads.get(Optional.ofNullable(side)); } - else if(!models.containsKey(Optional.of(layer))) - { - model = missing; - } else { - model = models.get(Optional.of(layer)); + model = models.getOrDefault(Optional.of(layer), missing); } // assumes that child model will handle this state properly. FIXME? return model.getQuads(state, side, rand); diff --git a/src/main/java/net/minecraftforge/common/BiomeDictionary.java b/src/main/java/net/minecraftforge/common/BiomeDictionary.java index d94a72758..bedcbda83 100644 --- a/src/main/java/net/minecraftforge/common/BiomeDictionary.java +++ b/src/main/java/net/minecraftforge/common/BiomeDictionary.java @@ -360,13 +360,7 @@ public class BiomeDictionary //Internal implementation private static BiomeInfo getBiomeInfo(Biome biome) { - BiomeInfo info = biomeInfoMap.get(biome.getRegistryName()); - if (info == null) - { - info = new BiomeInfo(); - biomeInfoMap.put(biome.getRegistryName(), info); - } - return info; + return biomeInfoMap.computeIfAbsent(biome.getRegistryName(), k -> new BiomeInfo()); } /** diff --git a/src/main/java/net/minecraftforge/common/ForgeModContainer.java b/src/main/java/net/minecraftforge/common/ForgeModContainer.java index c09ca0b8b..c74cfb02c 100644 --- a/src/main/java/net/minecraftforge/common/ForgeModContainer.java +++ b/src/main/java/net/minecraftforge/common/ForgeModContainer.java @@ -401,14 +401,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/'))) all.add(asm.getClassName()); - Iterator itr = all.iterator(); - while (itr.hasNext()) - { - String cls = itr.next(); - if (!cls.startsWith("net/minecraft/") && - !cls.startsWith("net/minecraftforge/")) - itr.remove(); - } + all.removeIf(cls -> !cls.startsWith("net/minecraft/") && !cls.startsWith("net/minecraftforge/")); log.debug("Preloading CrashReport Classes"); Collections.sort(all); //Sort it because I like pretty output ;) diff --git a/src/main/java/net/minecraftforge/common/capabilities/CapabilityManager.java b/src/main/java/net/minecraftforge/common/capabilities/CapabilityManager.java index 113d499b3..9218b871c 100644 --- a/src/main/java/net/minecraftforge/common/capabilities/CapabilityManager.java +++ b/src/main/java/net/minecraftforge/common/capabilities/CapabilityManager.java @@ -114,12 +114,7 @@ public enum CapabilityManager } final String capabilityName = type.getInternalName().replace('/', '.').intern(); - List, Object>> list = callbacks.get(capabilityName); - if (list == null) - { - list = Lists.newArrayList(); - callbacks.put(capabilityName, list); - } + List, Object>> list = callbacks.computeIfAbsent(capabilityName, k -> Lists.newArrayList()); if (entry.getObjectName().indexOf('(') > 0) { diff --git a/src/main/java/net/minecraftforge/common/config/ConfigManager.java b/src/main/java/net/minecraftforge/common/config/ConfigManager.java index c43f460d6..96001f831 100644 --- a/src/main/java/net/minecraftforge/common/config/ConfigManager.java +++ b/src/main/java/net/minecraftforge/common/config/ConfigManager.java @@ -108,12 +108,7 @@ public class ConfigManager for (ASMData target : data.getAll(Config.class.getName())) { String modid = (String)target.getAnnotationInfo().get("modid"); - Multimap map = asm_data.get(modid); - if (map == null) - { - map = ArrayListMultimap.create(); - asm_data.put(modid, map); - } + Multimap map = asm_data.computeIfAbsent(modid, k -> ArrayListMultimap.create()); EnumHolder tholder = (EnumHolder)target.getAnnotationInfo().get("type"); Config.Type type = tholder == null ? Config.Type.INSTANCE : Config.Type.valueOf(tholder.getValue()); @@ -164,9 +159,8 @@ public class ConfigManager { Class cls = Class.forName(targ.getClassName(), true, mcl); - if (MOD_CONFIG_CLASSES.get(modid) == null) - MOD_CONFIG_CLASSES.put(modid, Sets.>newHashSet()); - MOD_CONFIG_CLASSES.get(modid).add(cls); + Set> modConfigClasses = MOD_CONFIG_CLASSES.computeIfAbsent(modid, k -> Sets.>newHashSet()); + modConfigClasses.add(cls); String name = (String)targ.getAnnotationInfo().get("name"); if (name == null) diff --git a/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java b/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java index 4439617f7..8868a28f9 100644 --- a/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java +++ b/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java @@ -435,7 +435,7 @@ public class CraftingHelper { throw new JsonSyntaxException("Or condition values must be an array of JsonObjects"); children.add(CraftingHelper.getCondition(j.getAsJsonObject(), context)); } - return () -> children.stream().anyMatch(c -> c.getAsBoolean()); + return () -> children.stream().anyMatch(BooleanSupplier::getAsBoolean); }); registerC("forge:and", (context, json) -> { JsonArray values = JsonUtils.getJsonArray(json, "values"); @@ -610,8 +610,8 @@ public class CraftingHelper { GameData.revert(RegistryManager.FROZEN, GameData.RECIPES, false); //ModContainer old = Loader.instance().activeModContainer(); Loader.instance().setActiveModContainer(null); - Loader.instance().getActiveModList().forEach((mod) -> loadFactories(mod)); - Loader.instance().getActiveModList().forEach((mod) -> loadRecipes(mod)); + Loader.instance().getActiveModList().forEach(CraftingHelper::loadFactories); + Loader.instance().getActiveModList().forEach(CraftingHelper::loadRecipes); Loader.instance().setActiveModContainer(null); //reg.freeze(); FMLCommonHandler.instance().resetClientRecipeBook(); diff --git a/src/main/java/net/minecraftforge/common/util/CompoundDataFixer.java b/src/main/java/net/minecraftforge/common/util/CompoundDataFixer.java index 6d86eb242..293165bcf 100644 --- a/src/main/java/net/minecraftforge/common/util/CompoundDataFixer.java +++ b/src/main/java/net/minecraftforge/common/util/CompoundDataFixer.java @@ -108,13 +108,7 @@ public class CompoundDataFixer extends DataFixer private List getWalkers(IFixType type) { - List ret = walkers.get(type); - if (ret == null) - { - ret = Lists.newArrayList(); - walkers.put(type, ret); - } - return ret; + return walkers.computeIfAbsent(type, k -> Lists.newArrayList()); } @Override diff --git a/src/main/java/net/minecraftforge/common/util/FakePlayerFactory.java b/src/main/java/net/minecraftforge/common/util/FakePlayerFactory.java index 45a9ac604..c3e789773 100644 --- a/src/main/java/net/minecraftforge/common/util/FakePlayerFactory.java +++ b/src/main/java/net/minecraftforge/common/util/FakePlayerFactory.java @@ -67,14 +67,6 @@ public class FakePlayerFactory public static void unloadWorld(WorldServer world) { - Iterator> itr = fakePlayers.entrySet().iterator(); - while (itr.hasNext()) - { - Entry entry = itr.next(); - if (entry.getValue().world == world) - { - itr.remove(); - } - } + fakePlayers.entrySet().removeIf(entry -> entry.getValue().world == world); } } diff --git a/src/main/java/net/minecraftforge/common/util/ModFixs.java b/src/main/java/net/minecraftforge/common/util/ModFixs.java index 2dc01f210..2514089d3 100644 --- a/src/main/java/net/minecraftforge/common/util/ModFixs.java +++ b/src/main/java/net/minecraftforge/common/util/ModFixs.java @@ -45,13 +45,7 @@ public class ModFixs public List getFixes(IFixType type) { - List ret = this.fixes.get(type); - if (ret == null) - { - ret = Lists.newArrayList(); - this.fixes.put(type, ret); - } - return ret; + return this.fixes.computeIfAbsent(type, k -> Lists.newArrayList()); } public void registerFix(IFixType type, IFixableData fixer) diff --git a/src/main/java/net/minecraftforge/fml/common/asm/transformers/deobf/FMLDeobfuscatingRemapper.java b/src/main/java/net/minecraftforge/fml/common/asm/transformers/deobf/FMLDeobfuscatingRemapper.java index e4c775e67..8b3205412 100644 --- a/src/main/java/net/minecraftforge/fml/common/asm/transformers/deobf/FMLDeobfuscatingRemapper.java +++ b/src/main/java/net/minecraftforge/fml/common/asm/transformers/deobf/FMLDeobfuscatingRemapper.java @@ -494,12 +494,7 @@ public class FMLDeobfuscatingRemapper extends Remapper { { return fType; } - Map newClassMap = fieldDescriptions.get(newType); - if (newClassMap == null) - { - newClassMap = Maps.newHashMap(); - fieldDescriptions.put(newType, newClassMap); - } + Map newClassMap = fieldDescriptions.computeIfAbsent(newType, k -> Maps.newHashMap()); newClassMap.put(newName, fType); return fType; } diff --git a/src/main/java/net/minecraftforge/fml/common/event/FMLModIdMappingEvent.java b/src/main/java/net/minecraftforge/fml/common/event/FMLModIdMappingEvent.java index 0477dc9b3..d08c54816 100644 --- a/src/main/java/net/minecraftforge/fml/common/event/FMLModIdMappingEvent.java +++ b/src/main/java/net/minecraftforge/fml/common/event/FMLModIdMappingEvent.java @@ -19,7 +19,7 @@ package net.minecraftforge.fml.common.event; -import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Map; import com.google.common.collect.ImmutableList; @@ -71,8 +71,8 @@ public class FMLModIdMappingEvent extends FMLEvent remaps.forEach((name, rm) -> { List tmp = Lists.newArrayList(); - rm.entrySet().forEach(e -> tmp.add(new ModRemapping(name, e.getKey(), e.getValue()[0], e.getValue()[1]))); - Collections.sort(tmp, (o1, o2) -> (o1.newId < o2.newId) ? -1 : ((o1.newId == o2.newId) ? 0 : 1)); + rm.forEach((key, value) -> tmp.add(new ModRemapping(name, key, value[0], value[1]))); + tmp.sort(Comparator.comparingInt(o -> o.newId)); this.remaps.put(name, ImmutableList.copyOf(tmp)); }); this.keys = ImmutableSet.copyOf(this.remaps.keySet()); diff --git a/src/main/java/net/minecraftforge/fml/common/eventhandler/EventBus.java b/src/main/java/net/minecraftforge/fml/common/eventhandler/EventBus.java index 5305f5f22..2a8aaf986 100644 --- a/src/main/java/net/minecraftforge/fml/common/eventhandler/EventBus.java +++ b/src/main/java/net/minecraftforge/fml/common/eventhandler/EventBus.java @@ -150,12 +150,7 @@ public class EventBus implements IEventExceptionHandler event.getListenerList().register(busID, asm.getPriority(), listener); - ArrayList others = listeners.get(target); - if (others == null) - { - others = new ArrayList(); - listeners.put(target, others); - } + ArrayList others = listeners.computeIfAbsent(target, k -> new ArrayList<>()); others.add(listener); } catch (Exception e) diff --git a/src/main/java/net/minecraftforge/fml/common/registry/EntityRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/EntityRegistry.java index a8e8aeba5..77abd68f1 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/EntityRegistry.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/EntityRegistry.java @@ -284,16 +284,7 @@ public class EntityRegistry { for (Biome biome : biomes) { - Iterator spawns = biome.getSpawnableList(typeOfCreature).iterator(); - - while (spawns.hasNext()) - { - SpawnListEntry entry = spawns.next(); - if (entry.entityClass == entityClass) - { - spawns.remove(); - } - } + biome.getSpawnableList(typeOfCreature).removeIf(entry -> entry.entityClass == entityClass); } } diff --git a/src/main/java/net/minecraftforge/oredict/OreDictionary.java b/src/main/java/net/minecraftforge/oredict/OreDictionary.java index 885cec713..5718078d5 100644 --- a/src/main/java/net/minecraftforge/oredict/OreDictionary.java +++ b/src/main/java/net/minecraftforge/oredict/OreDictionary.java @@ -709,12 +709,7 @@ public class OreDictionary { hash |= ((ore.getItemDamage() + 1) << 16); // +1 so meta 0 is significant } - List ids = stackToId.get(hash); - if (ids == null) - { - ids = Lists.newArrayList(); - stackToId.put(hash, ids); - } + List ids = stackToId.computeIfAbsent(hash, k -> Lists.newArrayList()); ids.add(id); //System.out.println(id + " " + getOreName(id) + " " + Integer.toHexString(hash) + " " + ore); } diff --git a/src/main/java/net/minecraftforge/registries/ForgeRegistry.java b/src/main/java/net/minecraftforge/registries/ForgeRegistry.java index 3718ad113..1cfc2a8a1 100644 --- a/src/main/java/net/minecraftforge/registries/ForgeRegistry.java +++ b/src/main/java/net/minecraftforge/registries/ForgeRegistry.java @@ -469,7 +469,7 @@ public class ForgeRegistry> implements IForgeRe this.min = from.min; */ this.aliases.clear(); - from.aliases.forEach((f, t) -> this.addAlias(f, t)); + from.aliases.forEach(this::addAlias); this.ids.clear(); this.names.clear(); @@ -517,7 +517,7 @@ public class ForgeRegistry> implements IForgeRe //Needs to be below add so that dummies are persisted this.dummies.clear(); - from.dummies.forEach(dummy -> this.addDummy(dummy)); + from.dummies.forEach(this::addDummy); if (errored) throw new RuntimeException("One of more entry values did not copy to the correct id. Check log for details!"); @@ -718,9 +718,9 @@ public class ForgeRegistry> implements IForgeRe { Snapshot ret = new Snapshot(); this.ids.forEach((id, value) -> ret.ids.put(getKey(value), id)); - this.aliases.forEach((from, to) -> ret.aliases.put(from, to)); - this.blocked.forEach(id -> ret.blocked.add(id)); - this.dummies.forEach(name -> ret.dummied.add(name)); + ret.aliases.putAll(this.aliases); + ret.blocked.addAll(this.blocked); + ret.dummied.addAll(this.dummies); ret.overrides.putAll(getOverrideOwners()); return ret; } diff --git a/src/main/java/net/minecraftforge/registries/GameData.java b/src/main/java/net/minecraftforge/registries/GameData.java index 77d6d4257..9865ad00e 100644 --- a/src/main/java/net/minecraftforge/registries/GameData.java +++ b/src/main/java/net/minecraftforge/registries/GameData.java @@ -469,20 +469,20 @@ public class GameData final Map> remaps = Maps.newHashMap(); final LinkedHashMap> missing = Maps.newLinkedHashMap(); // Load the snapshot into the "STAGING" registry - snapshot.entrySet().forEach(e -> + snapshot.forEach((key, value) -> { - final Class clazz = RegistryManager.ACTIVE.getSuperType(e.getKey()); - remaps.put(e.getKey(), Maps.newLinkedHashMap()); - missing.put(e.getKey(), Maps.newHashMap()); - loadPersistentDataToStagingRegistry(RegistryManager.ACTIVE, STAGING, remaps.get(e.getKey()), missing.get(e.getKey()), e.getKey(), e.getValue(), clazz); + final Class clazz = RegistryManager.ACTIVE.getSuperType(key); + remaps.put(key, Maps.newLinkedHashMap()); + missing.put(key, Maps.newHashMap()); + loadPersistentDataToStagingRegistry(RegistryManager.ACTIVE, STAGING, remaps.get(key), missing.get(key), key, value, clazz); }); - snapshot.entrySet().forEach(e -> + snapshot.forEach((key, value) -> { - snapshot.get(e.getKey()).dummied.forEach(dummy -> + value.dummied.forEach(dummy -> { - Map m = missing.get(e.getKey()); - ForgeRegistry reg = STAGING.getRegistry(e.getKey()); + Map m = missing.get(key); + ForgeRegistry reg = STAGING.getRegistry(key); // Currently missing locally, we just inject and carry on if (m.containsKey(dummy)) @@ -493,20 +493,20 @@ public class GameData else if (isLocalWorld) { if (ForgeRegistry.DEBUG) - FMLLog.log.debug("Registry {}: Resuscitating dummy entry {}", e.getKey(), dummy); + FMLLog.log.debug("Registry {}: Resuscitating dummy entry {}", key, dummy); } else { // The server believes this is a dummy block identity, but we seem to have one locally. This is likely a conflict // in mod setup - Mark this entry as a dummy int id = reg.getID(dummy); - FMLLog.log.warn("Registry {}: The ID {} is currently locally mapped - it will be replaced with a dummy for this session", e.getKey(), id); + FMLLog.log.warn("Registry {}: The ID {} is currently locally mapped - it will be replaced with a dummy for this session", key, id); reg.markDummy(dummy, id); } }); }); - int count = missing.values().stream().mapToInt(e -> e.size()).sum(); + int count = missing.values().stream().mapToInt(Map::size).sum(); if (count > 0) { FMLLog.log.debug("There are {} mappings missing - attempting a mod remap", count); @@ -635,10 +635,10 @@ public class GameData if (active == null) return; // We've already asked the user if they wish to continue. So if the reg isnt found just assume the user knows and accepted it. ForgeRegistry _new = to.getRegistry(name, RegistryManager.ACTIVE); - snap.aliases.forEach((f, t) -> _new.addAlias(f, t)); - snap.blocked.forEach(id -> _new.block(id)); + snap.aliases.forEach(_new::addAlias); + snap.blocked.forEach(_new::block); // Load current dummies BEFORE the snapshot is loaded so that add() will remove from the list. - snap.dummied.forEach(key -> _new.addDummy(key)); + snap.dummied.forEach(_new::addDummy); _new.loadIds(snap.ids, snap.overrides, missing, remaps, active, name); } diff --git a/src/main/java/net/minecraftforge/server/ForgeTimeTracker.java b/src/main/java/net/minecraftforge/server/ForgeTimeTracker.java index fbc5dff1e..53a7372b0 100644 --- a/src/main/java/net/minecraftforge/server/ForgeTimeTracker.java +++ b/src/main/java/net/minecraftforge/server/ForgeTimeTracker.java @@ -83,12 +83,7 @@ public class ForgeTimeTracker { // race, exit return; } - int[] timings = tileEntityTimings.get(tileEntity); - if (timings == null) - { - timings = new int[101]; - tileEntityTimings.put(tileEntity, timings); - } + int[] timings = tileEntityTimings.computeIfAbsent(tileEntity, k -> new int[101]); int idx = timings[100] = (timings[100] + 1) % 100; timings[idx] = (int) (nanoTime - timing); }