OSDN Git Service

785e21e5db91a8cd1be706bad6dd6dd567217664
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / model / Song.java
1 /*
2  * Copyright (C) 2012 Andrew Neal
3  * Copyright (C) 2014 The CyanogenMod Project
4  * Licensed under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
8  * or agreed to in writing, software distributed under the License is
9  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10  * KIND, either express or implied. See the License for the specific language
11  * governing permissions and limitations under the License.
12  */
13
14 package com.cyanogenmod.eleven.model;
15
16 import android.text.TextUtils;
17
18 /**
19  * A class that represents a song.
20  *
21  * @author Andrew Neal (andrewdneal@gmail.com)
22  */
23 public class Song {
24
25     /**
26      * The unique Id of the song
27      */
28     public long mSongId;
29
30     /**
31      * The song name
32      */
33     public String mSongName;
34
35     /**
36      * The song artist
37      */
38     public String mArtistName;
39
40     /**
41      * The song album
42      */
43     public String mAlbumName;
44
45     /**
46      * The album id
47      */
48     public long mAlbumId;
49
50     /**
51      * The song duration in seconds
52      */
53     public int mDuration;
54
55     /**
56      * The year the song was recorded
57      */
58     public int mYear;
59
60     /**
61      * Bucket label for the name - may not necessarily be the name - for example songs sorted by
62      * artists would be the artist bucket label and not the song name bucket label
63      */
64     public String mBucketLabel;
65
66     /**
67      * Constructor of <code>Song</code>
68      *
69      * @param songId The Id of the song
70      * @param songName The name of the song
71      * @param artistName The song artist
72      * @param albumName The song album
73      * @param duration The duration of a song in seconds
74      * @param year The year the song was recorded
75      */
76     public Song(final long songId, final String songName, final String artistName,
77             final String albumName, final long albumId, final int duration, final int year) {
78         mSongId = songId;
79         mSongName = songName;
80         mArtistName = artistName;
81         mAlbumName = albumName;
82         mAlbumId = albumId;
83         mDuration = duration;
84         mYear = year;
85     }
86
87     /**
88      * {@inheritDoc}
89      */
90     @Override
91     public int hashCode() {
92         final int prime = 31;
93         int result = 1;
94         result = prime * result + (mAlbumName == null ? 0 : mAlbumName.hashCode());
95         result = prime * result + (int) mAlbumId;
96         result = prime * result + (mArtistName == null ? 0 : mArtistName.hashCode());
97         result = prime * result + mDuration;
98         result = prime * result + (int) mSongId;
99         result = prime * result + (mSongName == null ? 0 : mSongName.hashCode());
100         result = prime * result + mYear;
101         return result;
102     }
103
104     /**
105      * {@inheritDoc}
106      */
107     @Override
108     public boolean equals(final Object obj) {
109         if (this == obj) {
110             return true;
111         }
112         if (obj == null) {
113             return false;
114         }
115         if (getClass() != obj.getClass()) {
116             return false;
117         }
118         final Song other = (Song)obj;
119         if (mSongId != other.mSongId) {
120             return false;
121         }
122         if (!TextUtils.equals(mAlbumName, other.mAlbumName)) {
123             return false;
124         }
125         if (mAlbumId != other.mAlbumId) {
126             return false;
127         }
128         if (!TextUtils.equals(mArtistName, other.mArtistName)) {
129             return false;
130         }
131         if (mDuration != other.mDuration) {
132             return false;
133         }
134         if (!TextUtils.equals(mSongName, other.mSongName)) {
135             return false;
136         }
137
138         if (mYear != other.mYear) {
139             return false;
140         }
141
142         return true;
143     }
144
145     /**
146      * {@inheritDoc}
147      */
148     @Override
149     public String toString() {
150         return mSongName;
151     }
152 }