Advertisement
Guest User

Static generic builder

a guest
Jul 21st, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. package su.ati.client.models.network;
  2.  
  3. public class ResponseWrapper<T> {
  4.     private final T responseBody;
  5.     private final String requestBody;
  6.     private final String errorBody;
  7.     private final String url;
  8.     private final int responseCode;
  9.  
  10.     private ResponseWrapper(T responseBody, String requestBody, String errorBody, String url, int responseCode) {
  11.         this.responseBody = responseBody;
  12.         this.requestBody = requestBody;
  13.         this.errorBody = errorBody;
  14.         this.url = url;
  15.         this.responseCode = responseCode;
  16.     }
  17.  
  18.     public T getResponseBody() {
  19.         return responseBody;
  20.     }
  21.  
  22.     public String getRequestBody() {
  23.         return requestBody;
  24.     }
  25.  
  26.     public String getErrorBody() {
  27.         return errorBody;
  28.     }
  29.  
  30.     public String getUrl() {
  31.         return url;
  32.     }
  33.  
  34.     public int getResponseCode() {
  35.         return responseCode;
  36.     }
  37.  
  38.     public static final class Builder<T> {
  39.         private T responseBody;
  40.         private String requestBody;
  41.         private String errorBody;
  42.         private String url;
  43.         private int responseCode;
  44.  
  45.         public Builder() {
  46.         }
  47.  
  48.         public Builder<T> responseBody(T responseBody) {
  49.             this.responseBody = responseBody;
  50.             return this;
  51.         }
  52.  
  53.         public Builder<T> requestBody(String requestBody) {
  54.             this.requestBody = requestBody;
  55.             return this;
  56.         }
  57.  
  58.         public Builder<T> errorBody(String errorBody) {
  59.             this.errorBody = errorBody;
  60.             return this;
  61.         }
  62.  
  63.         public Builder<T> url(String url) {
  64.             this.url = url;
  65.             return this;
  66.         }
  67.  
  68.         public Builder<T> responseCode(int responseCode) {
  69.             this.responseCode = responseCode;
  70.             return this;
  71.         }
  72.  
  73.         public ResponseWrapper<T> build() {
  74.             return new ResponseWrapper<>(responseBody, requestBody, errorBody, url, responseCode);
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement