Use var to replace verbose map entrySet loop

This commit is contained in:
TheMode 2021-08-16 01:29:46 +02:00
parent ef5c15fb6a
commit f3524d4a4f
7 changed files with 15 additions and 21 deletions

View File

@ -102,15 +102,12 @@ public class CommandContext {
} }
protected void retrieveDefaultValues(@Nullable Map<String, Supplier<Object>> defaultValuesMap) { protected void retrieveDefaultValues(@Nullable Map<String, Supplier<Object>> defaultValuesMap) {
if (defaultValuesMap == null) if (defaultValuesMap == null) return;
return; for (var entry : defaultValuesMap.entrySet()) {
for (Map.Entry<String, Supplier<Object>> entry : defaultValuesMap.entrySet()) {
final String key = entry.getKey(); final String key = entry.getKey();
if (!args.containsKey(key)) { if (!args.containsKey(key)) {
final var supplier = entry.getValue(); final var supplier = entry.getValue();
this.args.put(key, supplier.get()); this.args.put(key, supplier.get());
} }
} }
} }

View File

@ -148,10 +148,9 @@ public class CommandParser {
// Fill arguments map // Fill arguments map
finalContext = new CommandContext(validSyntaxHolder.commandString); finalContext = new CommandContext(validSyntaxHolder.commandString);
for (Map.Entry<Argument<?>, ArgumentParser.ArgumentResult> entry : argsValues.entrySet()) { for (var entry : argsValues.entrySet()) {
final Argument<?> argument = entry.getKey(); final Argument<?> argument = entry.getKey();
final ArgumentParser.ArgumentResult argumentResult = entry.getValue(); final ArgumentParser.ArgumentResult argumentResult = entry.getValue();
finalContext.setArg(argument.getId(), argumentResult.parsedValue, argumentResult.rawArg); finalContext.setArg(argument.getId(), argumentResult.parsedValue, argumentResult.rawArg);
} }
} }

View File

@ -476,12 +476,10 @@ public class ExtensionManager {
).isEmpty() ).isEmpty()
) { ) {
// Get all "loadable" (not actually being loaded!) extensions and put them in the sorted list. // Get all "loadable" (not actually being loaded!) extensions and put them in the sorted list.
for (Map.Entry<DiscoveredExtension, List<DiscoveredExtension>> entry : loadableExtensions) { for (var entry : loadableExtensions) {
// Add to sorted list. // Add to sorted list.
sortedList.add(entry.getKey()); sortedList.add(entry.getKey());
// Remove to make the next iterations a little quicker (hopefully) and to find cyclic dependencies.
// Remove to make the next iterations a little bit quicker (hopefully) and to find cyclic dependencies.
dependencyMap.remove(entry.getKey()); dependencyMap.remove(entry.getKey());
// Remove this dependency from all the lists (if they include it) to make way for next level of extensions. // Remove this dependency from all the lists (if they include it) to make way for next level of extensions.
@ -496,7 +494,7 @@ public class ExtensionManager {
if (!dependencyMap.isEmpty()) { if (!dependencyMap.isEmpty()) {
LOGGER.error("Minestom found {} cyclic extensions.", dependencyMap.size()); LOGGER.error("Minestom found {} cyclic extensions.", dependencyMap.size());
LOGGER.error("Cyclic extensions depend on each other and can therefore not be loaded."); LOGGER.error("Cyclic extensions depend on each other and can therefore not be loaded.");
for (Map.Entry<DiscoveredExtension, List<DiscoveredExtension>> entry : dependencyMap.entrySet()) { for (var entry : dependencyMap.entrySet()) {
DiscoveredExtension discoveredExtension = entry.getKey(); DiscoveredExtension discoveredExtension = entry.getKey();
LOGGER.error("{} could not be loaded, as it depends on: {}.", LOGGER.error("{} could not be loaded, as it depends on: {}.",
discoveredExtension.getName(), discoveredExtension.getName(),

View File

@ -82,7 +82,7 @@ public class FullQueryResponse implements Writeable {
* *
* @param players the players * @param players the players
*/ */
public void addPlayers(@NotNull String @NotNull... players) { public void addPlayers(@NotNull String @NotNull ... players) {
Collections.addAll(this.players, players); Collections.addAll(this.players, players);
} }
@ -143,7 +143,7 @@ public class FullQueryResponse implements Writeable {
writer.writeBytes(PADDING_11); writer.writeBytes(PADDING_11);
// key-values // key-values
for (Map.Entry<String, String> entry : this.kv.entrySet()) { for (var entry : this.kv.entrySet()) {
writer.writeNullTerminatedString(entry.getKey(), Query.CHARSET); writer.writeNullTerminatedString(entry.getKey(), Query.CHARSET);
writer.writeNullTerminatedString(entry.getValue(), Query.CHARSET); writer.writeNullTerminatedString(entry.getValue(), Query.CHARSET);
} }

View File

@ -21,9 +21,9 @@ public class StatusListener {
StatisticsPacket statisticsPacket = new StatisticsPacket(); StatisticsPacket statisticsPacket = new StatisticsPacket();
final Map<PlayerStatistic, Integer> playerStatisticValueMap = player.getStatisticValueMap(); final Map<PlayerStatistic, Integer> playerStatisticValueMap = player.getStatisticValueMap();
for (Map.Entry<PlayerStatistic, Integer> entry : playerStatisticValueMap.entrySet()) { for (var entry : playerStatisticValueMap.entrySet()) {
PlayerStatistic playerStatistic = entry.getKey(); final PlayerStatistic playerStatistic = entry.getKey();
int value = entry.getValue(); final int value = entry.getValue();
StatisticsPacket.Statistic statistic = new StatisticsPacket.Statistic(); StatisticsPacket.Statistic statistic = new StatisticsPacket.Statistic();
statistic.category = playerStatistic.getCategory(); statistic.category = playerStatistic.getCategory();

View File

@ -105,7 +105,7 @@ public final class BenchmarkManager {
public Component getCpuMonitoringMessage() { public Component getCpuMonitoringMessage() {
Check.stateCondition(!enabled, "CPU monitoring is only possible when the benchmark manager is enabled."); Check.stateCondition(!enabled, "CPU monitoring is only possible when the benchmark manager is enabled.");
TextComponent.Builder benchmarkMessage = Component.text(); TextComponent.Builder benchmarkMessage = Component.text();
for (Map.Entry<String, ThreadResult> resultEntry : resultMap.entrySet()) { for (var resultEntry : resultMap.entrySet()) {
final String name = resultEntry.getKey(); final String name = resultEntry.getKey();
final ThreadResult result = resultEntry.getValue(); final ThreadResult result = resultEntry.getValue();

View File

@ -100,7 +100,7 @@ public final class NBTUtils {
public static void writeEnchant(@NotNull NBTCompound nbt, @NotNull String listName, public static void writeEnchant(@NotNull NBTCompound nbt, @NotNull String listName,
@NotNull Map<Enchantment, Short> enchantmentMap) { @NotNull Map<Enchantment, Short> enchantmentMap) {
NBTList<NBTCompound> enchantList = new NBTList<>(NBTTypes.TAG_Compound); NBTList<NBTCompound> enchantList = new NBTList<>(NBTTypes.TAG_Compound);
for (Map.Entry<Enchantment, Short> entry : enchantmentMap.entrySet()) { for (var entry : enchantmentMap.entrySet()) {
final Enchantment enchantment = entry.getKey(); final Enchantment enchantment = entry.getKey();
final short level = entry.getValue(); final short level = entry.getValue();
enchantList.add(new NBTCompound() enchantList.add(new NBTCompound()