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) {
if (defaultValuesMap == null)
return;
for (Map.Entry<String, Supplier<Object>> entry : defaultValuesMap.entrySet()) {
if (defaultValuesMap == null) return;
for (var entry : defaultValuesMap.entrySet()) {
final String key = entry.getKey();
if (!args.containsKey(key)) {
final var supplier = entry.getValue();
this.args.put(key, supplier.get());
}
}
}

View File

@ -148,10 +148,9 @@ public class CommandParser {
// Fill arguments map
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 ArgumentParser.ArgumentResult argumentResult = entry.getValue();
finalContext.setArg(argument.getId(), argumentResult.parsedValue, argumentResult.rawArg);
}
}

View File

@ -476,12 +476,10 @@ public class ExtensionManager {
).isEmpty()
) {
// 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.
sortedList.add(entry.getKey());
// Remove to make the next iterations a little bit quicker (hopefully) and to find cyclic dependencies.
// Remove to make the next iterations a little quicker (hopefully) and to find cyclic dependencies.
dependencyMap.remove(entry.getKey());
// 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()) {
LOGGER.error("Minestom found {} cyclic extensions.", dependencyMap.size());
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();
LOGGER.error("{} could not be loaded, as it depends on: {}.",
discoveredExtension.getName(),

View File

@ -42,7 +42,7 @@ public class FullQueryResponse implements Writeable {
/**
* Puts a key-value mapping into the response.
*
* @param key the key
* @param key the key
* @param value the value
*/
public void put(@NotNull QueryKey key, @NotNull String value) {
@ -52,7 +52,7 @@ public class FullQueryResponse implements Writeable {
/**
* Puts a key-value mapping into the response.
*
* @param key the key
* @param key the key
* @param value the value
*/
public void put(@NotNull String key, @NotNull String value) {
@ -82,7 +82,7 @@ public class FullQueryResponse implements Writeable {
*
* @param players the players
*/
public void addPlayers(@NotNull String @NotNull... players) {
public void addPlayers(@NotNull String @NotNull ... players) {
Collections.addAll(this.players, players);
}
@ -143,7 +143,7 @@ public class FullQueryResponse implements Writeable {
writer.writeBytes(PADDING_11);
// 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.getValue(), Query.CHARSET);
}

View File

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

View File

@ -105,7 +105,7 @@ public final class BenchmarkManager {
public Component getCpuMonitoringMessage() {
Check.stateCondition(!enabled, "CPU monitoring is only possible when the benchmark manager is enabled.");
TextComponent.Builder benchmarkMessage = Component.text();
for (Map.Entry<String, ThreadResult> resultEntry : resultMap.entrySet()) {
for (var resultEntry : resultMap.entrySet()) {
final String name = resultEntry.getKey();
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,
@NotNull Map<Enchantment, Short> enchantmentMap) {
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 short level = entry.getValue();
enchantList.add(new NBTCompound()