Package jsonvalues
Class TryObj
- java.lang.Object
-
- jsonvalues.TryObj
-
public final class TryObj extends Object
Computation that parses a string into a JsObj and may either result in a MalformedJson exception or a successfully parsed object.
-
-
Constructor Summary
Constructors Constructor Description TryObj(JsObj obj)
TryObj(MalformedJson error)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isFailure()
Returns true if the parsed string is a malformed json object.boolean
isSuccess()
Returns true if the parsed string is a well-formed json object.JsObj
orElse(Supplier<JsObj> other)
Returns the computed JsObj if the parsed string is a well-formed json object, returning the JsObj given by the supplier otherwise.JsObj
orElseThrow()
Returns the computed JsObj if the parsed string is a well-formed json object, throwing an exception otherwise.Optional<JsObj>
toOptional()
Returns the computed json object wrapped in an optional if the parsed string is a well-formed json object, returning an empty optional otherwise.
-
-
-
Constructor Detail
-
TryObj
@EnsuresNonNull("#1") public TryObj(JsObj obj)
-
TryObj
@EnsuresNonNull("#1") public TryObj(MalformedJson error)
-
-
Method Detail
-
isFailure
public boolean isFailure()
Returns true if the parsed string is a malformed json object.- Returns:
- true if the parsed string is a malformed json object
-
isSuccess
public boolean isSuccess()
Returns true if the parsed string is a well-formed json object.- Returns:
- true if the parsed string is a well-formed json object
-
toOptional
public Optional<JsObj> toOptional()
Returns the computed json object wrapped in an optional if the parsed string is a well-formed json object, returning an empty optional otherwise.- Returns:
- an Optional containing a JsObj or Optional.empty() if the given string is not a well-formed json object.
-
orElseThrow
public JsObj orElseThrow() throws MalformedJson
Returns the computed JsObj if the parsed string is a well-formed json object, throwing an exception otherwise.- Returns:
- a JsObj
- Throws:
MalformedJson
- if this try is a failure
-
-