root / src / gr / ebs / gss / client / rest / resource / QuotaHolder.java @ 3de51e55
History | View | Annotate | Download (2.8 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* GSS is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.client.rest.resource; |
20 |
|
21 |
import java.io.Serializable; |
22 |
|
23 |
import com.google.gwt.i18n.client.NumberFormat; |
24 |
|
25 |
|
26 |
/**
|
27 |
* @author kman
|
28 |
*
|
29 |
*/
|
30 |
public class QuotaHolder implements Serializable{ |
31 |
private Long fileCount = 0L; |
32 |
private Long fileSize = 0L; |
33 |
private Long quotaLeftSize = 0L; |
34 |
|
35 |
/**
|
36 |
* Retrieve the fileCount.
|
37 |
*
|
38 |
* @return the fileCount
|
39 |
*/
|
40 |
public Long getFileCount() { |
41 |
return fileCount;
|
42 |
} |
43 |
|
44 |
/**
|
45 |
* Modify the fileCount.
|
46 |
*
|
47 |
* @param aFileCount the fileCount to set
|
48 |
*/
|
49 |
public void setFileCount(Long aFileCount) { |
50 |
fileCount = aFileCount; |
51 |
} |
52 |
|
53 |
/**
|
54 |
* Retrieve the fileSize.
|
55 |
*
|
56 |
* @return the fileSize
|
57 |
*/
|
58 |
public Long getFileSize() { |
59 |
return fileSize;
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* Modify the fileSize.
|
64 |
*
|
65 |
* @param aFileSize the fileSize to set
|
66 |
*/
|
67 |
public void setFileSize(Long aFileSize) { |
68 |
fileSize = aFileSize; |
69 |
} |
70 |
|
71 |
/**
|
72 |
* Retrieve the quotaLeftSize.
|
73 |
*
|
74 |
* @return the quotaLeftSize
|
75 |
*/
|
76 |
public Long getQuotaLeftSize() { |
77 |
return quotaLeftSize;
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* Modify the quotaLeftSize.
|
82 |
*
|
83 |
* @param aQuotaLeftSize the quotaLeftSize to set
|
84 |
*/
|
85 |
public void setQuotaLeftSize(Long aQuotaLeftSize) { |
86 |
quotaLeftSize = aQuotaLeftSize; |
87 |
} |
88 |
|
89 |
public String getFileSizeAsString() { |
90 |
if (fileSize < 1024) |
91 |
return String.valueOf(fileSize) + " B"; |
92 |
else if (fileSize < 1024*1024) |
93 |
return getSize(fileSize, 1024D) + " KB"; |
94 |
else if (fileSize < 1024*1024*1024) |
95 |
return getSize(fileSize,(1024D*1024D)) + " MB"; |
96 |
return getSize(fileSize , (1024D*1024D*1024D)) + " GB"; |
97 |
} |
98 |
|
99 |
public String getQuotaLeftAsString() { |
100 |
if (quotaLeftSize < 1024) |
101 |
return String.valueOf(quotaLeftSize) + " B"; |
102 |
else if (quotaLeftSize < 1024*1024) |
103 |
return getSize(quotaLeftSize, 1024D) + " KB"; |
104 |
else if (quotaLeftSize < 1024*1024*1024) |
105 |
return getSize(quotaLeftSize,(1024D*1024D)) + " MB"; |
106 |
return getSize(quotaLeftSize , (1024D*1024D*1024D)) + " GB"; |
107 |
} |
108 |
|
109 |
private String getSize(Long size, Double division){ |
110 |
Double res = Double.valueOf(size.toString())/division; |
111 |
NumberFormat nf = NumberFormat.getFormat("######.#"); |
112 |
return nf.format(res);
|
113 |
} |
114 |
|
115 |
public long percentOfFreeSpace(){ |
116 |
return (long) ((double)quotaLeftSize*100/(fileSize+quotaLeftSize)+0.5); |
117 |
} |
118 |
} |