2 * Copyright (C) 2012 The CyanogenMod Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.cyanogenmod.filemanager.model;
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.List;
24 * A class that holds information about the usage of a disk (total, used and free space).
26 public class DiskUsage implements Serializable {
28 private static final long serialVersionUID = -4540446701543226294L;
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;
38 * Constructor of <code>DiskUsage</code>.
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
45 public DiskUsage(String mountPoint, long total, long used, long free) {
47 this.mMountPoint = mountPoint;
54 * Method that returns the mount point.
56 * @return String The mount point
58 public String getMountPoint() {
59 return this.mMountPoint;
63 * Method that returns the total amount of space.
65 * @return long The total amount of space
67 public long getTotal() {
72 * Method that returns the used amount of space.
74 * @return long The used amount of space
76 public long getUsed() {
81 * Method that returns the free amount of space.
83 * @return long The free amount of space
85 public long getFree() {
90 * Method that returns the total sum of all categories
92 * @return {@link java.lang.Long}
94 public long getCategorySum() {
96 for (DiskUsageCategory category : getUsageCategoryList()) {
97 bytes += category.getSizeBytes();
103 * Add a usage category
105 * @param category {@link com.cyanogenmod.filemanager.model.DiskUsageCategory} not null
107 * @throws IllegalArgumentException {@link java.lang.IllegalArgumentException}
109 public void addUsageCategory(DiskUsageCategory category) throws IllegalArgumentException {
110 if (category == null) {
111 throw new IllegalArgumentException("'category' cannot be null!");
113 mDiskUsageCategoryList.add(category);
116 public List<DiskUsageCategory> getUsageCategoryList() {
117 return mDiskUsageCategoryList;
121 * Clears the list of usage categories
123 public void clearUsageCategories() {
124 mDiskUsageCategoryList.clear();
131 public int hashCode() {
132 final int prime = 31;
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));
145 public boolean equals(Object obj) {
152 if (getClass() != obj.getClass()) {
155 DiskUsage other = (DiskUsage) obj;
156 if (this.mFree != other.mFree) {
159 if (this.mMountPoint == null) {
160 if (other.mMountPoint != null) {
163 } else if (!this.mMountPoint.equals(other.mMountPoint)) {
166 if (this.mTotal != other.mTotal) {
169 if (this.mUsed != other.mUsed) {
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$