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 newTransaction
with the added possibility of intermediary transactions that may have taken place between what isoriginal
andthe default result
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
contentVersion()
Gets the content version of thisDataSerializable
.Optional<T>
custom()
Gets the custom snapshot if one was set.T
defaultReplacement()
Gets the default replacement snapshot.boolean
equals(@Nullable Object obj)
T
finalReplacement()
Gets the proposed final snapshot, if thecustom()
returnsOptional.isPresent()
, the custom is returned, otherwise,defaultReplacement()
is returned.int
hashCode()
List<? extends T>
intermediary()
Gets aList
of any and all intermediary transactions that may have taken place to get the finalTransaction
ofthe original
andthe default
results.void
invalidate()
boolean
isValid()
Gets whether this transaction is marked as valid.T
original()
Gets the original snapshot.void
setCustom(@Nullable T custom)
Sets the custom snapshot.void
setValid(boolean valid)
Sets whether this transaction is valid or not.DataContainer
toContainer()
Serializes this object into a comprehensibleDataContainer
.String
toString()
void
validate()
-
-
-
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 newTransaction
with the added possibility of intermediary transactions that may have taken place between what isoriginal
andthe 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
Transaction
synchronously 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 aList
of any and all intermediary transactions that may have taken place to get the finalTransaction
ofthe original
andthe default
results. This is exposed for monitoring purposes only, as the provided list is not modifiable. The list may beempty
by default, but will never benull
.Note that special processing with this list may sometimes only take place if
a custom
result 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:DataSerializable
Gets the content version of thisDataSerializable
. The version may differ between instances of plugins and implementations such that theDataView
fromDataSerializable.toContainer()
may include different information, or remove other information as they are no longer deemed necessary. The version goes hand in hand withDataContentUpdater
as it is required when there exists anyDataView
of thisDataSerializable
with an "older" version.- Specified by:
contentVersion
in interfaceDataSerializable
- Returns:
- The version of the content being serialized
-
toContainer
public DataContainer toContainer()
Description copied from interface:DataSerializable
Serializes this object into a comprehensibleDataContainer
.- Specified by:
toContainer
in interfaceDataSerializable
- Returns:
- A newly created DataContainer
-
-