2 * Copyright 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
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.
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.
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/>.
19 package gr.ebs.gss.client.rest.resource;
21 import java.io.Serializable;
23 import com.google.gwt.i18n.client.NumberFormat;
30 public class QuotaHolder implements Serializable{
31 private Long fileCount = 0L;
32 private Long fileSize = 0L;
33 private Long quotaLeftSize = 0L;
36 * Retrieve the fileCount.
38 * @return the fileCount
40 public Long getFileCount() {
45 * Modify the fileCount.
47 * @param aFileCount the fileCount to set
49 public void setFileCount(Long aFileCount) {
50 fileCount = aFileCount;
54 * Retrieve the fileSize.
56 * @return the fileSize
58 public Long getFileSize() {
63 * Modify the fileSize.
65 * @param aFileSize the fileSize to set
67 public void setFileSize(Long aFileSize) {
72 * Retrieve the quotaLeftSize.
74 * @return the quotaLeftSize
76 public Long getQuotaLeftSize() {
81 * Modify the quotaLeftSize.
83 * @param aQuotaLeftSize the quotaLeftSize to set
85 public void setQuotaLeftSize(Long aQuotaLeftSize) {
86 quotaLeftSize = aQuotaLeftSize;
89 public String getFileSizeAsString() {
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";
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";
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);
115 public long percentOfFreeSpace(){
116 return quotaLeftSize*100/(fileSize+quotaLeftSize);