Skip to content

Instantly share code, notes, and snippets.

@anitaa1990
Created December 24, 2018 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anitaa1990/fb0f086e64ac7212a545feb068747aa1 to your computer and use it in GitHub Desktop.
Save anitaa1990/fb0f086e64ac7212a545feb068747aa1 to your computer and use it in GitHub Desktop.
public class Resource<T> {
@NonNull
public final Status status;
@Nullable
public final T data;
@Nullable public final String message;
private Resource(@NonNull Status status, @Nullable T data, @Nullable String message) {
this.status = status;
this.data = data;
this.message = message;
}
public static <T> Resource<T> success(@NonNull T data) {
return new Resource<>(SUCCESS, data, null);
}
public static <T> Resource<T> error(String msg, @Nullable T data) {
return new Resource<>(ERROR, data, msg);
}
public static <T> Resource<T> loading(@Nullable T data) {
return new Resource<>(LOADING, data, null);
}
public boolean isSuccess() {
return status == Status.SUCCESS && data != null;
}
public boolean isLoading() {
return status == Status.LOADING;
}
public boolean isLoaded() {
return status != Status.LOADING;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment