Package org.spongepowered.api.data
Class DataTransactionResult
java.lang.Object
org.spongepowered.api.data.DataTransactionResult
Represents a transaction taking place where a
DataHolder.Mutable
is
accepting Value
s.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
A type of builder for buildingDataTransactionResult
s.static enum
The type of transaction result. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Gets a newDataTransactionResult.Builder
to build a newDataTransactionResult
.boolean
static DataTransactionResult
errorResult
(Value.Immutable<?> value) Creates a newDataTransactionResult
that ends in failure.static DataTransactionResult
Creates a newDataTransactionResult
that ends in failure.static DataTransactionResult
failResult
(Iterable<Value.Immutable<?>> values) Creates a newDataTransactionResult
that ends in failure.static DataTransactionResult
failResult
(Value.Immutable<?> value) Creates a newDataTransactionResult
that ends in failure.int
hashCode()
<E extends Exception>
voidifNotSuccessful
(Supplier<E> supplier) Used to call aSupplier
for anException
of typeE
such that if this transaction'sisSuccessful()
returnsfalse
, the supplier's exception is thrown.void
ifSuccessful
(Consumer<List<Value.Immutable<?>>> consumer) If this result ofisSuccessful()
returnstrue
, the providedConsumer
is called provided a list of all "successful" data as retrieved fromsuccessfulData()
.boolean
Gets whether thisDataTransactionResult
was successful or not.List<Value.Immutable<?>>
IfValue.Mutable
s were supplied to the operation, this collection will return anyValue.Immutable
s which were rejected by the targetDataHolder
.<T,
V extends Value<T>>
Optional<Value.Immutable<T>>rejectedValue
(Key<V> key) List<Value.Immutable<?>>
If the operation replaced anyValue.Mutable
s, this returns a collection of the replacedValue.Immutable
s.<T,
V extends Value<T>>
Optional<Value.Immutable<T>>replacedValue
(Key<V> key) List<Value.Immutable<?>>
If anyValue
s applied onto aDataHolder
were successful, they'll be stored in the given list.<T,
V extends Value<T>>
Optional<Value.Immutable<T>>successfulValue
(Key<V> key) static DataTransactionResult
Creates aDataTransactionResult
with no data successfully added, removed, or rejected, and with theDataTransactionResult.Type
ofDataTransactionResult.Type.SUCCESS
result type.static DataTransactionResult
successRemove
(Collection<Value.Immutable<?>> removed) Creates aDataTransactionResult
with the providedValue.Immutable
s being successfully removed.static DataTransactionResult
successRemove
(Value.Immutable<?> removed) Creates aDataTransactionResult
with the providedValue.Immutable
being successfully removed.static DataTransactionResult
successReplaceResult
(Collection<Value.Immutable<?>> successful, Collection<Value.Immutable<?>> replaced) Creates a newDataTransactionResult
with the providedValue.Immutable
s being the successful additions and the providedValue.Immutable
s that were replaced.static DataTransactionResult
successReplaceResult
(Value.Immutable<?> successful, Value.Immutable<?> replaced) Creates a newDataTransactionResult
with the providedValue.Immutable
being the successful addition.static DataTransactionResult
successResult
(Value.Immutable<?> value) Creates a newDataTransactionResult
with the providedValue.Immutable
being the successful addition.toString()
type()
Gets the type of result.
-
Method Details
-
toTransaction
public static Collector<DataTransactionResult,DataTransactionResult.Builder, toTransaction()DataTransactionResult> -
builder
Gets a newDataTransactionResult.Builder
to build a newDataTransactionResult
.- Returns:
- The new builder, for chaining
-
successNoData
Creates aDataTransactionResult
with no data successfully added, removed, or rejected, and with theDataTransactionResult.Type
ofDataTransactionResult.Type.SUCCESS
result type.- Returns:
- A clean and empty data transaction
-
successResult
Creates a newDataTransactionResult
with the providedValue.Immutable
being the successful addition. The result type is stillDataTransactionResult.Type.SUCCESS
. If aValue.Mutable
is necessary, useValue.Mutable
#asImmutable()} to use this method. ADataTransactionResult
is always immutable once created, and anyValue
s should be provided asValue.Immutable
s or transformed intoValue.Immutable
s.- Parameters:
value
- The successfully added immutable value- Returns:
- The new data transaction result
-
successReplaceResult
public static DataTransactionResult successReplaceResult(Value.Immutable<?> successful, Value.Immutable<?> replaced) Creates a newDataTransactionResult
with the providedValue.Immutable
being the successful addition. The result type is stillDataTransactionResult.Type.SUCCESS
. If aValue.Mutable
is necessary, useValue.Mutable
#asImmutable()} to use this method. ADataTransactionResult
is always immutable once created, and anyValue
s should be provided asValue.Immutable
s or transformed intoValue.Immutable
s.- Parameters:
successful
- The successfully added immutable valuereplaced
- The replaced value- Returns:
- The new data transaction result
-
successReplaceResult
public static DataTransactionResult successReplaceResult(Collection<Value.Immutable<?>> successful, Collection<Value.Immutable<?>> replaced) Creates a newDataTransactionResult
with the providedValue.Immutable
s being the successful additions and the providedValue.Immutable
s that were replaced. The result type is stillDataTransactionResult.Type.SUCCESS
. If aValue.Mutable
is necessary, useValue.Mutable
#asImmutable()} to use this method. ADataTransactionResult
is always immutable once created, and anyValue
s should be provided asValue.Immutable
s or transformed intoValue.Immutable
s.- Parameters:
successful
- The successfully added immutable valuesreplaced
- The successfully replaced immutable values- Returns:
- The new data transaction result
-
successRemove
Creates aDataTransactionResult
with the providedValue.Immutable
s being successfully removed. The result type is stillDataTransactionResult.Type.SUCCESS
. If aValue.Mutable
is necessary, useValue.Mutable
#asImmutable()} to use this method. ADataTransactionResult
is always immutable once created, and anyValue
s should be provided asValue.Immutable
s or transformed intoValue.Immutable
s.- Parameters:
removed
- The successfully removed values- Returns:
- The new data transaction result
-
successRemove
Creates aDataTransactionResult
with the providedValue.Immutable
being successfully removed. The result type is stillDataTransactionResult.Type.SUCCESS
. If aValue.Mutable
is necessary, useValue.Mutable
#asImmutable()} to use this method. ADataTransactionResult
is always immutable once created, and aValue
should be provided as anValue.Immutable
or transformed into anValue.Immutable
.- Parameters:
removed
- The successfully removed value- Returns:
- The new data transaction result
-
failResult
Creates a newDataTransactionResult
that ends in failure. The providedValue.Immutable
is considered "rejected" and was not successfully added.- Parameters:
value
- The value that was rejected- Returns:
- The new data transaction result
-
failResult
Creates a newDataTransactionResult
that ends in failure. The providedValue.Immutable
s are considered "rejected" and were not successfully added.- Parameters:
values
- The values that were rejected- Returns:
- The new data transaction result
-
failNoData
Creates a newDataTransactionResult
that ends in failure. There is no additional data to include.- Returns:
- The new data transaction result
-
errorResult
Creates a newDataTransactionResult
that ends in failure. The providedValue.Immutable
is considered "incompatible" and was not successfully added.- Parameters:
value
- The value that was incompatible or errored- Returns:
- The new data transaction result
-
type
Gets the type of result.- Returns:
- the type of result
-
isSuccessful
public boolean isSuccessful()Gets whether thisDataTransactionResult
was successful or not.- Returns:
- True if this result was successful
-
successfulData
If anyValue
s applied onto aDataHolder
were successful, they'll be stored in the given list.- Returns:
- An immutable list of the values successfully offered
-
successfulValue
- Type Parameters:
T
- The data typeV
- The value type- Parameters:
key
- The key- Returns:
- The value, if available
-
rejectedData
IfValue.Mutable
s were supplied to the operation, this collection will return anyValue.Immutable
s which were rejected by the targetDataHolder
.- Returns:
- Any data that was rejected from the operation
-
rejectedValue
- Type Parameters:
T
- The data typeV
- The value type- Parameters:
key
- The key- Returns:
- The value, if available
-
replacedData
If the operation replaced anyValue.Mutable
s, this returns a collection of the replacedValue.Immutable
s.- Returns:
- Any data that was replaced
-
replacedValue
- Type Parameters:
T
- The data typeV
- The value type- Parameters:
key
- The key- Returns:
- The value, if available
-
ifSuccessful
If this result ofisSuccessful()
returnstrue
, the providedConsumer
is called provided a list of all "successful" data as retrieved fromsuccessfulData()
.- Parameters:
consumer
- The consumer to call
-
ifNotSuccessful
Used to call aSupplier
for anException
of typeE
such that if this transaction'sisSuccessful()
returnsfalse
, the supplier's exception is thrown.- Type Parameters:
E
- The type of exception- Parameters:
supplier
- The supplier of the exception to throw- Throws:
E
- The exception to throw if this transaction is not successful
-
toString
-
equals
-
hashCode
public int hashCode()
-