• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.net.Uri;
20 
21 import androidx.annotation.AnyThread;
22 import androidx.annotation.NonNull;
23 import androidx.annotation.Nullable;
24 
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
28 
29 @AnyThread
30 public class Artist {
31     private final long mId;
32 
33     // TODO(b/123706949) Lock mutable fields to ensure consistent updates
34     private String mName;
35     private String mDescription;
36     private Uri mHeadshotUri;
37     private final List<Album> mAlbums = new ArrayList<>();
38     private final List<Audio> mAudios = new ArrayList<>();
39     private boolean mLoaded;
40 
Artist(long id)41     Artist(long id) {
42         mId = id;
43     }
44 
getId()45     public long getId() {
46         return mId;
47     }
48 
getName()49     public @Nullable String getName() {
50         return mName;
51     }
52 
getAlbums()53     public @NonNull List<Album> getAlbums() {
54         return Collections.unmodifiableList(mAlbums);
55     }
56 
getAudios()57     public @NonNull List<Audio> getAudios() {
58         return Collections.unmodifiableList(mAudios);
59     }
60 
getHeadshotUri()61     public @Nullable Uri getHeadshotUri() {
62         return mHeadshotUri;
63     }
64 
getDescription()65     public @Nullable String getDescription() {
66         return mDescription;
67     }
68 
setHeadshotUri(@onNull Uri headshotUri)69     public boolean setHeadshotUri(@NonNull Uri headshotUri) {
70         if (headshotUri.equals(mHeadshotUri)) {
71             return false;
72         }
73         mHeadshotUri = headshotUri;
74         return true;
75     }
76 
setDescription(@onNull String description)77     public boolean setDescription(@NonNull String description) {
78         if (description.equals(mDescription)) {
79             return false;
80         }
81         mDescription = description;
82         return true;
83     }
84 
setName(@onNull String name)85     boolean setName(@NonNull String name) {
86         if (name.equals(mName)) {
87             return false;
88         }
89         mName = name;
90         return true;
91     }
92 
addAlbum(@onNull Album album)93     boolean addAlbum(@NonNull Album album) {
94         if (mAlbums.contains(album)) {
95             return false;
96         }
97         return mAlbums.add(album);
98     }
99 
addAudio(@onNull Audio audio)100     boolean addAudio(@NonNull Audio audio) {
101         if (mAudios.contains(audio)) {
102             return false;
103         }
104         return mAudios.add(audio);
105     }
106 
isLoaded()107     boolean isLoaded() {
108         return mLoaded;
109     }
110 
setLoaded()111     void setLoaded() {
112         mLoaded = true;
113     }
114 
115     @Override
equals(@ullable Object obj)116     public final boolean equals(@Nullable Object obj) {
117         return obj instanceof Artist && mId == ((Artist) obj).mId;
118     }
119 
120     @Override
hashCode()121     public final int hashCode() {
122         return (int) (mId ^ (mId >>> 32));
123     }
124 }
125