If you think the Android project Volley-Ball listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2011 The Android Open Source Project
*//www.java2s.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.siu.android.volleyball;
import com.android.volley.Cache;
import com.android.volley.Response;
import com.android.volley.VolleyError;
/**
* Encapsulates a parsed response for delivery.
*
* @param <T> Parsed type of this response
*/publicclass BallResponse<T> {
publicstaticenum ResponseSource {
LOCAL, CACHE, NETWORK
}
protected Response<T> mResponse;
protected ResponseSource mResponseSource;
protectedboolean mIdentical = false;
/**
* Returns whether this response is considered successful.
*/publicboolean isSuccess() {
return mResponse.isSuccess();
}
publicstatic <T> BallResponse<T> identical(ResponseSource responseSource) {
returnnew BallResponse<T>(Response.<T>success(null, null), responseSource, true);
}
publicstatic <T> BallResponse<T> success(T result) {
returnnew BallResponse<T>(Response.success(result, null));
}
publicstatic <T> BallResponse<T> success(T result, Cache.Entry cacheEntry) {
returnnew BallResponse<T>(Response.success(result, cacheEntry));
}
publicstatic <T> BallResponse<T> error(VolleyError error) {
returnnew BallResponse<T>(Response.<T>error(error), ResponseSource.NETWORK); // error cames always from network
}
protected BallResponse(Response<T> response) {
this(response, null, false);
}
protected BallResponse(Response<T> response, ResponseSource responseSource) {
this(response, responseSource, false);
}
public BallResponse(Response<T> response, ResponseSource responseSource, boolean identical) {
mResponse = response;
mResponseSource = responseSource;
mIdentical = identical;
}
public ResponseSource getResponseSource() {
return mResponseSource;
}
publicvoid setResponseSource(ResponseSource responseSource) {
this.mResponseSource = responseSource;
}
publicboolean isIntermediate() {
return mResponse.intermediate;
}
publicvoid setIntermediate(boolean intermediate) {
mResponse.intermediate = intermediate;
}
public T getResult() {
return mResponse.result;
}
public Cache.Entry getCacheEntry() {
return mResponse.cacheEntry;
}
public VolleyError getError() {
return mResponse.error;
}
publicboolean isIdentical() {
return mIdentical;
}
publicvoid setIdentical(boolean identical) {
mIdentical = identical;
}
}