Package org.spongepowered.api.data
Class DataTransactionResult
- java.lang.Object
-
- org.spongepowered.api.data.DataTransactionResult
-
public final class DataTransactionResult extends java.lang.ObjectRepresents a transaction taking place where aDataHolder.Mutableis acceptingValues.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataTransactionResult.BuilderA type of builder for buildingDataTransactionResults.static classDataTransactionResult.TypeThe type of transaction result.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DataTransactionResult.Builderbuilder()Gets a newDataTransactionResult.Builderto build a newDataTransactionResult.booleanequals(@Nullable java.lang.Object o)static DataTransactionResulterrorResult(Value.Immutable<?> value)Creates a newDataTransactionResultthat ends in failure.static DataTransactionResultfailNoData()Creates a newDataTransactionResultthat ends in failure.static DataTransactionResultfailResult(java.lang.Iterable<Value.Immutable<?>> values)Creates a newDataTransactionResultthat ends in failure.static DataTransactionResultfailResult(Value.Immutable<?> value)Creates a newDataTransactionResultthat ends in failure.inthashCode()<E extends java.lang.Exception>
voidifNotSuccessful(java.util.function.Supplier<E> supplier)Used to call aSupplierfor anExceptionof typeEsuch that if this transaction'sisSuccessful()returnsfalse, the supplier's exception is thrown.voidifSuccessful(java.util.function.Consumer<java.util.List<Value.Immutable<?>>> consumer)If this result ofisSuccessful()returnstrue, the providedConsumeris called provided a list of all "successful" data as retrieved fromsuccessfulData().booleanisSuccessful()Gets whether thisDataTransactionResultwas successful or not.java.util.List<Value.Immutable<?>>rejectedData()IfValue.Mutables were supplied to the operation, this collection will return anyValue.Immutables which were rejected by the targetDataHolder.<T,V extends Value<T>>
java.util.Optional<Value.Immutable<T>>rejectedValue(Key<V> key)java.util.List<Value.Immutable<?>>replacedData()If the operation replaced anyValue.Mutables, this returns a collection of the replacedValue.Immutables.<T,V extends Value<T>>
java.util.Optional<Value.Immutable<T>>replacedValue(Key<V> key)java.util.List<Value.Immutable<?>>successfulData()If anyValues applied onto aDataHolderwere successful, they'll be stored in the given list.<T,V extends Value<T>>
java.util.Optional<Value.Immutable<T>>successfulValue(Key<V> key)static DataTransactionResultsuccessNoData()Creates aDataTransactionResultwith no data successfully added, removed, or rejected, and with theDataTransactionResult.TypeofDataTransactionResult.Type.SUCCESSresult type.static DataTransactionResultsuccessRemove(java.util.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(java.util.Collection<Value.Immutable<?>> successful, java.util.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.java.lang.StringtoString()static java.util.stream.Collector<DataTransactionResult,DataTransactionResult.Builder,DataTransactionResult>toTransaction()DataTransactionResult.Typetype()Gets the type of result.
-
-
-
Method Detail
-
toTransaction
public static java.util.stream.Collector<DataTransactionResult,DataTransactionResult.Builder,DataTransactionResult> toTransaction()
-
builder
public static DataTransactionResult.Builder builder()
Gets a newDataTransactionResult.Builderto build a newDataTransactionResult.- Returns:
- The new builder, for chaining
-
successNoData
public static DataTransactionResult 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
public static DataTransactionResult successResult(Value.Immutable<?> value)
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(java.util.Collection<Value.Immutable<?>> successful, java.util.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
public static DataTransactionResult successRemove(java.util.Collection<Value.Immutable<?>> removed)
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
public static DataTransactionResult successRemove(Value.Immutable<?> removed)
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
public static DataTransactionResult failResult(Value.Immutable<?> value)
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
public static DataTransactionResult failResult(java.lang.Iterable<Value.Immutable<?>> values)
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
public static DataTransactionResult failNoData()
Creates a newDataTransactionResultthat 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 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
public DataTransactionResult.Type 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
public java.util.List<Value.Immutable<?>> 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
public <T,V extends Value<T>> java.util.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 java.util.List<Value.Immutable<?>> 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
public <T,V extends Value<T>> java.util.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 java.util.List<Value.Immutable<?>> replacedData()
If the operation replaced anyValue.Mutables, this returns a collection of the replacedValue.Immutables.- Returns:
- Any data that was replaced
-
replacedValue
public <T,V extends Value<T>> java.util.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(java.util.function.Consumer<java.util.List<Value.Immutable<?>>> consumer)
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
public <E extends java.lang.Exception> void ifNotSuccessful(java.util.function.Supplier<E> supplier) throws E extends java.lang.ExceptionUsed 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 successfulE extends java.lang.Exception
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(@Nullable java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-