美文网首页
通用代码

通用代码

作者: goforlondon | 来源:发表于2016-06-27 10:19 被阅读0次

AsyncTask返回封装与数据缓存

public class DataStructure {
    public static final class StInfo<T> {
        public boolean success;
        public T data;
        public int code;
        public String errMsg;

        public StInfo<T> success(T data) {
            this.success = true;
            this.data = data;
            return this;
        }

        public StInfo<T> fail(String reason) {
            return fail(reason, -1);
        }

        public StInfo<T> fail(String reason, int code) {
            this.success = false;
            this.errMsg = reason;
            this.code = code;
            return this;
        }
     }

     public static final class MemoryCacheItem<T> {
          public T data;
          public long cacheTime;

          public MemoryCacheItem<T> cache(T data) {
              this.data = data;
              this.cacheTime = new Date().getTime();
              return this;
          }

          public boolean isExpired() {
              return data == null || new Date().getTime() - cacheTime >= 5 * 60 * 1000;
          }
    }
}

相关文章

网友评论

      本文标题:通用代码

      本文链接:https://www.haomeiwen.com/subject/ylezdttx.html