Use java 8 collection functions

This commit is contained in:
mezz 2017-06-28 00:14:10 -07:00
parent 9675585891
commit 8581225da8
19 changed files with 45 additions and 142 deletions

View File

@ -46,6 +46,7 @@ import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation; import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.common.FMLLog;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -169,15 +170,7 @@ public class ForgeBlockStateV1 extends Marker
} }
} }
Iterator<List<Variant>> iter = v.submodels.values().iterator(); v.submodels.values().removeIf(Objects::isNull);
while (iter.hasNext())
{
List<Variant> submodel = iter.next();
if (submodel == null)
iter.remove();
}
if (v.textures != null) if (v.textures != null)
{ {

View File

@ -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. //Remove any faces that use a null texture, this is for performance reasons, also allows some cool layering stuff.
for (BlockPart part : newModel.getElements()) for (BlockPart part : newModel.getElements())
{ {
Iterator<Entry<EnumFacing, BlockPartFace>> itr = part.mapFaces.entrySet().iterator(); part.mapFaces.entrySet().removeIf(entry -> removed.contains(entry.getValue().texture));
while (itr.hasNext())
{
Entry<EnumFacing, BlockPartFace> entry = itr.next();
if (removed.contains(entry.getValue().texture))
itr.remove();
}
} }
return new VanillaModelWrapper(location, newModel, uvlock, animation); return new VanillaModelWrapper(location, newModel, uvlock, animation);

View File

@ -138,14 +138,7 @@ public final class MultiLayerModel implements IModel
this.models = models; this.models = models;
this.cameraTransforms = cameraTransforms; this.cameraTransforms = cameraTransforms;
this.missing = missing; this.missing = missing;
if(models.containsKey(Optional.empty())) base = models.getOrDefault(Optional.empty(), missing);
{
base = models.get(Optional.empty());
}
else
{
base = missing;
}
ImmutableMap.Builder<Optional<EnumFacing>, ImmutableList<BakedQuad>> quadBuilder = ImmutableMap.builder(); ImmutableMap.Builder<Optional<EnumFacing>, ImmutableList<BakedQuad>> quadBuilder = ImmutableMap.builder();
quadBuilder.put(Optional.empty(), buildQuads(models, Optional.empty())); quadBuilder.put(Optional.empty(), buildQuads(models, Optional.empty()));
for(EnumFacing side: EnumFacing.values()) for(EnumFacing side: EnumFacing.values())
@ -174,13 +167,9 @@ public final class MultiLayerModel implements IModel
{ {
return quads.get(Optional.ofNullable(side)); return quads.get(Optional.ofNullable(side));
} }
else if(!models.containsKey(Optional.of(layer)))
{
model = missing;
}
else else
{ {
model = models.get(Optional.of(layer)); model = models.getOrDefault(Optional.of(layer), missing);
} }
// assumes that child model will handle this state properly. FIXME? // assumes that child model will handle this state properly. FIXME?
return model.getQuads(state, side, rand); return model.getQuads(state, side, rand);

View File

@ -360,13 +360,7 @@ public class BiomeDictionary
//Internal implementation //Internal implementation
private static BiomeInfo getBiomeInfo(Biome biome) private static BiomeInfo getBiomeInfo(Biome biome)
{ {
BiomeInfo info = biomeInfoMap.get(biome.getRegistryName()); return biomeInfoMap.computeIfAbsent(biome.getRegistryName(), k -> new BiomeInfo());
if (info == null)
{
info = new BiomeInfo();
biomeInfoMap.put(biome.getRegistryName(), info);
}
return info;
} }
/** /**

View File

@ -401,14 +401,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/'))) for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/')))
all.add(asm.getClassName()); all.add(asm.getClassName());
Iterator<String> itr = all.iterator(); all.removeIf(cls -> !cls.startsWith("net/minecraft/") && !cls.startsWith("net/minecraftforge/"));
while (itr.hasNext())
{
String cls = itr.next();
if (!cls.startsWith("net/minecraft/") &&
!cls.startsWith("net/minecraftforge/"))
itr.remove();
}
log.debug("Preloading CrashReport Classes"); log.debug("Preloading CrashReport Classes");
Collections.sort(all); //Sort it because I like pretty output ;) Collections.sort(all); //Sort it because I like pretty output ;)

View File

@ -114,12 +114,7 @@ public enum CapabilityManager
} }
final String capabilityName = type.getInternalName().replace('/', '.').intern(); final String capabilityName = type.getInternalName().replace('/', '.').intern();
List<Function<Capability<?>, Object>> list = callbacks.get(capabilityName); List<Function<Capability<?>, Object>> list = callbacks.computeIfAbsent(capabilityName, k -> Lists.newArrayList());
if (list == null)
{
list = Lists.newArrayList();
callbacks.put(capabilityName, list);
}
if (entry.getObjectName().indexOf('(') > 0) if (entry.getObjectName().indexOf('(') > 0)
{ {

View File

@ -108,12 +108,7 @@ public class ConfigManager
for (ASMData target : data.getAll(Config.class.getName())) for (ASMData target : data.getAll(Config.class.getName()))
{ {
String modid = (String)target.getAnnotationInfo().get("modid"); String modid = (String)target.getAnnotationInfo().get("modid");
Multimap<Config.Type, ASMData> map = asm_data.get(modid); Multimap<Config.Type, ASMData> map = asm_data.computeIfAbsent(modid, k -> ArrayListMultimap.create());
if (map == null)
{
map = ArrayListMultimap.create();
asm_data.put(modid, map);
}
EnumHolder tholder = (EnumHolder)target.getAnnotationInfo().get("type"); EnumHolder tholder = (EnumHolder)target.getAnnotationInfo().get("type");
Config.Type type = tholder == null ? Config.Type.INSTANCE : Config.Type.valueOf(tholder.getValue()); 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); Class<?> cls = Class.forName(targ.getClassName(), true, mcl);
if (MOD_CONFIG_CLASSES.get(modid) == null) Set<Class<?>> modConfigClasses = MOD_CONFIG_CLASSES.computeIfAbsent(modid, k -> Sets.<Class<?>>newHashSet());
MOD_CONFIG_CLASSES.put(modid, Sets.<Class<?>>newHashSet()); modConfigClasses.add(cls);
MOD_CONFIG_CLASSES.get(modid).add(cls);
String name = (String)targ.getAnnotationInfo().get("name"); String name = (String)targ.getAnnotationInfo().get("name");
if (name == null) if (name == null)

View File

@ -435,7 +435,7 @@ public class CraftingHelper {
throw new JsonSyntaxException("Or condition values must be an array of JsonObjects"); throw new JsonSyntaxException("Or condition values must be an array of JsonObjects");
children.add(CraftingHelper.getCondition(j.getAsJsonObject(), context)); 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) -> { registerC("forge:and", (context, json) -> {
JsonArray values = JsonUtils.getJsonArray(json, "values"); JsonArray values = JsonUtils.getJsonArray(json, "values");
@ -610,8 +610,8 @@ public class CraftingHelper {
GameData.revert(RegistryManager.FROZEN, GameData.RECIPES, false); GameData.revert(RegistryManager.FROZEN, GameData.RECIPES, false);
//ModContainer old = Loader.instance().activeModContainer(); //ModContainer old = Loader.instance().activeModContainer();
Loader.instance().setActiveModContainer(null); Loader.instance().setActiveModContainer(null);
Loader.instance().getActiveModList().forEach((mod) -> loadFactories(mod)); Loader.instance().getActiveModList().forEach(CraftingHelper::loadFactories);
Loader.instance().getActiveModList().forEach((mod) -> loadRecipes(mod)); Loader.instance().getActiveModList().forEach(CraftingHelper::loadRecipes);
Loader.instance().setActiveModContainer(null); Loader.instance().setActiveModContainer(null);
//reg.freeze(); //reg.freeze();
FMLCommonHandler.instance().resetClientRecipeBook(); FMLCommonHandler.instance().resetClientRecipeBook();

View File

@ -108,13 +108,7 @@ public class CompoundDataFixer extends DataFixer
private List<IDataWalker> getWalkers(IFixType type) private List<IDataWalker> getWalkers(IFixType type)
{ {
List<IDataWalker> ret = walkers.get(type); return walkers.computeIfAbsent(type, k -> Lists.newArrayList());
if (ret == null)
{
ret = Lists.newArrayList();
walkers.put(type, ret);
}
return ret;
} }
@Override @Override

View File

@ -67,14 +67,6 @@ public class FakePlayerFactory
public static void unloadWorld(WorldServer world) public static void unloadWorld(WorldServer world)
{ {
Iterator<Entry<GameProfile, FakePlayer>> itr = fakePlayers.entrySet().iterator(); fakePlayers.entrySet().removeIf(entry -> entry.getValue().world == world);
while (itr.hasNext())
{
Entry<GameProfile, FakePlayer> entry = itr.next();
if (entry.getValue().world == world)
{
itr.remove();
}
}
} }
} }

View File

@ -45,13 +45,7 @@ public class ModFixs
public List<IFixableData> getFixes(IFixType type) public List<IFixableData> getFixes(IFixType type)
{ {
List<IFixableData> ret = this.fixes.get(type); return this.fixes.computeIfAbsent(type, k -> Lists.newArrayList());
if (ret == null)
{
ret = Lists.newArrayList();
this.fixes.put(type, ret);
}
return ret;
} }
public void registerFix(IFixType type, IFixableData fixer) public void registerFix(IFixType type, IFixableData fixer)

View File

@ -494,12 +494,7 @@ public class FMLDeobfuscatingRemapper extends Remapper {
{ {
return fType; return fType;
} }
Map<String,String> newClassMap = fieldDescriptions.get(newType); Map<String, String> newClassMap = fieldDescriptions.computeIfAbsent(newType, k -> Maps.newHashMap());
if (newClassMap == null)
{
newClassMap = Maps.newHashMap();
fieldDescriptions.put(newType, newClassMap);
}
newClassMap.put(newName, fType); newClassMap.put(newName, fType);
return fType; return fType;
} }

View File

@ -19,7 +19,7 @@
package net.minecraftforge.fml.common.event; package net.minecraftforge.fml.common.event;
import java.util.Collections; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -71,8 +71,8 @@ public class FMLModIdMappingEvent extends FMLEvent
remaps.forEach((name, rm) -> remaps.forEach((name, rm) ->
{ {
List<ModRemapping> tmp = Lists.newArrayList(); List<ModRemapping> tmp = Lists.newArrayList();
rm.entrySet().forEach(e -> tmp.add(new ModRemapping(name, e.getKey(), e.getValue()[0], e.getValue()[1]))); rm.forEach((key, value) -> tmp.add(new ModRemapping(name, key, value[0], value[1])));
Collections.sort(tmp, (o1, o2) -> (o1.newId < o2.newId) ? -1 : ((o1.newId == o2.newId) ? 0 : 1)); tmp.sort(Comparator.comparingInt(o -> o.newId));
this.remaps.put(name, ImmutableList.copyOf(tmp)); this.remaps.put(name, ImmutableList.copyOf(tmp));
}); });
this.keys = ImmutableSet.copyOf(this.remaps.keySet()); this.keys = ImmutableSet.copyOf(this.remaps.keySet());

View File

@ -150,12 +150,7 @@ public class EventBus implements IEventExceptionHandler
event.getListenerList().register(busID, asm.getPriority(), listener); event.getListenerList().register(busID, asm.getPriority(), listener);
ArrayList<IEventListener> others = listeners.get(target); ArrayList<IEventListener> others = listeners.computeIfAbsent(target, k -> new ArrayList<>());
if (others == null)
{
others = new ArrayList<IEventListener>();
listeners.put(target, others);
}
others.add(listener); others.add(listener);
} }
catch (Exception e) catch (Exception e)

View File

@ -284,16 +284,7 @@ public class EntityRegistry
{ {
for (Biome biome : biomes) for (Biome biome : biomes)
{ {
Iterator<SpawnListEntry> spawns = biome.getSpawnableList(typeOfCreature).iterator(); biome.getSpawnableList(typeOfCreature).removeIf(entry -> entry.entityClass == entityClass);
while (spawns.hasNext())
{
SpawnListEntry entry = spawns.next();
if (entry.entityClass == entityClass)
{
spawns.remove();
}
}
} }
} }

View File

@ -709,12 +709,7 @@ public class OreDictionary
{ {
hash |= ((ore.getItemDamage() + 1) << 16); // +1 so meta 0 is significant hash |= ((ore.getItemDamage() + 1) << 16); // +1 so meta 0 is significant
} }
List<Integer> ids = stackToId.get(hash); List<Integer> ids = stackToId.computeIfAbsent(hash, k -> Lists.newArrayList());
if (ids == null)
{
ids = Lists.newArrayList();
stackToId.put(hash, ids);
}
ids.add(id); ids.add(id);
//System.out.println(id + " " + getOreName(id) + " " + Integer.toHexString(hash) + " " + ore); //System.out.println(id + " " + getOreName(id) + " " + Integer.toHexString(hash) + " " + ore);
} }

View File

@ -469,7 +469,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
this.min = from.min; this.min = from.min;
*/ */
this.aliases.clear(); this.aliases.clear();
from.aliases.forEach((f, t) -> this.addAlias(f, t)); from.aliases.forEach(this::addAlias);
this.ids.clear(); this.ids.clear();
this.names.clear(); this.names.clear();
@ -517,7 +517,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
//Needs to be below add so that dummies are persisted //Needs to be below add so that dummies are persisted
this.dummies.clear(); this.dummies.clear();
from.dummies.forEach(dummy -> this.addDummy(dummy)); from.dummies.forEach(this::addDummy);
if (errored) if (errored)
throw new RuntimeException("One of more entry values did not copy to the correct id. Check log for details!"); 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<V extends IForgeRegistryEntry<V>> implements IForgeRe
{ {
Snapshot ret = new Snapshot(); Snapshot ret = new Snapshot();
this.ids.forEach((id, value) -> ret.ids.put(getKey(value), id)); this.ids.forEach((id, value) -> ret.ids.put(getKey(value), id));
this.aliases.forEach((from, to) -> ret.aliases.put(from, to)); ret.aliases.putAll(this.aliases);
this.blocked.forEach(id -> ret.blocked.add(id)); ret.blocked.addAll(this.blocked);
this.dummies.forEach(name -> ret.dummied.add(name)); ret.dummied.addAll(this.dummies);
ret.overrides.putAll(getOverrideOwners()); ret.overrides.putAll(getOverrideOwners());
return ret; return ret;
} }

View File

@ -469,20 +469,20 @@ public class GameData
final Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps = Maps.newHashMap(); final Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps = Maps.newHashMap();
final LinkedHashMap<ResourceLocation, Map<ResourceLocation, Integer>> missing = Maps.newLinkedHashMap(); final LinkedHashMap<ResourceLocation, Map<ResourceLocation, Integer>> missing = Maps.newLinkedHashMap();
// Load the snapshot into the "STAGING" registry // Load the snapshot into the "STAGING" registry
snapshot.entrySet().forEach(e -> snapshot.forEach((key, value) ->
{ {
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(e.getKey()); final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(key);
remaps.put(e.getKey(), Maps.newLinkedHashMap()); remaps.put(key, Maps.newLinkedHashMap());
missing.put(e.getKey(), Maps.newHashMap()); missing.put(key, Maps.newHashMap());
loadPersistentDataToStagingRegistry(RegistryManager.ACTIVE, STAGING, remaps.get(e.getKey()), missing.get(e.getKey()), e.getKey(), e.getValue(), clazz); 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<ResourceLocation, Integer> m = missing.get(e.getKey()); Map<ResourceLocation, Integer> m = missing.get(key);
ForgeRegistry<?> reg = STAGING.getRegistry(e.getKey()); ForgeRegistry<?> reg = STAGING.getRegistry(key);
// Currently missing locally, we just inject and carry on // Currently missing locally, we just inject and carry on
if (m.containsKey(dummy)) if (m.containsKey(dummy))
@ -493,20 +493,20 @@ public class GameData
else if (isLocalWorld) else if (isLocalWorld)
{ {
if (ForgeRegistry.DEBUG) if (ForgeRegistry.DEBUG)
FMLLog.log.debug("Registry {}: Resuscitating dummy entry {}", e.getKey(), dummy); FMLLog.log.debug("Registry {}: Resuscitating dummy entry {}", key, dummy);
} }
else else
{ {
// The server believes this is a dummy block identity, but we seem to have one locally. This is likely a conflict // 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 // in mod setup - Mark this entry as a dummy
int id = reg.getID(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); 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) if (count > 0)
{ {
FMLLog.log.debug("There are {} mappings missing - attempting a mod remap", count); FMLLog.log.debug("There are {} mappings missing - attempting a mod remap", count);
@ -635,10 +635,10 @@ public class GameData
if (active == null) 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. 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<T> _new = to.getRegistry(name, RegistryManager.ACTIVE); ForgeRegistry<T> _new = to.getRegistry(name, RegistryManager.ACTIVE);
snap.aliases.forEach((f, t) -> _new.addAlias(f, t)); snap.aliases.forEach(_new::addAlias);
snap.blocked.forEach(id -> _new.block(id)); snap.blocked.forEach(_new::block);
// Load current dummies BEFORE the snapshot is loaded so that add() will remove from the list. // 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); _new.loadIds(snap.ids, snap.overrides, missing, remaps, active, name);
} }

View File

@ -83,12 +83,7 @@ public class ForgeTimeTracker {
// race, exit // race, exit
return; return;
} }
int[] timings = tileEntityTimings.get(tileEntity); int[] timings = tileEntityTimings.computeIfAbsent(tileEntity, k -> new int[101]);
if (timings == null)
{
timings = new int[101];
tileEntityTimings.put(tileEntity, timings);
}
int idx = timings[100] = (timings[100] + 1) % 100; int idx = timings[100] = (timings[100] + 1) % 100;
timings[idx] = (int) (nanoTime - timing); timings[idx] = (int) (nanoTime - timing);
} }