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 Values.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA type of builder for buildingDataTransactionResults.static enumThe type of transaction result. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Gets a newDataTransactionResult.Builderto build a newDataTransactionResult.booleanstatic DataTransactionResulterrorResult(Value.Immutable<?> value) Creates a newDataTransactionResultthat ends in failure.static DataTransactionResultCreates a newDataTransactionResultthat ends in failure.static DataTransactionResultfailResult(Iterable<Value.Immutable<?>> values) Creates a newDataTransactionResultthat ends in failure.static DataTransactionResultfailResult(Value.Immutable<?> value) Creates a newDataTransactionResultthat ends in failure.inthashCode()<E extends Exception>
voidifNotSuccessful(Supplier<E> supplier) Used to call aSupplierfor anExceptionof typeEsuch that if this transaction'sisSuccessful()returnsfalse, the supplier's exception is thrown.voidifSuccessful(Consumer<List<Value.Immutable<?>>> consumer) If this result ofisSuccessful()returnstrue, the providedConsumeris called provided a list of all "successful" data as retrieved fromsuccessfulData().booleanGets whether thisDataTransactionResultwas successful or not.List<Value.Immutable<?>> IfValue.Mutables were supplied to the operation, this collection will return anyValue.Immutables 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.Mutables, this returns a collection of the replacedValue.Immutables.<T,V extends Value<T>>
Optional<Value.Immutable<T>> replacedValue(Key<V> key) List<Value.Immutable<?>> If anyValues applied onto aDataHolderwere successful, they'll be stored in the given list.<T,V extends Value<T>>
Optional<Value.Immutable<T>> successfulValue(Key<V> key) static DataTransactionResultCreates aDataTransactionResultwith no data successfully added, removed, or rejected, and with theDataTransactionResult.TypeofDataTransactionResult.Type.SUCCESSresult type.static DataTransactionResultsuccessRemove(Collection<Value.Immutable<?>> removed) Creates aDataTransactionResultwith the providedValue.Immutables being successfully removed.static DataTransactionResultsuccessRemove(Value.Immutable<?> removed) Creates aDataTransactionResultwith the providedValue.Immutablebeing successfully removed.static DataTransactionResultsuccessReplaceResult(Collection<Value.Immutable<?>> successful, Collection<Value.Immutable<?>> replaced) Creates a newDataTransactionResultwith the providedValue.Immutables being the successful additions and the providedValue.Immutables that were replaced.static DataTransactionResultsuccessReplaceResult(Value.Immutable<?> successful, Value.Immutable<?> replaced) Creates a newDataTransactionResultwith the providedValue.Immutablebeing the successful addition.static DataTransactionResultsuccessResult(Value.Immutable<?> value) Creates a newDataTransactionResultwith the providedValue.Immutablebeing 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.Builderto build a newDataTransactionResult.- Returns:
- The new builder, for chaining
-
successNoData
Creates aDataTransactionResultwith no data successfully added, removed, or rejected, and with theDataTransactionResult.TypeofDataTransactionResult.Type.SUCCESSresult type.- Returns:
- A clean and empty data transaction
-
successResult
Creates a newDataTransactionResultwith the providedValue.Immutablebeing the successful addition. The result type is stillDataTransactionResult.Type.SUCCESS. If aValue.Mutableis necessary, useValue.Mutable#asImmutable()} to use this method. ADataTransactionResultis always immutable once created, and anyValues should be provided asValue.Immutables or transformed intoValue.Immutables.- 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 newDataTransactionResultwith the providedValue.Immutablebeing the successful addition. The result type is stillDataTransactionResult.Type.SUCCESS. If aValue.Mutableis necessary, useValue.Mutable#asImmutable()} to use this method. ADataTransactionResultis always immutable once created, and anyValues should be provided asValue.Immutables or transformed intoValue.Immutables.- 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 newDataTransactionResultwith the providedValue.Immutables being the successful additions and the providedValue.Immutables that were replaced. The result type is stillDataTransactionResult.Type.SUCCESS. If aValue.Mutableis necessary, useValue.Mutable#asImmutable()} to use this method. ADataTransactionResultis always immutable once created, and anyValues should be provided asValue.Immutables or transformed intoValue.Immutables.- Parameters:
successful- The successfully added immutable valuesreplaced- The successfully replaced immutable values- Returns:
- The new data transaction result
-
successRemove
Creates aDataTransactionResultwith the providedValue.Immutables being successfully removed. The result type is stillDataTransactionResult.Type.SUCCESS. If aValue.Mutableis necessary, useValue.Mutable#asImmutable()} to use this method. ADataTransactionResultis always immutable once created, and anyValues should be provided asValue.Immutables or transformed intoValue.Immutables.- Parameters:
removed- The successfully removed values- Returns:
- The new data transaction result
-
successRemove
Creates aDataTransactionResultwith the providedValue.Immutablebeing successfully removed. The result type is stillDataTransactionResult.Type.SUCCESS. If aValue.Mutableis necessary, useValue.Mutable#asImmutable()} to use this method. ADataTransactionResultis always immutable once created, and aValueshould be provided as anValue.Immutableor transformed into anValue.Immutable.- Parameters:
removed- The successfully removed value- Returns:
- The new data transaction result
-
failResult
Creates a newDataTransactionResultthat ends in failure. The providedValue.Immutableis considered "rejected" and was not successfully added.- Parameters:
value- The value that was rejected- Returns:
- The new data transaction result
-
failResult
Creates a newDataTransactionResultthat ends in failure. The providedValue.Immutables are considered "rejected" and were not successfully added.- Parameters:
values- The values that were rejected- Returns:
- The new data transaction result
-
failNoData
Creates a newDataTransactionResultthat ends in failure. There is no additional data to include.- Returns:
- The new data transaction result
-
errorResult
Creates a newDataTransactionResultthat ends in failure. The providedValue.Immutableis 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 thisDataTransactionResultwas successful or not.- Returns:
- True if this result was successful
-
successfulData
If anyValues applied onto aDataHolderwere 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.Mutables were supplied to the operation, this collection will return anyValue.Immutables 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.Mutables, this returns a collection of the replacedValue.Immutables.- 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 providedConsumeris called provided a list of all "successful" data as retrieved fromsuccessfulData().- Parameters:
consumer- The consumer to call
-
ifNotSuccessful
Used to call aSupplierfor anExceptionof typeEsuch 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()
-