1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.work; 18 19 import android.support.annotation.NonNull; 20 21 import java.util.HashSet; 22 import java.util.List; 23 import java.util.Set; 24 import java.util.UUID; 25 26 /** 27 * A simple class with the id of a {@link WorkRequest}, its current {@link State}, output, and 28 * tags. Note that output is only available for terminal states ({@link State#SUCCEEDED} and 29 * {@link State#FAILED}). 30 */ 31 32 public final class WorkStatus { 33 34 private @NonNull UUID mId; 35 private @NonNull State mState; 36 private @NonNull Data mOutputData; 37 private @NonNull Set<String> mTags; 38 39 public WorkStatus( 40 @NonNull UUID id, 41 @NonNull State state, 42 @NonNull Data outputData, 43 @NonNull List<String> tags) { 44 mId = id; 45 mState = state; 46 mOutputData = outputData; 47 mTags = new HashSet<>(tags); 48 } 49 50 public @NonNull UUID getId() { 51 return mId; 52 } 53 54 public @NonNull State getState() { 55 return mState; 56 } 57 58 public @NonNull Data getOutputData() { 59 return mOutputData; 60 } 61 62 public @NonNull Set<String> getTags() { 63 return mTags; 64 } 65 66 @Override 67 public boolean equals(Object o) { 68 if (this == o) return true; 69 if (o == null || getClass() != o.getClass()) return false; 70 71 WorkStatus that = (WorkStatus) o; 72 73 if (mId != null ? !mId.equals(that.mId) : that.mId != null) return false; 74 if (mState != that.mState) return false; 75 if (mOutputData != null ? !mOutputData.equals(that.mOutputData) 76 : that.mOutputData != null) { 77 return false; 78 } 79 return mTags != null ? mTags.equals(that.mTags) : that.mTags == null; 80 } 81 82 @Override 83 public int hashCode() { 84 int result = mId != null ? mId.hashCode() : 0; 85 result = 31 * result + (mState != null ? mState.hashCode() : 0); 86 result = 31 * result + (mOutputData != null ? mOutputData.hashCode() : 0); 87 result = 31 * result + (mTags != null ? mTags.hashCode() : 0); 88 return result; 89 } 90 91 @Override 92 public String toString() { 93 return "WorkStatus{" 94 + "mId='" + mId + '\'' 95 + ", mState=" + mState 96 + ", mOutputData=" + mOutputData 97 + ", mTags=" + mTags 98 + '}'; 99 } 100 } 101