From 9675585891745f81d3a6924a13ee7c737daf42f8 Mon Sep 17 00:00:00 2001 From: mezz Date: Tue, 27 Jun 2017 23:18:09 -0700 Subject: [PATCH] Use lambdas for short anonymous methods --- .../client/ItemModelMesherForge.java | 10 +++------- .../client/gui/ForgeGuiFactory.java | 9 +-------- .../client/model/ModelLoader.java | 9 +-------- .../capabilities/CapabilityManager.java | 14 +++++--------- .../model/animation/CapabilityAnimation.java | 9 +-------- .../energy/CapabilityEnergy.java | 9 +-------- .../capability/CapabilityFluidHandler.java | 19 ++----------------- .../fml/client/config/GuiConfig.java | 10 +--------- .../fml/common/FMLModContainer.java | 18 ++---------------- .../net/minecraftforge/fml/common/Loader.java | 11 ----------- .../network/internal/EntitySpawnHandler.java | 9 +-------- .../network/internal/OpenGuiHandler.java | 9 +-------- .../fml/common/registry/GameRegistry.java | 9 +-------- .../fml/common/toposort/TopologicalSort.java | 8 +------- .../items/CapabilityItemHandler.java | 9 +-------- .../server/console/TerminalHandler.java | 10 +--------- 16 files changed, 23 insertions(+), 149 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/ItemModelMesherForge.java b/src/main/java/net/minecraftforge/client/ItemModelMesherForge.java index e5b227f5d..99670a54b 100644 --- a/src/main/java/net/minecraftforge/client/ItemModelMesherForge.java +++ b/src/main/java/net/minecraftforge/client/ItemModelMesherForge.java @@ -88,14 +88,10 @@ public class ItemModelMesherForge extends ItemModelMesher models.put(e.getKey(), mods); } final TIntObjectHashMap map = mods; - e.getValue().forEachEntry(new TIntObjectProcedure() + e.getValue().forEachEntry((meta, location) -> { - @Override - public boolean execute(int meta, ModelResourceLocation location) - { - map.put(meta, manager.getModel(location)); - return true; - } + map.put(meta, manager.getModel(location)); + return true; }); } } diff --git a/src/main/java/net/minecraftforge/client/gui/ForgeGuiFactory.java b/src/main/java/net/minecraftforge/client/gui/ForgeGuiFactory.java index aa6a7a576..04cc4a147 100644 --- a/src/main/java/net/minecraftforge/client/gui/ForgeGuiFactory.java +++ b/src/main/java/net/minecraftforge/client/gui/ForgeGuiFactory.java @@ -231,14 +231,7 @@ public class ForgeGuiFactory implements IModGuiFactory props.add(ForgeModContainer.getConfig().get(VERSION_CHECK_CAT, mod.getModId(), true)); //Get or make the value in the config } props.addAll(values.values()); // Add any left overs from the config - Collections.sort(props, new Comparator() - { - @Override - public int compare(Property o1, Property o2) - { - return o1.getName().compareTo(o2.getName()); - } - }); + props.sort(Comparator.comparing(Property::getName)); List list = new ArrayList(); list.add(new ConfigElement(global)); diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoader.java b/src/main/java/net/minecraftforge/client/model/ModelLoader.java index a525ec18a..e3c9d06f5 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoader.java @@ -1145,14 +1145,7 @@ public final class ModelLoader extends ModelBakery * Helper method for registering all itemstacks for given item to map to universal bucket model. */ public static void setBucketModelDefinition(Item item) { - ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() - { - @Override - public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) - { - return ModelDynBucket.LOCATION; - } - }); + ModelLoader.setCustomMeshDefinition(item, stack -> ModelDynBucket.LOCATION); ModelBakery.registerItemVariants(item, ModelDynBucket.LOCATION); } diff --git a/src/main/java/net/minecraftforge/common/capabilities/CapabilityManager.java b/src/main/java/net/minecraftforge/common/capabilities/CapabilityManager.java index d77028a1a..113d499b3 100644 --- a/src/main/java/net/minecraftforge/common/capabilities/CapabilityManager.java +++ b/src/main/java/net/minecraftforge/common/capabilities/CapabilityManager.java @@ -57,16 +57,12 @@ public enum CapabilityManager public void register(Class type, Capability.IStorage storage, final Class implementation) { Preconditions.checkArgument(implementation != null, "Attempted to register a capability with no default implementation"); - register(type, storage, new Callable() + register(type, storage, () -> { - @Override - public T call() throws Exception - { - try { - return implementation.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - throw Throwables.propagate(e); - } + try { + return implementation.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + throw Throwables.propagate(e); } }); } diff --git a/src/main/java/net/minecraftforge/common/model/animation/CapabilityAnimation.java b/src/main/java/net/minecraftforge/common/model/animation/CapabilityAnimation.java index 640acf040..55b292732 100644 --- a/src/main/java/net/minecraftforge/common/model/animation/CapabilityAnimation.java +++ b/src/main/java/net/minecraftforge/common/model/animation/CapabilityAnimation.java @@ -48,14 +48,7 @@ public class CapabilityAnimation @Override public void readNBT(Capability capability, IAnimationStateMachine instance, EnumFacing side, NBTBase nbt) {} - }, new Callable() - { - @Override - public IAnimationStateMachine call() throws Exception - { - return AnimationStateMachine.getMissing(); - } - }); + }, AnimationStateMachine::getMissing); } public static class DefaultItemAnimationCapabilityProvider implements ICapabilityProvider diff --git a/src/main/java/net/minecraftforge/energy/CapabilityEnergy.java b/src/main/java/net/minecraftforge/energy/CapabilityEnergy.java index 9f8cacf80..07522db11 100644 --- a/src/main/java/net/minecraftforge/energy/CapabilityEnergy.java +++ b/src/main/java/net/minecraftforge/energy/CapabilityEnergy.java @@ -50,13 +50,6 @@ public class CapabilityEnergy ((EnergyStorage)instance).energy = ((NBTTagInt)nbt).getInt(); } }, - new Callable() - { - @Override - public IEnergyStorage call() throws Exception - { - return new EnergyStorage(1000); - } - }); + () -> new EnergyStorage(1000)); } } diff --git a/src/main/java/net/minecraftforge/fluids/capability/CapabilityFluidHandler.java b/src/main/java/net/minecraftforge/fluids/capability/CapabilityFluidHandler.java index 6685c42c6..90e17f6e5 100644 --- a/src/main/java/net/minecraftforge/fluids/capability/CapabilityFluidHandler.java +++ b/src/main/java/net/minecraftforge/fluids/capability/CapabilityFluidHandler.java @@ -19,8 +19,6 @@ package net.minecraftforge.fluids.capability; -import java.util.concurrent.Callable; - import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; @@ -44,22 +42,9 @@ public class CapabilityFluidHandler public static void register() { - CapabilityManager.INSTANCE.register(IFluidHandler.class, new DefaultFluidHandlerStorage(), new Callable() - { - @Override - public IFluidHandler call() throws Exception - { - return new FluidTank(Fluid.BUCKET_VOLUME); - } - }); + CapabilityManager.INSTANCE.register(IFluidHandler.class, new DefaultFluidHandlerStorage<>(), () -> new FluidTank(Fluid.BUCKET_VOLUME)); - CapabilityManager.INSTANCE.register(IFluidHandlerItem.class, new DefaultFluidHandlerStorage(), new Callable() { - @Override - public IFluidHandlerItem call() throws Exception - { - return new FluidHandlerItemStack(new ItemStack(Items.BUCKET), Fluid.BUCKET_VOLUME); - } - }); + CapabilityManager.INSTANCE.register(IFluidHandlerItem.class, new DefaultFluidHandlerStorage<>(), () -> new FluidHandlerItemStack(new ItemStack(Items.BUCKET), Fluid.BUCKET_VOLUME)); } private static class DefaultFluidHandlerStorage implements Capability.IStorage { diff --git a/src/main/java/net/minecraftforge/fml/client/config/GuiConfig.java b/src/main/java/net/minecraftforge/fml/client/config/GuiConfig.java index d9855f228..6b415c59b 100644 --- a/src/main/java/net/minecraftforge/fml/client/config/GuiConfig.java +++ b/src/main/java/net/minecraftforge/fml/client/config/GuiConfig.java @@ -127,15 +127,7 @@ public class GuiConfig extends GuiScreen toReturn.add(ConfigElement.from(clazz)); } } - Collections.sort(toReturn, new Comparator(){ - - @Override - public int compare(IConfigElement e1, IConfigElement e2) - { - return I18n.format(e1.getLanguageKey()).compareTo(I18n.format(e2.getLanguageKey())); - } - - }); + toReturn.sort(Comparator.comparing(e -> I18n.format(e.getLanguageKey()))); return toReturn; } diff --git a/src/main/java/net/minecraftforge/fml/common/FMLModContainer.java b/src/main/java/net/minecraftforge/fml/common/FMLModContainer.java index 8a4cef56a..6df36509f 100644 --- a/src/main/java/net/minecraftforge/fml/common/FMLModContainer.java +++ b/src/main/java/net/minecraftforge/fml/common/FMLModContainer.java @@ -441,22 +441,8 @@ public class FMLModContainer implements ModContainer { SetMultimap annotations = asmDataTable.getAnnotationsFor(this); - parseSimpleFieldAnnotation(annotations, Instance.class.getName(), new Function() - { - @Override - public Object apply(ModContainer mc) - { - return mc.getMod(); - } - }); - parseSimpleFieldAnnotation(annotations, Metadata.class.getName(), new Function() - { - @Override - public Object apply(ModContainer mc) - { - return mc.getMetadata(); - } - }); + parseSimpleFieldAnnotation(annotations, Instance.class.getName(), ModContainer::getMod); + parseSimpleFieldAnnotation(annotations, Metadata.class.getName(), ModContainer::getMetadata); } private void parseSimpleFieldAnnotation(SetMultimap annotations, String annotationClassName, Function retriever) throws IllegalAccessException diff --git a/src/main/java/net/minecraftforge/fml/common/Loader.java b/src/main/java/net/minecraftforge/fml/common/Loader.java index c24ee786e..f5b0005ec 100644 --- a/src/main/java/net/minecraftforge/fml/common/Loader.java +++ b/src/main/java/net/minecraftforge/fml/common/Loader.java @@ -569,17 +569,6 @@ public class Loader modController.transition(LoaderState.CONSTRUCTING, false); modController.distributeStateMessage(LoaderState.CONSTRUCTING, modClassLoader, discoverer.getASMTable(), reverseDependencies); - List mods = Lists.newArrayList(); - mods.addAll(getActiveModList()); - Collections.sort(mods, new Comparator() - { - @Override - public int compare(ModContainer o1, ModContainer o2) - { - return o1.getModId().compareTo(o2.getModId()); - } - }); - FMLLog.log.debug("Mod signature data"); FMLLog.log.debug(" \tValid Signatures:"); for (ModContainer mod : getActiveModList()) diff --git a/src/main/java/net/minecraftforge/fml/common/network/internal/EntitySpawnHandler.java b/src/main/java/net/minecraftforge/fml/common/network/internal/EntitySpawnHandler.java index ae9fa74ba..aafd2e09a 100644 --- a/src/main/java/net/minecraftforge/fml/common/network/internal/EntitySpawnHandler.java +++ b/src/main/java/net/minecraftforge/fml/common/network/internal/EntitySpawnHandler.java @@ -56,14 +56,7 @@ public class EntitySpawnHandler extends SimpleChannelInboundHandler EntitySpawnHandler.this.process(msg)); } } diff --git a/src/main/java/net/minecraftforge/fml/common/network/internal/OpenGuiHandler.java b/src/main/java/net/minecraftforge/fml/common/network/internal/OpenGuiHandler.java index cc93e47be..96ba30b48 100644 --- a/src/main/java/net/minecraftforge/fml/common/network/internal/OpenGuiHandler.java +++ b/src/main/java/net/minecraftforge/fml/common/network/internal/OpenGuiHandler.java @@ -40,14 +40,7 @@ public class OpenGuiHandler extends SimpleChannelInboundHandler OpenGuiHandler.this.process(msg)); } } diff --git a/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java index f22474d33..8f092fda6 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java @@ -177,14 +177,7 @@ public class GameRegistry private static void computeSortedGeneratorList() { ArrayList list = Lists.newArrayList(worldGenerators); - Collections.sort(list, new Comparator() - { - @Override - public int compare(IWorldGenerator o1, IWorldGenerator o2) - { - return Ints.compare(worldGeneratorIndex.get(o1), worldGeneratorIndex.get(o2)); - } - }); + list.sort(Comparator.comparingInt(o -> worldGeneratorIndex.get(o))); sortedGeneratorList = ImmutableList.copyOf(list); } diff --git a/src/main/java/net/minecraftforge/fml/common/toposort/TopologicalSort.java b/src/main/java/net/minecraftforge/fml/common/toposort/TopologicalSort.java index 014afe001..6b5829b07 100644 --- a/src/main/java/net/minecraftforge/fml/common/toposort/TopologicalSort.java +++ b/src/main/java/net/minecraftforge/fml/common/toposort/TopologicalSort.java @@ -60,13 +60,7 @@ public class TopologicalSort } orderedNodes.add(node); - graph.put(node, new TreeSet(new Comparator() - { - @Override - public int compare(T o1, T o2) { - return orderedNodes.indexOf(o1)-orderedNodes.indexOf(o2); - } - })); + graph.put(node, new TreeSet(Comparator.comparingInt(o -> orderedNodes.indexOf(o)))); return true; } diff --git a/src/main/java/net/minecraftforge/items/CapabilityItemHandler.java b/src/main/java/net/minecraftforge/items/CapabilityItemHandler.java index 48225f6a1..53bb31493 100644 --- a/src/main/java/net/minecraftforge/items/CapabilityItemHandler.java +++ b/src/main/java/net/minecraftforge/items/CapabilityItemHandler.java @@ -76,14 +76,7 @@ public class CapabilityItemHandler } } } - }, new Callable() - { - @Override - public ItemStackHandler call() throws Exception - { - return new ItemStackHandler(); - } - }); + }, ItemStackHandler::new); } } diff --git a/src/main/java/net/minecraftforge/server/console/TerminalHandler.java b/src/main/java/net/minecraftforge/server/console/TerminalHandler.java index 055945ce3..6160859cb 100644 --- a/src/main/java/net/minecraftforge/server/console/TerminalHandler.java +++ b/src/main/java/net/minecraftforge/server/console/TerminalHandler.java @@ -74,15 +74,7 @@ public final class TerminalHandler } else { - TerminalConsoleAppender.setFormatter(new Function() { - - @Override - public String apply(String text) - { - return TextFormatting.getTextWithoutFormattingCodes(text); - } - - }); + TerminalConsoleAppender.setFormatter(TextFormatting::getTextWithoutFormattingCodes); return false; } }