1 /***
2 * Ambient - A music player for the Android platform
3 Copyright (C) 2007 Martin Vysny
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package sk.baka.ambient.collection;
20
21 import java.io.Serializable;
22
23 import sk.baka.ambient.commons.ThreadUnsafe;
24
25 /***
26 * Statistics class.
27 *
28 * @author Martin Vysny
29 */
30 @ThreadUnsafe
31 public final class Statistics implements Serializable {
32 private static final long serialVersionUID = -6991284221227650772L;
33 /***
34 * Number of tracks.
35 */
36 public int tracks = 0;
37 /***
38 * Overall length in seconds.
39 */
40 public int length = 0;
41
42 /***
43 * Overall file size.
44 */
45 public long fileSize = 0;
46
47 /***
48 * Albums count.
49 */
50 public int albums = 0;
51
52 /***
53 * Artists count.
54 */
55 public int artists = 0;
56
57 /***
58 * Merge this object with another statistics object.
59 *
60 * @param other
61 * the other statistics.
62 */
63 public void add(final Statistics other) {
64 tracks += other.tracks;
65 length += other.length;
66 fileSize += other.fileSize;
67 albums += other.albums;
68 artists += other.artists;
69 }
70
71 /***
72 * Copies statistics from another statistics object.
73 *
74 * @param other
75 * the other statistics.
76 */
77 public void copyFrom(final Statistics other) {
78 tracks = other.tracks;
79 length = other.length;
80 fileSize = other.fileSize;
81 albums = other.albums;
82 artists = other.artists;
83 }
84
85 /***
86 * Computes average track length.
87 *
88 * @return average track length in seconds.
89 */
90 public int getAverageLength() {
91 if (tracks == 0)
92 return 0;
93 return length / tracks;
94 }
95 }