Package org.spongepowered.api.data
Class DataTransactionResult
- java.lang.Object
-
- org.spongepowered.api.data.DataTransactionResult
-
public final class DataTransactionResult extends Object
Represents a transaction taking place where aDataHolder.Mutable
is acceptingValue
s.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataTransactionResult.Builder
A type of builder for buildingDataTransactionResult
s.static class
DataTransactionResult.Type
The type of transaction result.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DataTransactionResult.Builder
builder()
Gets a newDataTransactionResult.Builder
to build a newDataTransactionResult
.boolean
equals(@Nullable Object o)
static DataTransactionResult
errorResult(Value.Immutable<?> value)
Creates a newDataTransactionResult
that ends in failure.static DataTransactionResult
failNoData()
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
isSuccessful()
Gets whether thisDataTransactionResult
was successful or not.List<Value.Immutable<?>>
rejectedData()
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<?>>
replacedData()
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<?>>
successfulData()
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
successNoData()
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.String
toString()
static Collector<DataTransactionResult,DataTransactionResult.Builder,DataTransactionResult>
toTransaction()
DataTransactionResult.Type
type()
Gets the type of result.
-
-
-
Method Detail
-
toTransaction
public static Collector<DataTransactionResult,DataTransactionResult.Builder,DataTransactionResult> toTransaction()
-
builder
public static DataTransactionResult.Builder builder()
Gets a newDataTransactionResult.Builder
to build a newDataTransactionResult
.- Returns:
- The new builder, for chaining
-
successNoData
public static DataTransactionResult 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
public static DataTransactionResult successResult(Value.Immutable<?> value)
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
public static DataTransactionResult successRemove(Collection<Value.Immutable<?>> removed)
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
public static DataTransactionResult successRemove(Value.Immutable<?> removed)
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
public static DataTransactionResult failResult(Value.Immutable<?> value)
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
public static DataTransactionResult failResult(Iterable<Value.Immutable<?>> values)
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
public static DataTransactionResult failNoData()
Creates a newDataTransactionResult
that ends in failure. There is no additional data to include.- Returns:
- The new data transaction result
-
errorResult
public static DataTransactionResult errorResult(Value.Immutable<?> value)
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
public DataTransactionResult.Type 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
public List<Value.Immutable<?>> 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
public <T,V extends Value<T>> Optional<Value.Immutable<T>> successfulValue(Key<V> key)
- Type Parameters:
T
- The data typeV
- The value type- Parameters:
key
- The key- Returns:
- The value, if available
-
rejectedData
public List<Value.Immutable<?>> 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
public <T,V extends Value<T>> Optional<Value.Immutable<T>> rejectedValue(Key<V> key)
- Type Parameters:
T
- The data typeV
- The value type- Parameters:
key
- The key- Returns:
- The value, if available
-
replacedData
public List<Value.Immutable<?>> replacedData()
If the operation replaced anyValue.Mutable
s, this returns a collection of the replacedValue.Immutable
s.- Returns:
- Any data that was replaced
-
replacedValue
public <T,V extends Value<T>> Optional<Value.Immutable<T>> replacedValue(Key<V> key)
- Type Parameters:
T
- The data typeV
- The value type- Parameters:
key
- The key- Returns:
- The value, if available
-
ifSuccessful
public 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()
.- Parameters:
consumer
- The consumer to call
-
ifNotSuccessful
public <E extends Exception> void ifNotSuccessful(Supplier<E> supplier) throws E extends Exception
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 successfulE extends Exception
-
-