Package jsonvalues
Class TryPatch<T extends Json<T>>
- java.lang.Object
-
- jsonvalues.TryPatch<T>
-
- Type Parameters:
T
- the type of the successful result of the computation
public final class TryPatch<T extends Json<T>> extends Object
Computation that applies a group of operations to a Json according to the RFC 6902 and may either result in a PatchMalformed or PatchOpError exceptions, or a successfully transformed json.
-
-
Constructor Summary
Constructors Constructor Description TryPatch(@NonNull T result)
TryPatch(PatchMalformed malformed)
TryPatch(PatchOpError opError)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TryPatch<T>
flatMap(Function<T,TryPatch<T>> fn)
if this TryPatch failed, it returns this instance, whereas if it didn't fail, it returns the TryPatch result of applying the given function to the result of this TryPatch.boolean
isFailure()
return true if the patch failedboolean
isMalformed()
return true if the patch couldn't be applied because an operation was malformed: a field was missing or it didn't have the expected schemaboolean
isOpError()
return true if the patch failed because an operation returned an error.boolean
isSuccess()
return true if the patch didn't failTryPatch<T>
map(UnaryOperator<T> fn)
if this TryPatch failed, it returns this instance, whereas if it didn't fail, it returns the result of this TryPatch mapped with the given function and wrapped in a TryPatch.T
orElseThrow()
Optional<T>
toOptional()
the result of the patch wrapped into an optional.
-
-
-
Constructor Detail
-
TryPatch
@EnsuresNonNull("#1") public TryPatch(PatchMalformed malformed)
-
TryPatch
@EnsuresNonNull("#1") public TryPatch(PatchOpError opError)
-
TryPatch
@EnsuresNonNull("#1") public TryPatch(@NonNull T result)
-
-
Method Detail
-
isSuccess
public boolean isSuccess()
return true if the patch didn't fail- Returns:
- true if the patch didn't fail
-
isFailure
public boolean isFailure()
return true if the patch failed- Returns:
- true if the patch failed
-
isMalformed
public boolean isMalformed()
return true if the patch couldn't be applied because an operation was malformed: a field was missing or it didn't have the expected schema- Returns:
- true if the patch couldn't be applied because an operation was malformed
-
isOpError
public boolean isOpError()
return true if the patch failed because an operation returned an error. Go to the RFC 6902 to see all the details.- Returns:
- true if the patch failed because some operation couldn't be applied
-
toOptional
public Optional<T> toOptional()
the result of the patch wrapped into an optional. If the patch failed, an Optional.empty() is returned- Returns:
- an Optional
-
orElseThrow
public T orElseThrow() throws PatchMalformed, PatchOpError
- Returns:
- the result of the patch it it didn't fail or throws the error
- Throws:
PatchMalformed
- if the patch couldn't be applied because the operations had a malformed schemaPatchOpError
- if the patch was applied but failed
-
flatMap
public TryPatch<T> flatMap(Function<T,TryPatch<T>> fn)
if this TryPatch failed, it returns this instance, whereas if it didn't fail, it returns the TryPatch result of applying the given function to the result of this TryPatch.- Parameters:
fn
- the given function that will be applied only if this patch didn't fail. The result of the flatMap operation will be the result of this function, if this TryPatch didn't fail- Returns:
- a TryPatch
-
map
public TryPatch<T> map(UnaryOperator<T> fn)
if this TryPatch failed, it returns this instance, whereas if it didn't fail, it returns the result of this TryPatch mapped with the given function and wrapped in a TryPatch.- Parameters:
fn
- the given function that will be applied only if this patch didn't fail. The result of the map operation will be the result of this function wrapped in a TryPatch- Returns:
- a TryPatch
-
-