Skip to content

Commit 6ff094e

Browse files
committed
Start the process to move MemoryDataView implementation to the implementation. Add DataContainer#createNew(). Fix compiler warnings.
Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
1 parent fb20c88 commit 6ff094e

24 files changed

+268
-242
lines changed

src/main/java/org/spongepowered/api/data/DataAlreadyRegisteredException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
public class DataAlreadyRegisteredException extends DataException {
3434

35+
private static final long serialVersionUID = 6644721737729647869L;
3536
@Nullable private final Class<? extends DataManipulator<?, ?>> manipulatorClass;
3637
@Nullable private final Class<? extends ImmutableDataManipulator<?, ?>> immutableManipulatorClass;
3738
@Nullable private final DataManipulatorBuilder<?, ?> builder;

src/main/java/org/spongepowered/api/data/DataContainer.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,32 @@
3131
* Represents a data structure that contains data. A DataContainer is
3232
* an object that can be considered a root {@link DataView}.
3333
*/
34+
@SuppressWarnings("deprecation")
3435
public interface DataContainer extends DataView {
3536

37+
/**
38+
* Creates a new {@link DataContainer} with a default
39+
* {@link org.spongepowered.api.data.DataView.SafetyMode} of
40+
* {@link org.spongepowered.api.data.DataView.SafetyMode#ALL_DATA_CLONED}.
41+
*
42+
* @return A new data container
43+
*/
44+
static DataContainer createNew() {
45+
return new MemoryDataContainer();
46+
}
47+
48+
/**
49+
* Creates a new {@link DataContainer} with the provided
50+
* {@link org.spongepowered.api.data.DataView.SafetyMode}.
51+
*
52+
* @param safety The safety mode to use
53+
* @see org.spongepowered.api.data.DataView.SafetyMode
54+
* @return A new data container with the provided safety mode
55+
*/
56+
static DataContainer createNew(SafetyMode safety) {
57+
return new MemoryDataContainer(safety);
58+
}
59+
3660
@Override
3761
DataContainer set(DataQuery path, Object value);
3862

src/main/java/org/spongepowered/api/data/DataException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
public class DataException extends RuntimeException {
2828

29+
private static final long serialVersionUID = -7843375998187638640L;
30+
2931
public DataException() {
3032
}
3133

src/main/java/org/spongepowered/api/data/DataRegistration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public interface DataRegistration<T extends DataManipulator<T, I>, I extends Imm
3838
* Creates a new {@link Builder} to build a {@link DataRegistration}.
3939
* Through the use of generics, this can be duck-typed to the generics of
4040
* the desired {@link DataManipulator} type to be registered.
41-
* @param <M> The type of data manipulator
42-
* @param <D> The type of immutable data manipulator
41+
*
4342
* @return The new builder instance
4443
*/
4544
@SuppressWarnings("unchecked")

src/main/java/org/spongepowered/api/data/DataRegistrationNotFoundException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
public class DataRegistrationNotFoundException extends DataException {
3333

34+
private static final long serialVersionUID = -1671720083547789746L;
3435
@Nullable private String registrationQuery;
3536
@Nullable private Class<? extends DataManipulator<?, ?>> manipulatorClass;
3637
@Nullable private Class<? extends ImmutableDataManipulator<?, ?>> immutableClass;

src/main/java/org/spongepowered/api/data/MemoryDataContainer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,22 @@
3535
* The default implementation of {@link DataContainer} that can be instantiated
3636
* for any use. This is the primary implementation of any {@link DataView} that
3737
* is used throughout both SpongeAPI and Sponge implementation.
38+
*
39+
* @deprecated To be removed in future releases to avoid implementation bugs
40+
* being part of the API.
3841
*/
42+
@SuppressWarnings("deprecation")
43+
@Deprecated
3944
public class MemoryDataContainer extends MemoryDataView implements DataContainer {
4045

4146
/**
4247
* Creates a new {@link MemoryDataContainer} with a default
4348
* {@link org.spongepowered.api.data.DataView.SafetyMode} of
4449
* {@link org.spongepowered.api.data.DataView.SafetyMode#ALL_DATA_CLONED}.
50+
*
51+
* @deprecated Use {@link DataContainer#createNew()}
4552
*/
53+
@Deprecated
4654
public MemoryDataContainer() {
4755
this(DataView.SafetyMode.ALL_DATA_CLONED);
4856
}
@@ -53,7 +61,10 @@ public MemoryDataContainer() {
5361
*
5462
* @param safety The safety mode to use
5563
* @see org.spongepowered.api.data.DataView.SafetyMode
64+
*
65+
* @deprecated Use {@link DataContainer#createNew(org.spongepowered.api.data.DataView.SafetyMode)}
5666
*/
67+
@Deprecated
5768
public MemoryDataContainer(DataView.SafetyMode safety) {
5869
super(safety);
5970
}

src/main/java/org/spongepowered/api/data/MemoryDataView.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858

5959
/**
6060
* Default implementation of a {@link DataView} being used in memory.
61+
* @deprecated To be moved to implementation to avoid implementation bugs
62+
* being existing in the API.
6163
*/
64+
@Deprecated
6265
public class MemoryDataView implements DataView {
6366

6467
protected final Map<String, Object> map = Maps.newLinkedHashMap();

src/main/java/org/spongepowered/api/data/Transaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public int getContentVersion() {
153153

154154
@Override
155155
public DataContainer toContainer() {
156-
final DataContainer container = new MemoryDataContainer()
156+
final DataContainer container = DataContainer.createNew()
157157
.set(Queries.CONTENT_VERSION, getContentVersion())
158158
.set(Queries.TYPE_CLASS, this.original.getClass().getName())
159159
.set(Queries.ORIGINAL, this.original)

src/main/java/org/spongepowered/api/data/manipulator/immutable/common/AbstractImmutableData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.google.common.collect.ImmutableSet;
3030
import com.google.common.collect.Maps;
3131
import org.spongepowered.api.data.DataContainer;
32-
import org.spongepowered.api.data.MemoryDataContainer;
3332
import org.spongepowered.api.data.Queries;
3433
import org.spongepowered.api.data.key.Key;
3534
import org.spongepowered.api.data.manipulator.DataManipulator;
@@ -162,7 +161,7 @@ public boolean equals(Object obj) {
162161

163162
@Override
164163
public DataContainer toContainer() {
165-
return new MemoryDataContainer()
164+
return DataContainer.createNew()
166165
.set(Queries.CONTENT_VERSION, getContentVersion());
167166
}
168167

src/main/java/org/spongepowered/api/data/manipulator/mutable/common/AbstractData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.google.common.collect.ImmutableSet;
3131
import com.google.common.collect.Maps;
3232
import org.spongepowered.api.data.DataContainer;
33-
import org.spongepowered.api.data.MemoryDataContainer;
3433
import org.spongepowered.api.data.Queries;
3534
import org.spongepowered.api.data.key.Key;
3635
import org.spongepowered.api.data.manipulator.DataManipulator;
@@ -209,7 +208,7 @@ public boolean equals(Object obj) {
209208

210209
@Override
211210
public DataContainer toContainer() {
212-
return new MemoryDataContainer()
211+
return DataContainer.createNew()
213212
.set(Queries.CONTENT_VERSION, getContentVersion());
214213
}
215214

0 commit comments

Comments
 (0)