Use lambdas for short anonymous methods

This commit is contained in:
mezz 2017-06-27 23:18:09 -07:00
parent 93025510ae
commit 9675585891
16 changed files with 23 additions and 149 deletions

View File

@ -88,14 +88,10 @@ public class ItemModelMesherForge extends ItemModelMesher
models.put(e.getKey(), mods);
}
final TIntObjectHashMap<IBakedModel> map = mods;
e.getValue().forEachEntry(new TIntObjectProcedure<ModelResourceLocation>()
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;
});
}
}

View File

@ -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<Property>()
{
@Override
public int compare(Property o1, Property o2)
{
return o1.getName().compareTo(o2.getName());
}
});
props.sort(Comparator.comparing(Property::getName));
List<IConfigElement> list = new ArrayList<IConfigElement>();
list.add(new ConfigElement(global));

View File

@ -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);
}

View File

@ -57,16 +57,12 @@ public enum CapabilityManager
public <T> void register(Class<T> type, Capability.IStorage<T> storage, final Class<? extends T> implementation)
{
Preconditions.checkArgument(implementation != null, "Attempted to register a capability with no default implementation");
register(type, storage, new Callable<T>()
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);
}
});
}

View File

@ -48,14 +48,7 @@ public class CapabilityAnimation
@Override
public void readNBT(Capability<IAnimationStateMachine> capability, IAnimationStateMachine instance, EnumFacing side, NBTBase nbt) {}
}, new Callable<IAnimationStateMachine>()
{
@Override
public IAnimationStateMachine call() throws Exception
{
return AnimationStateMachine.getMissing();
}
});
}, AnimationStateMachine::getMissing);
}
public static class DefaultItemAnimationCapabilityProvider implements ICapabilityProvider

View File

@ -50,13 +50,6 @@ public class CapabilityEnergy
((EnergyStorage)instance).energy = ((NBTTagInt)nbt).getInt();
}
},
new Callable<IEnergyStorage>()
{
@Override
public IEnergyStorage call() throws Exception
{
return new EnergyStorage(1000);
}
});
() -> new EnergyStorage(1000));
}
}

View File

@ -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<IFluidHandler>(), new Callable<IFluidHandler>()
{
@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<IFluidHandlerItem>(), new Callable<IFluidHandlerItem>() {
@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<T extends IFluidHandler> implements Capability.IStorage<T> {

View File

@ -127,15 +127,7 @@ public class GuiConfig extends GuiScreen
toReturn.add(ConfigElement.from(clazz));
}
}
Collections.sort(toReturn, new Comparator<IConfigElement>(){
@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;
}

View File

@ -441,22 +441,8 @@ public class FMLModContainer implements ModContainer
{
SetMultimap<String, ASMData> annotations = asmDataTable.getAnnotationsFor(this);
parseSimpleFieldAnnotation(annotations, Instance.class.getName(), new Function<ModContainer, Object>()
{
@Override
public Object apply(ModContainer mc)
{
return mc.getMod();
}
});
parseSimpleFieldAnnotation(annotations, Metadata.class.getName(), new Function<ModContainer, Object>()
{
@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<String, ASMData> annotations, String annotationClassName, Function<ModContainer, Object> retriever) throws IllegalAccessException

View File

@ -569,17 +569,6 @@ public class Loader
modController.transition(LoaderState.CONSTRUCTING, false);
modController.distributeStateMessage(LoaderState.CONSTRUCTING, modClassLoader, discoverer.getASMTable(), reverseDependencies);
List<ModContainer> mods = Lists.newArrayList();
mods.addAll(getActiveModList());
Collections.sort(mods, new Comparator<ModContainer>()
{
@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())

View File

@ -56,14 +56,7 @@ public class EntitySpawnHandler extends SimpleChannelInboundHandler<FMLMessage.E
}
else
{
thread.addScheduledTask(new Runnable()
{
@Override
public void run()
{
EntitySpawnHandler.this.process(msg);
}
});
thread.addScheduledTask(() -> EntitySpawnHandler.this.process(msg));
}
}

View File

@ -40,14 +40,7 @@ public class OpenGuiHandler extends SimpleChannelInboundHandler<FMLMessage.OpenG
}
else
{
thread.addScheduledTask(new Runnable()
{
@Override
public void run()
{
OpenGuiHandler.this.process(msg);
}
});
thread.addScheduledTask(() -> OpenGuiHandler.this.process(msg));
}
}

View File

@ -177,14 +177,7 @@ public class GameRegistry
private static void computeSortedGeneratorList()
{
ArrayList<IWorldGenerator> list = Lists.newArrayList(worldGenerators);
Collections.sort(list, new Comparator<IWorldGenerator>()
{
@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);
}

View File

@ -60,13 +60,7 @@ public class TopologicalSort
}
orderedNodes.add(node);
graph.put(node, new TreeSet<T>(new Comparator<T>()
{
@Override
public int compare(T o1, T o2) {
return orderedNodes.indexOf(o1)-orderedNodes.indexOf(o2);
}
}));
graph.put(node, new TreeSet<T>(Comparator.comparingInt(o -> orderedNodes.indexOf(o))));
return true;
}

View File

@ -76,14 +76,7 @@ public class CapabilityItemHandler
}
}
}
}, new Callable<ItemStackHandler>()
{
@Override
public ItemStackHandler call() throws Exception
{
return new ItemStackHandler();
}
});
}, ItemStackHandler::new);
}
}

View File

@ -74,15 +74,7 @@ public final class TerminalHandler
}
else
{
TerminalConsoleAppender.setFormatter(new Function<String, String>() {
@Override
public String apply(String text)
{
return TextFormatting.getTextWithoutFormattingCodes(text);
}
});
TerminalConsoleAppender.setFormatter(TextFormatting::getTextWithoutFormattingCodes);
return false;
}
}