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 java.lang.Object implements DataBuilder<T>
An abstract implementation ofDataBuilder
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 implementDataBuilder
and implementDataContentUpdater
s as necessary for future upgradeability of custom content.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDataBuilder(java.lang.Class<T> requiredClass, int supportedVersion)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.Optional<T>
build(DataView container)
Attempts to build the providedDataSerializable
from the givenDataView
.protected abstract java.util.Optional<T>
buildContent(DataView container)
Builds the currentlysupportedVersion
variant of the intendedDataSerializable
, such that all content upgrades have already been handled bybuild(DataView)
.
-
-
-
Constructor Detail
-
AbstractDataBuilder
protected AbstractDataBuilder(java.lang.Class<T> requiredClass, int supportedVersion)
-
-
Method Detail
-
buildContent
protected abstract java.util.Optional<T> buildContent(DataView container) throws InvalidDataException
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
public final java.util.Optional<T> build(DataView container) throws InvalidDataException
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
-
-