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 /***
24 * Statistics class.
25 *
26 * @author Martin Vysny
27 */
28 public final class Statistics implements Serializable {
29 private static final long serialVersionUID = -6991284221227650772L;
30 /***
31 * Number of tracks.
32 */
33 public int tracks = 0;
34 /***
35 * Overall length in seconds.
36 */
37 public int length = 0;
38
39 /***
40 * Overall file size.
41 */
42 public long fileSize = 0;
43
44 /***
45 * Albums count.
46 */
47 public int albums = 0;
48
49 /***
50 * Artists count.
51 */
52 public int artists = 0;
53
54 /***
55 * Merge this object with another statistics object.
56 *
57 * @param other
58 * the other statistics.
59 */
60 public void add(final Statistics other) {
61 tracks += other.tracks;
62 length += other.length;
63 fileSize += other.fileSize;
64 albums += other.albums;
65 artists += other.artists;
66 }
67
68 /***
69 * Copies statistics from another statistics object.
70 *
71 * @param other
72 * the other statistics.
73 */
74 public void copyFrom(final Statistics other) {
75 tracks = other.tracks;
76 length = other.length;
77 fileSize = other.fileSize;
78 albums = other.albums;
79 artists = other.artists;
80 }
81
82 /***
83 * Computes average track length.
84 *
85 * @return average track length in seconds.
86 */
87 public int getAverageLength() {
88 if (tracks == 0)
89 return 0;
90 return length / tracks;
91 }
92 }