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