Class AbstractDataBuilder<T extends DataSerializable>
java.lang.Object
org.spongepowered.api.data.persistence.AbstractDataBuilder<T>
- Type Parameters:
T
- The type of DataSerializable
- All Implemented Interfaces:
DataBuilder<T>
- Direct Known Subclasses:
Color.Builder
,RespawnLocation.Builder
public abstract class AbstractDataBuilder<T extends DataSerializable>
extends Object
implements DataBuilder<T>
An abstract implementation of
DataBuilder
that pre-defines all of
the necessary "content update" implementation required for content
versioning. Note that the builder itself is versioned to ensure that
content versioning is appropriately handled. It is highly recommended to
extend this class to implement DataBuilder
and implement
DataContentUpdater
s as necessary for future upgradeability of
custom content.-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractDataBuilder
(Class<T> requiredClass, int supportedVersion) -
Method Summary
Modifier and TypeMethodDescriptionAttempts to build the providedDataSerializable
from the givenDataView
.buildContent
(DataView container) Builds the currentlysupportedVersion
variant of the intendedDataSerializable
, such that all content upgrades have already been handled bybuild(DataView)
.
-
Constructor Details
-
AbstractDataBuilder
-
-
Method Details
-
buildContent
Builds the currentlysupportedVersion
variant of the intendedDataSerializable
, such that all content upgrades have already been handled bybuild(DataView)
. This otherwise follows the same contract asDataBuilder.build(DataView)
.- Parameters:
container
- The container with data to build from- Returns:
- The deserialized data serializable, if possible
- Throws:
InvalidDataException
- If there's issues of invalid data formats or invalid data
-
build
Description copied from interface:DataBuilder
Attempts to build the providedDataSerializable
from the givenDataView
. If theDataView
is invalid or missing necessary information to complete building theDataSerializable
,Optional.empty()
may be returned.- Specified by:
build
in interfaceDataBuilder<T extends DataSerializable>
- Parameters:
container
- The container containing all necessary data- Returns:
- The instance of the
DataSerializable
, if successful - Throws:
InvalidDataException
- In the event that the builder is unable to properly construct the data serializable from the data view
-