Package org.spongepowered.api.data
Class Transaction<T extends DataSerializable>
- java.lang.Object
-
- org.spongepowered.api.data.Transaction<T>
-
- All Implemented Interfaces:
DataSerializable
- Direct Known Subclasses:
BlockTransaction,SlotTransaction
public class Transaction<T extends DataSerializable> extends Object implements DataSerializable
-
-
Constructor Summary
Constructors Constructor Description Transaction(T original, T defaultReplacement)Creates a new transaction.Transaction(T original, T defaultReplacement, @Nullable List<? extends T> intermediary)Creates a newTransactionwith the added possibility of intermediary transactions that may have taken place between what isoriginalandthe default result.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcontentVersion()Gets the content version of thisDataSerializable.Optional<T>custom()Gets the custom snapshot if one was set.TdefaultReplacement()Gets the default replacement snapshot.booleanequals(@Nullable Object obj)TfinalReplacement()Gets the proposed final snapshot, if thecustom()returnsOptional.isPresent(), the custom is returned, otherwise,defaultReplacement()is returned.inthashCode()List<? extends T>intermediary()Gets aListof any and all intermediary transactions that may have taken place to get the finalTransactionofthe originalandthe defaultresults.voidinvalidate()booleanisValid()Gets whether this transaction is marked as valid.Toriginal()Gets the original snapshot.voidsetCustom(@Nullable T custom)Sets the custom snapshot.voidsetValid(boolean valid)Sets whether this transaction is valid or not.DataContainertoContainer()Serializes this object into a comprehensibleDataContainer.StringtoString()voidvalidate()
-
-
-
Constructor Detail
-
Transaction
public Transaction(T original, T defaultReplacement)
Creates a new transaction.- Parameters:
original- The original object being replaceddefaultReplacement- The default replacement
-
Transaction
public Transaction(T original, T defaultReplacement, @Nullable List<? extends T> intermediary)
Creates a newTransactionwith the added possibility of intermediary transactions that may have taken place between what isoriginalandthe default result. The list may benull, however the list will wrapped to become an unmodifiable list.It is imperative that the provided list is not to be modified outside this created
Transactionsynchronously and asynchronously as consumers of the provided list will not be able to react accordingly.- Parameters:
original- The originaldefaultReplacement- The replacementintermediary- The intermediary results
-
-
Method Detail
-
original
public final T original()
Gets the original snapshot.- Returns:
- The original snapshot
-
defaultReplacement
public final T defaultReplacement()
Gets the default replacement snapshot.- Returns:
- The default replacement
-
intermediary
public final List<? extends T> intermediary()
Gets aListof any and all intermediary transactions that may have taken place to get the finalTransactionofthe originalandthe defaultresults. This is exposed for monitoring purposes only, as the provided list is not modifiable. The list may beemptyby default, but will never benull.Note that special processing with this list may sometimes only take place if
a customresult has not been set by a plugin, or ifisValid()returnsfalse.- Returns:
- The intermediary list of transactions
-
custom
public final Optional<T> custom()
Gets the custom snapshot if one was set.- Returns:
- The custom snapshot, if available
-
setCustom
public final void setCustom(@Nullable T custom)
Sets the custom snapshot. If settingnull, this will reset to use thedefaultReplacement()snapshot.- Parameters:
custom- The custom snapshot
-
finalReplacement
public final T finalReplacement()
Gets the proposed final snapshot, if thecustom()returnsOptional.isPresent(), the custom is returned, otherwise,defaultReplacement()is returned.- Returns:
- The proposed final snapshot
-
isValid
public final boolean isValid()
Gets whether this transaction is marked as valid.- Returns:
- The valid state of this transaction
-
setValid
public final void setValid(boolean valid)
Sets whether this transaction is valid or not.- Parameters:
valid- The valid state of this transaction
-
validate
public final void validate()
-
invalidate
public final void invalidate()
-
contentVersion
public int contentVersion()
Description copied from interface:DataSerializableGets the content version of thisDataSerializable. The version may differ between instances of plugins and implementations such that theDataViewfromDataSerializable.toContainer()may include different information, or remove other information as they are no longer deemed necessary. The version goes hand in hand withDataContentUpdateras it is required when there exists anyDataViewof thisDataSerializablewith an "older" version.- Specified by:
contentVersionin interfaceDataSerializable- Returns:
- The version of the content being serialized
-
toContainer
public DataContainer toContainer()
Description copied from interface:DataSerializableSerializes this object into a comprehensibleDataContainer.- Specified by:
toContainerin interfaceDataSerializable- Returns:
- A newly created DataContainer
-
-