Skip to content

Commit

Permalink
Remove EnumMap and EnumSet usages (Slimefun#4258)
Browse files Browse the repository at this point in the history
  • Loading branch information
md5sha256 authored and gurrrrrrett3 committed Nov 23, 2024
1 parent 7e1186b commit 908a08c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/**
* This class houses a lot of instances of {@link Map} and {@link List} that hold
* various mappings and collections related to {@link SlimefunItem}.
*
*
* @author TheBusyBiscuit
*
*/
Expand Down Expand Up @@ -87,7 +87,7 @@ public final class SlimefunRegistry {
private final Map<String, BlockStorage> worlds = new ConcurrentHashMap<>();
private final Map<String, BlockInfoConfig> chunks = new HashMap<>();
private final Map<SlimefunGuideMode, SlimefunGuideImplementation> guides = new EnumMap<>(SlimefunGuideMode.class);
private final Map<EntityType, Set<ItemStack>> mobDrops = new EnumMap<>(EntityType.class);
private final Map<EntityType, Set<ItemStack>> mobDrops = new HashMap<>();

private final Map<String, BlockMenuPreset> blockMenuPresets = new HashMap<>();
private final Map<String, UniversalBlockMenu> universalInventories = new HashMap<>();
Expand Down Expand Up @@ -120,7 +120,7 @@ public void load(@Nonnull Slimefun plugin, @Nonnull Config cfg) {
* Auto-Loading will automatically call {@link SlimefunItem#load()} when the item is registered.
* Normally that method is called after the {@link Server} finished starting up.
* But in the unusual scenario if a {@link SlimefunItem} is registered after that, this is gonna cover that.
*
*
* @return Whether auto-loading is enabled
*/
public boolean isAutoLoadingEnabled() {
Expand All @@ -132,7 +132,7 @@ public boolean isAutoLoadingEnabled() {
* call {@link SlimefunItem#load()}.
* Normally this method call is delayed but when the {@link Server} is already running,
* the method can be called instantaneously.
*
*
* @param mode
* Whether auto-loading should be enabled
*/
Expand All @@ -142,7 +142,7 @@ public void setAutoLoadingMode(boolean mode) {

/**
* This returns a {@link List} containing every enabled {@link ItemGroup}.
*
*
* @return {@link List} containing every enabled {@link ItemGroup}
*/
public @Nonnull List<ItemGroup> getAllItemGroups() {
Expand All @@ -151,7 +151,7 @@ public void setAutoLoadingMode(boolean mode) {

/**
* This {@link List} contains every {@link SlimefunItem}, even disabled items.
*
*
* @return A {@link List} containing every {@link SlimefunItem}
*/
public @Nonnull List<SlimefunItem> getAllSlimefunItems() {
Expand All @@ -160,7 +160,7 @@ public void setAutoLoadingMode(boolean mode) {

/**
* This {@link List} contains every <strong>enabled</strong> {@link SlimefunItem}.
*
*
* @return A {@link List} containing every enabled {@link SlimefunItem}
*/
@Nonnull
Expand All @@ -170,7 +170,7 @@ public List<SlimefunItem> getEnabledSlimefunItems() {

/**
* This returns a {@link List} containing every enabled {@link Research}.
*
*
* @return A {@link List} containing every enabled {@link Research}
*/
@Nonnull
Expand All @@ -181,7 +181,7 @@ public List<Research> getResearches() {
/**
* This method returns a {@link Set} containing the {@link UUID} of every
* {@link Player} who is currently unlocking a {@link Research}.
*
*
* @return A {@link Set} holding the {@link UUID} from every {@link Player}
* who is currently unlocking a {@link Research}
*/
Expand Down Expand Up @@ -226,7 +226,7 @@ public boolean isLearningAnimationDisabled() {

/**
* This method returns a {@link List} of every enabled {@link MultiBlock}.
*
*
* @return A {@link List} containing every enabled {@link MultiBlock}
*/
@Nonnull
Expand All @@ -241,10 +241,10 @@ public List<MultiBlock> getMultiBlocks() {
* This mainly only exists for internal purposes, if you want to open a certain section
* using the {@link SlimefunGuide}, then please use the static methods provided in the
* {@link SlimefunGuide} class.
*
*
* @param mode
* The {@link SlimefunGuideMode}
*
*
* @return The corresponding {@link SlimefunGuideImplementation}
*/
@Nonnull
Expand All @@ -263,7 +263,7 @@ public SlimefunGuideImplementation getSlimefunGuide(@Nonnull SlimefunGuideMode m
/**
* This returns a {@link Map} connecting the {@link EntityType} with a {@link Set}
* of {@link ItemStack ItemStacks} which would be dropped when an {@link Entity} of that type was killed.
*
*
* @return The {@link Map} of custom mob drops
*/
@Nonnull
Expand All @@ -274,7 +274,7 @@ public Map<EntityType, Set<ItemStack>> getMobDrops() {
/**
* This returns a {@link Set} of {@link ItemStack ItemStacks} which can be obtained by bartering
* with {@link Piglin Piglins}.
*
*
* @return A {@link Set} of bartering drops
*/
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -33,8 +33,8 @@
*/
public class AutoBrewer extends AContainer implements NotHopperable {

private static final Map<Material, PotionType> potionRecipes = new EnumMap<>(Material.class);
private static final Map<PotionType, PotionType> fermentations = new EnumMap<>(PotionType.class);
private static final Map<Material, PotionType> potionRecipes = new HashMap<>();
private static final Map<PotionType, PotionType> fermentations = new HashMap<>();

static {
potionRecipes.put(Material.SUGAR, VersionedPotionType.SWIFTNESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -43,7 +43,7 @@
public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {

private static final double RANGE = 1.5;
private final Map<Material, List<Enchantment>> applicableEnchantments = new EnumMap<>(Material.class);
private final Map<Material, List<Enchantment>> applicableEnchantments = new HashMap<>();

@ParametersAreNonnullByDefault
public EnchantmentRune(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -62,7 +62,7 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
private final ItemSetting<Boolean> dualWielding = new ItemSetting<>(this, "dual-wielding", true);
private final ItemSetting<Boolean> damageOnUse = new ItemSetting<>(this, "damage-on-use", true);

private final Map<Material, ClimbableSurface> surfaces = new EnumMap<>(Material.class);
private final Map<Material, ClimbableSurface> surfaces = new HashMap<>();
private final Set<UUID> users = new HashSet<>();

@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -97,7 +97,7 @@ protected void addSurface(@Nonnull Material type, double defaultValue) {
/**
* This returns whether the {@link ClimbingPick} needs to be held in both
* arms to work.
*
*
* @return Whether dual wielding is enabled
*/
public boolean isDualWieldingEnabled() {
Expand All @@ -107,7 +107,7 @@ public boolean isDualWieldingEnabled() {
/**
* This method returns a {@link Collection} of every {@link ClimbableSurface} the
* {@link ClimbingPick} can climb.
*
*
* @return A {@link Collection} of every {@link ClimbableSurface}
*/
@Nonnull
Expand All @@ -117,10 +117,10 @@ public Collection<ClimbableSurface> getClimbableSurfaces() {

/**
* This returns the climbing speed for a given {@link Material}.
*
*
* @param type
* The {@link Material}
*
*
* @return The climbing speed for this {@link Material} or 0.
*/
public double getClimbingSpeed(@Nonnull Material type) {
Expand All @@ -136,12 +136,12 @@ public double getClimbingSpeed(@Nonnull Material type) {

/**
* This returns the climbing speed for a given {@link Material} and the used {@link ItemStack}.
*
*
* @param item
* the {@link ClimbingPick}'s {@link ItemStack}
* @param type
* The {@link Material}
*
*
* @return The climbing speed or 0.
*/
public double getClimbingSpeed(@Nonnull ItemStack item, @Nonnull Material type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

Expand All @@ -31,6 +31,11 @@
* The most common type is {@link Integer}, if you are using complex objects and try to read
* your {@link BiomeMap} from a {@link JsonElement}, make sure to provide an adequate
* {@link BiomeDataConverter} to convert the raw json data.
<<<<<<< HEAD
=======
*
* @author TheBusyBiscuit
>>>>>>> 47092df9a (Remove EnumMap and EnumSet usages (#4258))
*
* @param <T> The stored data type
*
Expand All @@ -39,9 +44,9 @@
public class BiomeMap<T> implements Keyed {

/**
* Our internal {@link EnumMap} holding all the data.
* Our internal {@link HashMap} holding all the data.
*/
private final Map<Biome, T> dataMap = new EnumMap<>(Biome.class);
private final Map<Biome, T> dataMap = new HashMap<>();

/**
* The {@link NamespacedKey} to identify this {@link BiomeMap}.
Expand All @@ -51,7 +56,12 @@ public class BiomeMap<T> implements Keyed {
/**
* This constructs a new {@link BiomeMap} with the given {@link NamespacedKey}.
*
<<<<<<< HEAD
* @param namespacedKey The {@link NamespacedKey} for this {@link BiomeMap}
=======
* @param namespacedKey
* The {@link NamespacedKey} for this {@link BiomeMap}
>>>>>>> 47092df9a (Remove EnumMap and EnumSet usages (#4258))
*/
@ParametersAreNonnullByDefault
public BiomeMap(NamespacedKey namespacedKey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.github.thebusybiscuit.slimefun4.utils.biomes;

import java.util.EnumMap;
import java.util.EnumSet;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
Expand All @@ -25,12 +26,12 @@

/**
* The {@link BiomeMapParser} allows you to parse json data into a {@link BiomeMap}.
*
*
* @author TheBusyBiscuit
*
* @param <T>
* The data type of the resulting {@link BiomeMap}
*
*
* @see BiomeMap
*/
public class BiomeMapParser<T> {
Expand All @@ -40,7 +41,7 @@ public class BiomeMapParser<T> {

private final NamespacedKey key;
private final BiomeDataConverter<T> valueConverter;
private final Map<Biome, T> map = new EnumMap<>(Biome.class);
private final Map<Biome, T> map = new HashMap<>();

/**
* This flag specifies whether the parsing is "lenient" or not.
Expand All @@ -54,7 +55,7 @@ public class BiomeMapParser<T> {
* This constructs a new {@link BiomeMapParser}.
* <p>
* To parse data, use the {@link #read(JsonArray)} or {@link #read(String)} method.
*
*
* @param key
* The {@link NamespacedKey} for the resulting {@link BiomeMap}
* @param valueConverter
Expand All @@ -75,7 +76,7 @@ public class BiomeMapParser<T> {
* A lenient parser will not throw a {@link BiomeMapException} if the {@link Biome}
* could not be found.
* The default value is false.
*
*
* @param isLenient
* Whether this parser should be lenient or not.
*/
Expand All @@ -89,7 +90,7 @@ void setLenient(boolean isLenient) {
* A lenient parser will not throw a {@link BiomeMapException} if the {@link Biome}
* could not be found.
* The default value is false.
*
*
* @return Whether this parser is lenient or not.
*/
boolean isLenient() {
Expand Down Expand Up @@ -159,7 +160,7 @@ private void readEntry(@Nonnull JsonObject entry) throws BiomeMapException {

private @Nonnull Set<Biome> readBiomes(@Nonnull JsonArray array) throws BiomeMapException {
Validate.notNull(array, "The JSON array should not be null!");
Set<Biome> biomes = EnumSet.noneOf(Biome.class);
Set<Biome> biomes = new HashSet<>();

for (JsonElement element : array) {
if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isString()) {
Expand Down Expand Up @@ -196,7 +197,7 @@ private void readEntry(@Nonnull JsonObject entry) throws BiomeMapException {
* <p>
* Make sure to parse data via {@link #read(JsonArray)} or {@link #read(String)}
* before calling this method! Otherwise the resulting {@link BiomeMap} will be empty.
*
*
* @return The resulting {@link BiomeMap}
*/
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.thebusybiscuit.slimefun4.utils.tags;

import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
Expand Down Expand Up @@ -298,7 +297,7 @@ public enum SlimefunTag implements Tag<Material> {
}

private final NamespacedKey key;
private final Set<Material> includedMaterials = EnumSet.noneOf(Material.class);
private final Set<Material> includedMaterials = new HashSet<>();
private final Set<Tag<Material>> additionalTags = new HashSet<>();

/**
Expand Down Expand Up @@ -370,8 +369,7 @@ public boolean isTagged(@Nonnull Material item) {
if (additionalTags.isEmpty()) {
return Collections.unmodifiableSet(includedMaterials);
} else {
Set<Material> materials = EnumSet.noneOf(Material.class);
materials.addAll(includedMaterials);
Set<Material> materials = new HashSet<>(includedMaterials);

for (Tag<Material> tag : additionalTags) {
materials.addAll(tag.getValues());
Expand Down
Loading

0 comments on commit 908a08c

Please sign in to comment.