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 com.android.pump.db;
18 
19 import androidx.annotation.AnyThread;
20 import androidx.annotation.NonNull;
21 import androidx.annotation.Nullable;
22 
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 
27 @AnyThread
28 public class Playlist {
29     private final long mId;
30 
31     // TODO(b/123706949) Lock mutable fields to ensure consistent updates
32     private String mName;
33     private final List<Audio> mAudios = new ArrayList<>();
34     private boolean mLoaded;
35 
Playlist(long id)36     Playlist(long id) {
37         mId = id;
38     }
39 
getId()40     public long getId() {
41         return mId;
42     }
43 
getName()44     public @Nullable String getName() {
45         return mName;
46     }
47 
getAudios()48     public @NonNull List<Audio> getAudios() {
49         return Collections.unmodifiableList(mAudios);
50     }
51 
setName(@onNull String name)52     boolean setName(@NonNull String name) {
53         if (name.equals(mName)) {
54             return false;
55         }
56         mName = name;
57         return true;
58     }
59 
addAudio(@onNull Audio audio)60     boolean addAudio(@NonNull Audio audio) {
61         if (mAudios.contains(audio)) {
62             return false;
63         }
64         return mAudios.add(audio);
65     }
66 
isLoaded()67     boolean isLoaded() {
68         return mLoaded;
69     }
70 
setLoaded()71     void setLoaded() {
72         mLoaded = true;
73     }
74 
75     @Override
equals(@ullable Object obj)76     public final boolean equals(@Nullable Object obj) {
77         return obj instanceof Playlist && mId == ((Playlist) obj).mId;
78     }
79 
80     @Override
hashCode()81     public final int hashCode() {
82         return (int) (mId ^ (mId >>> 32));
83     }
84 }
85