OSDN Git Service

CMFileManager: add usage stats by mime type
[android-x86/packages-apps-CMFileManager.git] / src / com / cyanogenmod / filemanager / model / DiskUsage.java
1 /*
2  * Copyright (C) 2012 The CyanogenMod 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.cyanogenmod.filemanager.model;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 /**
24  * A class that holds information about the usage of a disk (total, used and free space).
25  */
26 public class DiskUsage implements Serializable {
27
28     private static final long serialVersionUID = -4540446701543226294L;
29
30     private final List<DiskUsageCategory> mDiskUsageCategoryList =
31             new ArrayList<DiskUsageCategory>();
32     private final String mMountPoint;
33     private final long mTotal;
34     private final long mUsed;
35     private final long mFree;
36
37     /**
38      * Constructor of <code>DiskUsage</code>.
39      *
40      * @param mountPoint The mount point
41      * @param total The total amount of space
42      * @param used The used amount of space
43      * @param free The free amount of space
44      */
45     public DiskUsage(String mountPoint, long total, long used, long free) {
46         super();
47         this.mMountPoint = mountPoint;
48         this.mTotal = total;
49         this.mUsed = used;
50         this.mFree = free;
51     }
52
53     /**
54      * Method that returns the mount point.
55      *
56      * @return String The mount point
57      */
58     public String getMountPoint() {
59         return this.mMountPoint;
60     }
61
62     /**
63      * Method that returns the total amount of space.
64      *
65      * @return long The total amount of space
66      */
67     public long getTotal() {
68         return this.mTotal;
69     }
70
71     /**
72      * Method that returns the used amount of space.
73      *
74      * @return long The used amount of space
75      */
76     public long getUsed() {
77         return this.mUsed;
78     }
79
80     /**
81      * Method that returns the free amount of space.
82      *
83      * @return long The free amount of space
84      */
85     public long getFree() {
86         return this.mFree;
87     }
88
89     /**
90      * Method that returns the total sum of all categories
91      *
92      * @return {@link java.lang.Long}
93      */
94     public long getCategorySum() {
95         long bytes = 0;
96         for (DiskUsageCategory category : getUsageCategoryList()) {
97             bytes += category.getSizeBytes();
98         }
99         return bytes;
100     }
101
102     /**
103      * Add a usage category
104      *
105      * @param category {@link com.cyanogenmod.filemanager.model.DiskUsageCategory} not null
106      *
107      * @throws IllegalArgumentException {@link java.lang.IllegalArgumentException}
108      */
109     public void addUsageCategory(DiskUsageCategory category) throws IllegalArgumentException {
110         if (category == null) {
111             throw new IllegalArgumentException("'category' cannot be null!");
112         }
113         mDiskUsageCategoryList.add(category);
114     }
115
116     public List<DiskUsageCategory> getUsageCategoryList() {
117         return mDiskUsageCategoryList;
118     }
119
120     /**
121      * Clears the list of usage categories
122      */
123     public void clearUsageCategories() {
124         mDiskUsageCategoryList.clear();
125     }
126
127     /**
128      * {@inheritDoc}
129      */
130     @Override
131     public int hashCode() {
132         final int prime = 31;
133         int result = 1;
134         result = prime * result + (int) (this.mFree ^ (this.mFree >>> 32));
135         result = prime * result + ((this.mMountPoint == null) ? 0 : this.mMountPoint.hashCode());
136         result = prime * result + (int) (this.mTotal ^ (this.mTotal >>> 32));
137         result = prime * result + (int) (this.mUsed ^ (this.mUsed >>> 32));
138         return result;
139     }
140
141     /**
142      * {@inheritDoc}
143      */
144     @Override
145     public boolean equals(Object obj) {
146         if (this == obj) {
147             return true;
148         }
149         if (obj == null) {
150             return false;
151         }
152         if (getClass() != obj.getClass()) {
153             return false;
154         }
155         DiskUsage other = (DiskUsage) obj;
156         if (this.mFree != other.mFree) {
157             return false;
158         }
159         if (this.mMountPoint == null) {
160             if (other.mMountPoint != null) {
161                 return false;
162             }
163         } else if (!this.mMountPoint.equals(other.mMountPoint)) {
164             return false;
165         }
166         if (this.mTotal != other.mTotal) {
167             return false;
168         }
169         if (this.mUsed != other.mUsed) {
170             return false;
171         }
172         return true;
173     }
174
175     /**
176      * {@inheritDoc}
177      */
178     @Override
179     public String toString() {
180         return "DiskUsage [mMountPoint=" + this.mMountPoint //$NON-NLS-1$
181                 + ", mTotal=" + this.mTotal + //$NON-NLS-1$
182                 ", mUsed=" + this.mUsed + ", mFree=" //$NON-NLS-1$ //$NON-NLS-2$
183                 + this.mFree + "]";  //$NON-NLS-1$
184     }
185
186 }