Package net.solarnetwork.domain
Class Result<T>
java.lang.Object
net.solarnetwork.domain.Result<T>
- Type Parameters:
T- the object type
A simple service result envelope object.
- Version:
- 1.2
- Author:
- matt
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionResult()Construct a successful response with no data.Constructor.Constructor.Construct a successful response with just data. -
Method Summary
Modifier and TypeMethodDescriptionstatic <V> Result<V>error()Helper method to construct an error instance using generic return type inference.static <V> Result<V>error(String code, String message, List<Result.ErrorDetail> errors) Helper method to construct an error instance using generic return type inference.static <V> Result<V>error(String code, String message, Result.ErrorDetail... errors) Helper method to construct an error instance using generic return type inference.static <V> Result<V>error(String message, List<Result.ErrorDetail> errors) Helper method to construct an error instance using generic return type inference.getCode()Get the code.getData()Get the data.Get the error details.Get the message.Get the success indicator.static <V> Result<V>result(V data) Helper method to construct instance using generic return type inference.static <V> Result<V>success()Helper method to construct a success instance using generic return type inference.static <V> Result<V>success(V data) Helper method to construct a success instance using generic return type inference.
-
Constructor Details
-
Result
public Result()Construct a successful response with no data. -
Result
Construct a successful response with just data.- Parameters:
data- the data
-
Result
Constructor.- Parameters:
success- flag of successcode- optional code, e.g. error codemessage- optional descriptive messagedata- optional data in the response
-
Result
public Result(Boolean success, String code, String message, List<Result.ErrorDetail> errors, T data) Constructor.- Parameters:
success- flag of successcode- optional code, e.g. error codemessage- optional descriptive messageerrors- optional errorsdata- optional data in the response- Since:
- 1.2
-
-
Method Details
-
result
Helper method to construct instance using generic return type inference.This is an alias for
success(Object). If you import this static method, then in your code you can writereturn result(myData)instead ofnew Result<Object>(myData).- Type Parameters:
V- the result type- Parameters:
data- the data- Returns:
- the result with
successset to true - See Also:
-
success
Helper method to construct a success instance using generic return type inference.If you import this static method, then in your code you can write
return success(myData)instead ofnew Result<Object>(myData).- Type Parameters:
V- the result type- Returns:
- the result with
successset to true - Since:
- 1.2
-
success
Helper method to construct a success instance using generic return type inference.- Type Parameters:
V- the result type- Returns:
- the result with
successset to true - Since:
- 1.2
-
error
Helper method to construct an error instance using generic return type inference.- Type Parameters:
V- the result type- Returns:
- the result
- Since:
- 1.2
-
error
Helper method to construct an error instance using generic return type inference.- Type Parameters:
V- the result type- Parameters:
message- the messageerrors- the errors- Returns:
- the result
- Since:
- 1.2
-
error
Helper method to construct an error instance using generic return type inference.- Type Parameters:
V- the result type- Parameters:
code- the codemessage- the messageerrors- the errors- Returns:
- the result
- Since:
- 1.2
-
error
Helper method to construct an error instance using generic return type inference.- Type Parameters:
V- the result type- Parameters:
code- the codemessage- the messageerrors- the errors- Returns:
- the result
- Since:
- 1.2
-
getSuccess
Get the success indicator.- Returns:
- the success indicator, or null if not known
-
getCode
Get the code.- Returns:
- the code, or null
-
getMessage
Get the message.- Returns:
- the message, or null
-
getErrors
Get the error details.- Returns:
- the error details, or null
-
getData
Get the data.- Returns:
- the data, or null
-