Skip to content

Commit 5d443fd

Browse files
authored
Remove generic usage (#16)
* Remove generic value usage * Update test base to reflect the flattened structure * Rename class to reflect their context usage * Add new methods * Override equals and hashcode * Rename class * Add tests for the service class * Remove generic mention in the documentation
1 parent c67ec2a commit 5d443fd

File tree

11 files changed

+190
-87
lines changed

11 files changed

+190
-87
lines changed
Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.onelitefeather.guira;
22

3-
import net.theevilreaper.aves.map.BaseMap;
43
import net.onelitefeather.guira.data.SetupData;
54
import org.jetbrains.annotations.Contract;
65
import org.jetbrains.annotations.NotNull;
@@ -12,50 +11,62 @@
1211
import java.util.UUID;
1312

1413
/**
15-
* The (@link SetupDataService} is responsible for managing setup data during a runtime session.
14+
* The {@link SetupDataService} is responsible for managing setup data during a runtime session.
1615
* It allows adding, removing, and retrieving setup data associated with a unique identifier (UUID).
1716
*
18-
* @param <T> the type of setup data
17+
1918
* @author thEvilReaper
2019
* @version 1.0.0
2120
* @since 0.1.0
2221
*/
23-
public interface SetupDataService<T extends SetupData<? extends BaseMap>> {
22+
public interface SetupDataService {
2423

2524
/**
2625
* Creates a new instance of SetupDataService.
2726
*
28-
* @param <T> the type of setup data
2927
* @return a new instance of SetupDataService
3028
*/
3129
@Contract(pure = true)
32-
static @NotNull <T extends SetupData<? extends BaseMap>> SetupDataService<T> create() {
33-
return new SetupDataServiceImpl<>();
30+
static @NotNull SetupDataService create() {
31+
return new SetupDataServiceImpl();
3432
}
3533

3634
/**
37-
* Adds a new setup data to the service.
35+
* Checks if the service contains any setup data.
36+
*
37+
* @return true if the service is empty, false otherwise
38+
*/
39+
boolean isEmpty();
40+
41+
/**
42+
* Clears all setup data from the service.
43+
* This method removes all entries from the setup data map.
44+
*/
45+
void clear();
46+
47+
/**
48+
* Adds new setup data to the service.
3849
*
3950
* @param uuid the unique identifier for the setup data
4051
* @param data the setup data to add
4152
*/
42-
void add(@NotNull UUID uuid, @NotNull T data);
53+
void add(@NotNull UUID uuid, @NotNull SetupData data);
4354

4455
/**
4556
* Removes the setup data associated with the given UUID.
4657
*
4758
* @param uuid the unique identifier for the setup data
4859
* @return an optional containing the removed setup data, or empty if not found
4960
*/
50-
@NotNull Optional<@Nullable T> remove(@NotNull UUID uuid);
61+
@NotNull Optional<@Nullable SetupData> remove(@NotNull UUID uuid);
5162

5263
/**
5364
* Retrieves the setup data associated with the given UUID.
5465
*
5566
* @param uuid the unique identifier for the setup data
5667
* @return an optional containing the setup data, or empty if not found
5768
*/
58-
@NotNull Optional<@Nullable T> get(@NotNull UUID uuid);
69+
@NotNull Optional<@Nullable SetupData> get(@NotNull UUID uuid);
5970

6071
/**
6172
* Returns an unmodifiable view of the setup data map.
@@ -64,5 +75,5 @@ public interface SetupDataService<T extends SetupData<? extends BaseMap>> {
6475
*/
6576
@NotNull
6677
@UnmodifiableView
67-
Map<UUID, T> getView();
78+
Map<UUID, SetupData> getView();
6879
}
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.onelitefeather.guira;
22

3-
import net.theevilreaper.aves.map.BaseMap;
43
import net.onelitefeather.guira.data.SetupData;
54
import org.jetbrains.annotations.NotNull;
65
import org.jetbrains.annotations.UnmodifiableView;
@@ -11,31 +10,57 @@
1110
import java.util.Optional;
1211
import java.util.UUID;
1312

14-
public final class SetupDataServiceImpl<T extends SetupData<? extends BaseMap>> implements SetupDataService<T> {
13+
public final class SetupDataServiceImpl implements SetupDataService {
1514

16-
private final Map<UUID, T> dataMap;
15+
private final Map<UUID, SetupData> dataMap;
1716

1817
SetupDataServiceImpl() {
1918
this.dataMap = new HashMap<>();
2019
}
2120

2221
@Override
23-
public void add(@NotNull UUID uuid, @NotNull T data) {
22+
public void clear() {
23+
if (this.dataMap.isEmpty()) return;
24+
this.dataMap.clear();
25+
}
26+
27+
/**
28+
* {@inheritDoc}
29+
*/
30+
@Override
31+
public boolean isEmpty() {
32+
return this.dataMap.isEmpty();
33+
}
34+
35+
/**
36+
* {@inheritDoc}
37+
*/
38+
@Override
39+
public void add(@NotNull UUID uuid, @NotNull SetupData data) {
2440
dataMap.put(uuid, data);
2541
}
2642

43+
/**
44+
* {@inheritDoc}
45+
*/
2746
@Override
28-
public @NotNull Optional<T> remove(@NotNull UUID uuid) {
47+
public @NotNull Optional<SetupData> remove(@NotNull UUID uuid) {
2948
return Optional.ofNullable(this.dataMap.remove(uuid));
3049
}
3150

51+
/**
52+
* {@inheritDoc}
53+
*/
3254
@Override
33-
public @NotNull Optional<T> get(@NotNull UUID uuid) {
55+
public @NotNull Optional<SetupData> get(@NotNull UUID uuid) {
3456
return Optional.ofNullable(this.dataMap.get(uuid));
3557
}
3658

59+
/**
60+
* {@inheritDoc}
61+
*/
3762
@Override
38-
public @NotNull @UnmodifiableView Map<UUID, T> getView() {
63+
public @NotNull @UnmodifiableView Map<UUID, SetupData> getView() {
3964
return Collections.unmodifiableMap(this.dataMap);
4065
}
4166
}

src/main/java/net/onelitefeather/guira/data/BaseSetupData.java renamed to src/main/java/net/onelitefeather/guira/data/MapSetupData.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@
99
import java.util.UUID;
1010

1111
/**
12-
* The {@link BaseSetupData} is a generic implementation of the {@link SetupData} interface.
12+
* The {@link MapSetupData} is a generic implementation of the {@link SetupData} interface.
1313
* It provides a basic implementation and needs to be extended by a specific setup data class.
1414
* @param <T> the reference type of the map
1515
* @version 1.0.0
1616
* @since 0.1.0
1717
* @author theEvilReaper
1818
*/
19-
public abstract non-sealed class BaseSetupData<T extends BaseMap> implements SetupData<T> {
19+
public abstract class MapSetupData<T extends BaseMap> implements SetupData {
2020

2121
protected final UUID uuid;
2222
protected final MapEntry mapEntry;
2323
protected T map;
2424

25-
protected BaseSetupData(@NotNull UUID uuid, @NotNull MapEntry mapEntry) {
25+
protected MapSetupData(@NotNull UUID uuid, @NotNull MapEntry mapEntry) {
2626
this.uuid = uuid;
2727
this.mapEntry = mapEntry;
2828
}
2929

3030
@Override
3131
public boolean equals(Object o) {
32-
if (!(o instanceof BaseSetupData<?> that)) return false;
32+
if (!(o instanceof MapSetupData<?> that)) return false;
3333
return Objects.equals(uuid, that.uuid);
3434
}
3535

@@ -38,22 +38,33 @@ public int hashCode() {
3838
return Objects.hashCode(uuid);
3939
}
4040

41-
@Override
41+
/**
42+
* Returns if the setup data has a map file.
43+
*
44+
* @return {@code true} if the setup data has a map
45+
*/
4246
public boolean hasMapFile() {
4347
return this.mapEntry.hasMapFile();
4448
}
4549

46-
@Override
50+
/**
51+
* Returns the map entry of the setup data.
52+
*
53+
* @return the map entry as {@link MapEntry}
54+
*/
4755
public @NotNull MapEntry getEntry() {
4856
return this.mapEntry;
4957
}
5058

51-
@Override
59+
/**
60+
* Returns the map of the setup data.
61+
*
62+
* @return the map as {@link BaseMap}
63+
*/
5264
public @NotNull UUID getId() {
5365
return this.uuid;
5466
}
5567

56-
@Override
5768
public @NotNull Optional<T> getMap() {
5869
return Optional.ofNullable(this.map);
5970
}
Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package net.onelitefeather.guira.data;
22

3-
import net.theevilreaper.aves.map.BaseMap;
4-
import net.theevilreaper.aves.map.MapEntry;
53
import org.jetbrains.annotations.NotNull;
64

7-
import java.util.Optional;
85
import java.util.UUID;
96

107
/**
118
* The {@link SetupData} interface defines an object which contains all relevant values about a setup instance.
129
*
13-
* @param <T> the reference type of the map
10+
* @author theEvilReaper
11+
* @version 1.2.0
12+
* @since 0.1.0
1413
*/
15-
public sealed interface SetupData<T extends BaseMap> permits BaseSetupData {
14+
public interface SetupData {
1615

1716
/**
1817
* Can be used to save the data from the setup into another format.
@@ -29,31 +28,10 @@ public sealed interface SetupData<T extends BaseMap> permits BaseSetupData {
2928
*/
3029
void loadData();
3130

32-
/**
33-
* Returns if the setup data has a map file.
34-
*
35-
* @return {@code true} if the setup data has a map
36-
*/
37-
boolean hasMapFile();
38-
3931
/**
4032
* Returns the owner of the setup data.
4133
*
4234
* @return the owner as {@link UUID}
4335
*/
4436
@NotNull UUID getId();
45-
46-
/**
47-
* Returns the map of the setup data.
48-
*
49-
* @return the map as {@link BaseMap}
50-
*/
51-
@NotNull Optional<T> getMap();
52-
53-
/**
54-
* Returns the map entry of the setup data.
55-
*
56-
* @return the map entry as {@link MapEntry}
57-
*/
58-
@NotNull MapEntry getEntry();
5937
}

src/main/java/net/onelitefeather/guira/event/SetupCreateEvent.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.onelitefeather.guira.event;
22

3-
import net.theevilreaper.aves.map.BaseMap;
43
import net.minestom.server.event.Event;
54
import net.minestom.server.event.trait.CancellableEvent;
65
import net.onelitefeather.guira.data.SetupData;
@@ -10,17 +9,16 @@
109
* The {@link SetupCreateEvent} can be used to indicate that a setup has started by the owner.
1110
* You need to call it on your own and the handling of it.
1211
*
13-
* @param <T> the reference from the data
1412
* @author thEvilReaper
1513
* @version 1.0.0
1614
* @since 0.1.0
1715
*/
18-
public class SetupCreateEvent<T extends SetupData<? extends BaseMap>> implements Event, CancellableEvent {
16+
public class SetupCreateEvent implements Event, CancellableEvent {
1917

2018
private boolean cancelled;
21-
private final T data;
19+
private final SetupData data;
2220

23-
public SetupCreateEvent(@NotNull T data) {
21+
public SetupCreateEvent(@NotNull SetupData data) {
2422
this.data = data;
2523
}
2624

@@ -29,7 +27,7 @@ public SetupCreateEvent(@NotNull T data) {
2927
*
3028
* @return the reference
3129
*/
32-
public T getData() {
30+
public SetupData getData() {
3331
return data;
3432
}
3533

src/main/java/net/onelitefeather/guira/event/SetupFinishEvent.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
package net.onelitefeather.guira.event;
22

3-
import net.theevilreaper.aves.map.BaseMap;
43
import net.minestom.server.event.Event;
54
import net.minestom.server.event.trait.CancellableEvent;
65
import net.onelitefeather.guira.data.SetupData;
76
import org.jetbrains.annotations.NotNull;
87

98
/**
109
* The {@link SetupFinishEvent} can be used to indicate that a setup process has been finished by the user.
11-
* If your use case has some condition which needs to be checked before the setup process is finished, you can cancel
10+
* If your use case has some condition that needs to be checked before the setup process is finished, you can cancel
1211
* the event. But you need to handle the cancellation yourself.
1312
*
14-
* @param <T> the reference type of the map
1513
* @author theEvilReaper
1614
* @version 1.0.0
1715
* @since 0.1.0
1816
*/
19-
public class SetupFinishEvent<T extends SetupData<? extends BaseMap>> implements Event, CancellableEvent {
17+
public class SetupFinishEvent implements Event, CancellableEvent {
2018

21-
private final @NotNull T setupData;
19+
private final SetupData setupData;
2220
private boolean cancelled;
2321

2422
/**
2523
* Creates a new instance of the {@link SetupFinishEvent} class.
2624
*
2725
* @param setupData the setup data of the event
2826
*/
29-
public SetupFinishEvent(@NotNull T setupData) {
27+
public SetupFinishEvent(@NotNull SetupData setupData) {
3028
this.setupData = setupData;
3129
}
3230

@@ -55,7 +53,7 @@ public boolean isCancelled() {
5553
*
5654
* @return the setup data
5755
*/
58-
public @NotNull T getData() {
56+
public @NotNull SetupData getData() {
5957
return setupData;
6058
}
6159
}

src/test/java/net/onelitefeather/guira/BasicDataTest.java renamed to src/test/java/net/onelitefeather/guira/BasicTestMapData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import static org.junit.jupiter.api.Assertions.assertFalse;
1212
import static org.junit.jupiter.api.Assertions.assertNotNull;
1313

14-
public abstract class BasicDataTest {
14+
public abstract class BasicTestMapData {
1515

1616
protected static Path tempDir;
1717
protected static MapEntry emptyMapEntry;
1818

1919
@BeforeAll
2020
static void beforeAll() throws URISyntaxException {
21-
tempDir = Paths.get(BasicDataTest.class.getResource("/emptyFolder").toURI());
21+
tempDir = Paths.get(BasicTestMapData.class.getResource("/emptyFolder").toURI());
2222
assertNotNull(tempDir, "The test class for the SetupData requires a folder with the name 'emptyFolder'");
2323
emptyMapEntry = MapEntry.of(tempDir);
2424
assertFalse(emptyMapEntry.hasMapFile(), "The emptyFolder for the test should not contain any files!");

0 commit comments

Comments
 (0)