Skip to content

Commit 47092df

Browse files
authored
Remove EnumMap and EnumSet usages (#4258)
1 parent 6f02cae commit 47092df

File tree

8 files changed

+53
-55
lines changed

8 files changed

+53
-55
lines changed

src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
/**
4848
* This class houses a lot of instances of {@link Map} and {@link List} that hold
4949
* various mappings and collections related to {@link SlimefunItem}.
50-
*
50+
*
5151
* @author TheBusyBiscuit
5252
*
5353
*/
@@ -87,7 +87,7 @@ public final class SlimefunRegistry {
8787
private final Map<String, BlockStorage> worlds = new ConcurrentHashMap<>();
8888
private final Map<String, BlockInfoConfig> chunks = new HashMap<>();
8989
private final Map<SlimefunGuideMode, SlimefunGuideImplementation> guides = new EnumMap<>(SlimefunGuideMode.class);
90-
private final Map<EntityType, Set<ItemStack>> mobDrops = new EnumMap<>(EntityType.class);
90+
private final Map<EntityType, Set<ItemStack>> mobDrops = new HashMap<>();
9191

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

143143
/**
144144
* This returns a {@link List} containing every enabled {@link ItemGroup}.
145-
*
145+
*
146146
* @return {@link List} containing every enabled {@link ItemGroup}
147147
*/
148148
public @Nonnull List<ItemGroup> getAllItemGroups() {
@@ -151,7 +151,7 @@ public void setAutoLoadingMode(boolean mode) {
151151

152152
/**
153153
* This {@link List} contains every {@link SlimefunItem}, even disabled items.
154-
*
154+
*
155155
* @return A {@link List} containing every {@link SlimefunItem}
156156
*/
157157
public @Nonnull List<SlimefunItem> getAllSlimefunItems() {
@@ -160,7 +160,7 @@ public void setAutoLoadingMode(boolean mode) {
160160

161161
/**
162162
* This {@link List} contains every <strong>enabled</strong> {@link SlimefunItem}.
163-
*
163+
*
164164
* @return A {@link List} containing every enabled {@link SlimefunItem}
165165
*/
166166
@Nonnull
@@ -170,7 +170,7 @@ public List<SlimefunItem> getEnabledSlimefunItems() {
170170

171171
/**
172172
* This returns a {@link List} containing every enabled {@link Research}.
173-
*
173+
*
174174
* @return A {@link List} containing every enabled {@link Research}
175175
*/
176176
@Nonnull
@@ -181,7 +181,7 @@ public List<Research> getResearches() {
181181
/**
182182
* This method returns a {@link Set} containing the {@link UUID} of every
183183
* {@link Player} who is currently unlocking a {@link Research}.
184-
*
184+
*
185185
* @return A {@link Set} holding the {@link UUID} from every {@link Player}
186186
* who is currently unlocking a {@link Research}
187187
*/
@@ -226,7 +226,7 @@ public boolean isLearningAnimationDisabled() {
226226

227227
/**
228228
* This method returns a {@link List} of every enabled {@link MultiBlock}.
229-
*
229+
*
230230
* @return A {@link List} containing every enabled {@link MultiBlock}
231231
*/
232232
@Nonnull
@@ -241,10 +241,10 @@ public List<MultiBlock> getMultiBlocks() {
241241
* This mainly only exists for internal purposes, if you want to open a certain section
242242
* using the {@link SlimefunGuide}, then please use the static methods provided in the
243243
* {@link SlimefunGuide} class.
244-
*
244+
*
245245
* @param mode
246246
* The {@link SlimefunGuideMode}
247-
*
247+
*
248248
* @return The corresponding {@link SlimefunGuideImplementation}
249249
*/
250250
@Nonnull
@@ -263,7 +263,7 @@ public SlimefunGuideImplementation getSlimefunGuide(@Nonnull SlimefunGuideMode m
263263
/**
264264
* This returns a {@link Map} connecting the {@link EntityType} with a {@link Set}
265265
* of {@link ItemStack ItemStacks} which would be dropped when an {@link Entity} of that type was killed.
266-
*
266+
*
267267
* @return The {@link Map} of custom mob drops
268268
*/
269269
@Nonnull
@@ -274,7 +274,7 @@ public Map<EntityType, Set<ItemStack>> getMobDrops() {
274274
/**
275275
* This returns a {@link Set} of {@link ItemStack ItemStacks} which can be obtained by bartering
276276
* with {@link Piglin Piglins}.
277-
*
277+
*
278278
* @return A {@link Set} of bartering drops
279279
*/
280280
@Nonnull

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
22

3-
import java.util.EnumMap;
3+
import java.util.HashMap;
44
import java.util.Map;
55

66
import javax.annotation.Nonnull;
@@ -33,8 +33,8 @@
3333
*/
3434
public class AutoBrewer extends AContainer implements NotHopperable {
3535

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

3939
static {
4040
potionRecipes.put(Material.SUGAR, VersionedPotionType.SWIFTNESS);

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/EnchantmentRune.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.Collection;
5-
import java.util.EnumMap;
5+
import java.util.HashMap;
66
import java.util.Iterator;
77
import java.util.List;
88
import java.util.Map;
@@ -43,7 +43,7 @@
4343
public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
4444

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

4848
@ParametersAreNonnullByDefault
4949
public EnchantmentRune(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.Collection;
5-
import java.util.EnumMap;
5+
import java.util.HashMap;
66
import java.util.HashSet;
77
import java.util.List;
88
import java.util.Map;
@@ -62,7 +62,7 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
6262
private final ItemSetting<Boolean> dualWielding = new ItemSetting<>(this, "dual-wielding", true);
6363
private final ItemSetting<Boolean> damageOnUse = new ItemSetting<>(this, "damage-on-use", true);
6464

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

6868
@ParametersAreNonnullByDefault
@@ -97,7 +97,7 @@ protected void addSurface(@Nonnull Material type, double defaultValue) {
9797
/**
9898
* This returns whether the {@link ClimbingPick} needs to be held in both
9999
* arms to work.
100-
*
100+
*
101101
* @return Whether dual wielding is enabled
102102
*/
103103
public boolean isDualWieldingEnabled() {
@@ -107,7 +107,7 @@ public boolean isDualWieldingEnabled() {
107107
/**
108108
* This method returns a {@link Collection} of every {@link ClimbableSurface} the
109109
* {@link ClimbingPick} can climb.
110-
*
110+
*
111111
* @return A {@link Collection} of every {@link ClimbableSurface}
112112
*/
113113
@Nonnull
@@ -117,10 +117,10 @@ public Collection<ClimbableSurface> getClimbableSurfaces() {
117117

118118
/**
119119
* This returns the climbing speed for a given {@link Material}.
120-
*
120+
*
121121
* @param type
122122
* The {@link Material}
123-
*
123+
*
124124
* @return The climbing speed for this {@link Material} or 0.
125125
*/
126126
public double getClimbingSpeed(@Nonnull Material type) {
@@ -136,12 +136,12 @@ public double getClimbingSpeed(@Nonnull Material type) {
136136

137137
/**
138138
* This returns the climbing speed for a given {@link Material} and the used {@link ItemStack}.
139-
*
139+
*
140140
* @param item
141141
* the {@link ClimbingPick}'s {@link ItemStack}
142142
* @param type
143143
* The {@link Material}
144-
*
144+
*
145145
* @return The climbing speed or 0.
146146
*/
147147
public double getClimbingSpeed(@Nonnull ItemStack item, @Nonnull Material type) {

src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMap.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.io.IOException;
55
import java.io.InputStreamReader;
66
import java.nio.charset.StandardCharsets;
7-
import java.util.EnumMap;
7+
import java.util.HashMap;
88
import java.util.Map;
99
import java.util.stream.Collectors;
1010

@@ -34,7 +34,7 @@
3434
* The most common type is {@link Integer}, if you are using complex objects and try to read
3535
* your {@link BiomeMap} from a {@link JsonElement}, make sure to provide an adequate
3636
* {@link BiomeDataConverter} to convert the raw json data.
37-
*
37+
*
3838
* @author TheBusyBiscuit
3939
*
4040
* @param <T>
@@ -43,9 +43,9 @@
4343
public class BiomeMap<T> implements Keyed {
4444

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

5050
/**
5151
* The {@link NamespacedKey} to identify this {@link BiomeMap}.
@@ -54,7 +54,7 @@ public class BiomeMap<T> implements Keyed {
5454

5555
/**
5656
* This constructs a new {@link BiomeMap} with the given {@link NamespacedKey}.
57-
*
57+
*
5858
* @param namespacedKey
5959
* The {@link NamespacedKey} for this {@link BiomeMap}
6060
*/
@@ -92,7 +92,7 @@ public boolean containsValue(@Nonnull T value) {
9292
/**
9393
* This returns whether this {@link BiomeMap} is empty.
9494
* An empty {@link BiomeMap} contains no biomes or values.
95-
*
95+
*
9696
* @return Whether this {@link BiomeMap} is empty.
9797
*/
9898
public boolean isEmpty() {

src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package io.github.thebusybiscuit.slimefun4.utils.biomes;
22

3-
import java.util.EnumMap;
4-
import java.util.EnumSet;
3+
4+
import java.util.HashMap;
5+
import java.util.HashSet;
56
import java.util.Locale;
67
import java.util.Map;
78
import java.util.Set;
@@ -25,12 +26,12 @@
2526

2627
/**
2728
* The {@link BiomeMapParser} allows you to parse json data into a {@link BiomeMap}.
28-
*
29+
*
2930
* @author TheBusyBiscuit
3031
*
3132
* @param <T>
3233
* The data type of the resulting {@link BiomeMap}
33-
*
34+
*
3435
* @see BiomeMap
3536
*/
3637
public class BiomeMapParser<T> {
@@ -40,7 +41,7 @@ public class BiomeMapParser<T> {
4041

4142
private final NamespacedKey key;
4243
private final BiomeDataConverter<T> valueConverter;
43-
private final Map<Biome, T> map = new EnumMap<>(Biome.class);
44+
private final Map<Biome, T> map = new HashMap<>();
4445

4546
/**
4647
* This flag specifies whether the parsing is "lenient" or not.
@@ -54,7 +55,7 @@ public class BiomeMapParser<T> {
5455
* This constructs a new {@link BiomeMapParser}.
5556
* <p>
5657
* To parse data, use the {@link #read(JsonArray)} or {@link #read(String)} method.
57-
*
58+
*
5859
* @param key
5960
* The {@link NamespacedKey} for the resulting {@link BiomeMap}
6061
* @param valueConverter
@@ -75,7 +76,7 @@ public BiomeMapParser(NamespacedKey key, BiomeDataConverter<T> valueConverter) {
7576
* A lenient parser will not throw a {@link BiomeMapException} if the {@link Biome}
7677
* could not be found.
7778
* The default value is false.
78-
*
79+
*
7980
* @param isLenient
8081
* Whether this parser should be lenient or not.
8182
*/
@@ -89,7 +90,7 @@ public void setLenient(boolean isLenient) {
8990
* A lenient parser will not throw a {@link BiomeMapException} if the {@link Biome}
9091
* could not be found.
9192
* The default value is false.
92-
*
93+
*
9394
* @return Whether this parser is lenient or not.
9495
*/
9596
public boolean isLenient() {
@@ -159,7 +160,7 @@ private void readEntry(@Nonnull JsonObject entry) throws BiomeMapException {
159160

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

164165
for (JsonElement element : array) {
165166
if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isString()) {
@@ -196,7 +197,7 @@ private void readEntry(@Nonnull JsonObject entry) throws BiomeMapException {
196197
* <p>
197198
* Make sure to parse data via {@link #read(JsonArray)} or {@link #read(String)}
198199
* before calling this method! Otherwise the resulting {@link BiomeMap} will be empty.
199-
*
200+
*
200201
* @return The resulting {@link BiomeMap}
201202
*/
202203
@Nonnull

src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.github.thebusybiscuit.slimefun4.utils.tags;
22

33
import java.util.Collections;
4-
import java.util.EnumSet;
54
import java.util.HashMap;
65
import java.util.HashSet;
76
import java.util.Locale;
@@ -298,7 +297,7 @@ public enum SlimefunTag implements Tag<Material> {
298297
}
299298

300299
private final NamespacedKey key;
301-
private final Set<Material> includedMaterials = EnumSet.noneOf(Material.class);
300+
private final Set<Material> includedMaterials = new HashSet<>();
302301
private final Set<Tag<Material>> additionalTags = new HashSet<>();
303302

304303
/**
@@ -370,8 +369,7 @@ public boolean isTagged(@Nonnull Material item) {
370369
if (additionalTags.isEmpty()) {
371370
return Collections.unmodifiableSet(includedMaterials);
372371
} else {
373-
Set<Material> materials = EnumSet.noneOf(Material.class);
374-
materials.addAll(includedMaterials);
372+
Set<Material> materials = new HashSet<>(includedMaterials);
375373

376374
for (Tag<Material> tag : additionalTags) {
377375
materials.addAll(tag.getValues());

0 commit comments

Comments
 (0)