• 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 androidx.annotation.AnyThread;
20 import androidx.annotation.NonNull;
21 import androidx.annotation.Nullable;
22 
23 @AnyThread
24 public class Audio {
25     private final long mId;
26     private final String mMimeType;
27 
28     // TODO(b/123706949) Lock mutable fields to ensure consistent updates
29     private String mTitle;
30     private Artist mArtist;
31     private Album mAlbum;
32     private boolean mLoaded;
33 
Audio(long id, @NonNull String mimeType)34     Audio(long id, @NonNull String mimeType) {
35         mId = id;
36         mMimeType = mimeType;
37     }
38 
getId()39     public long getId() {
40         return mId;
41     }
42 
getMimeType()43     public @NonNull String getMimeType() {
44         return mMimeType;
45     }
46 
getTitle()47     public @Nullable String getTitle() {
48         return mTitle;
49     }
50 
getArtist()51     public @Nullable Artist getArtist() {
52         return mArtist;
53     }
54 
getAlbum()55     public @Nullable Album getAlbum() {
56         return mAlbum;
57     }
58 
setTitle(@onNull String title)59     boolean setTitle(@NonNull String title) {
60         if (title.equals(mTitle)) {
61             return false;
62         }
63         mTitle = title;
64         return true;
65     }
66 
setArtist(@onNull Artist artist)67     boolean setArtist(@NonNull Artist artist) {
68         if (artist.equals(mArtist)) {
69             return false;
70         }
71         mArtist = artist;
72         return true;
73     }
74 
setAlbum(@onNull Album album)75     boolean setAlbum(@NonNull Album album) {
76         if (album.equals(mAlbum)) {
77             return false;
78         }
79         mAlbum = album;
80         return true;
81     }
82 
isLoaded()83     boolean isLoaded() {
84         return mLoaded;
85     }
86 
setLoaded()87     void setLoaded() {
88         mLoaded = true;
89     }
90 
91     @Override
equals(@ullable Object obj)92     public final boolean equals(@Nullable Object obj) {
93         return obj instanceof Audio && mId == ((Audio) obj).mId;
94     }
95 
96     @Override
hashCode()97     public final int hashCode() {
98         return (int) (mId ^ (mId >>> 32));
99     }
100 }
101