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 ofDataBuilderthat 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 implementDataBuilderand implementDataContentUpdaters as necessary for future upgradeability of custom content.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDataBuilder(Class<T> requiredClass, int supportedVersion)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Optional<T>build(DataView container)Attempts to build the providedDataSerializablefrom the givenDataView.protected abstract Optional<T>buildContent(DataView container)Builds the currentlysupportedVersionvariant of the intendedDataSerializable, such that all content upgrades have already been handled bybuild(DataView).
-
-
-
Method Detail
-
buildContent
protected abstract Optional<T> buildContent(DataView container) throws InvalidDataException
Builds the currentlysupportedVersionvariant 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 Optional<T> build(DataView container) throws InvalidDataException
Description copied from interface:DataBuilderAttempts to build the providedDataSerializablefrom the givenDataView. If theDataViewis invalid or missing necessary information to complete building theDataSerializable,Optional.empty()may be returned.- Specified by:
buildin 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
-
-