1 |
/* |
/* |
2 |
* $Id$ |
* Quota.java |
3 |
* Copyright (C) 2004 The Free Software Foundation |
* Copyright (C) 2004 The Free Software Foundation |
4 |
* |
* |
5 |
* This file is part of GNU inetlib, a library. |
* This file is part of GNU inetlib, a library. |
66 |
* @param name the resource name |
* @param name the resource name |
67 |
* @param limit the resource limit |
* @param limit the resource limit |
68 |
*/ |
*/ |
69 |
public Resource (String name, int limit) |
public Resource(String name, int limit) |
70 |
{ |
{ |
71 |
this (name, -1, limit); |
this(name, -1, limit); |
72 |
} |
} |
73 |
|
|
74 |
Resource (String name, int current, int limit) |
Resource(String name, int current, int limit) |
75 |
{ |
{ |
76 |
this.name = name; |
this.name = name; |
77 |
this.current = current; |
this.current = current; |
81 |
/** |
/** |
82 |
* Returns the resource name. |
* Returns the resource name. |
83 |
*/ |
*/ |
84 |
public String getName () |
public String getName() |
85 |
{ |
{ |
86 |
return name; |
return name; |
87 |
} |
} |
90 |
* Returns the current usage of the resource, or <code>-1</code> if not |
* Returns the current usage of the resource, or <code>-1</code> if not |
91 |
* known. |
* known. |
92 |
*/ |
*/ |
93 |
public int getCurrentUsage () |
public int getCurrentUsage() |
94 |
{ |
{ |
95 |
return current; |
return current; |
96 |
} |
} |
98 |
/** |
/** |
99 |
* Returns the resource limit. |
* Returns the resource limit. |
100 |
*/ |
*/ |
101 |
public int getLimit () |
public int getLimit() |
102 |
{ |
{ |
103 |
return limit; |
return limit; |
104 |
} |
} |
106 |
/** |
/** |
107 |
* Debugging. |
* Debugging. |
108 |
*/ |
*/ |
109 |
public String toString () |
public String toString() |
110 |
{ |
{ |
111 |
StringBuffer buf = new StringBuffer (); |
StringBuffer buf = new StringBuffer(); |
112 |
buf.append ('('); |
buf.append('('); |
113 |
buf.append (name); |
buf.append(name); |
114 |
if (current >= 0) |
if (current >= 0) |
115 |
{ |
{ |
116 |
buf.append (' '); |
buf.append(' '); |
117 |
buf.append (current); |
buf.append(current); |
118 |
} |
} |
119 |
buf.append (' '); |
buf.append(' '); |
120 |
buf.append (limit); |
buf.append(limit); |
121 |
buf.append (')'); |
buf.append(')'); |
122 |
return buf.toString (); |
return buf.toString(); |
123 |
} |
} |
124 |
|
|
125 |
} |
} |
127 |
String quotaRoot; |
String quotaRoot; |
128 |
List resources; |
List resources; |
129 |
|
|
130 |
Quota (String text) |
Quota(String text) |
131 |
{ |
{ |
132 |
int len = text.length (); |
int len = text.length(); |
133 |
List acc = new ArrayList (); |
List acc = new ArrayList(); |
134 |
Namespaces.parse (text, 0, len, acc); |
Namespaces.parse(text, 0, len, acc); |
135 |
|
|
136 |
quotaRoot = (String) acc.get (0); |
quotaRoot = (String) acc.get(0); |
137 |
resources = new ArrayList (); |
resources = new ArrayList(); |
138 |
len = acc.size (); |
len = acc.size(); |
139 |
for (int i = 1; i < len; i++) |
for (int i = 1; i < len; i++) |
140 |
{ |
{ |
141 |
resources.add (parseResource ((List) acc.get (i))); |
resources.add(parseResource((List) acc.get(i))); |
142 |
} |
} |
143 |
} |
} |
144 |
|
|
145 |
private Resource parseResource (List triple) |
private Resource parseResource(List triple) |
146 |
{ |
{ |
147 |
String name = (String) triple.get (0); |
String name = (String) triple.get(0); |
148 |
String current = (String) triple.get (1); |
String current = (String) triple.get(1); |
149 |
String limit = (String) triple.get (2); |
String limit = (String) triple.get(2); |
150 |
return new Resource (name, |
return new Resource(name, |
151 |
Integer.parseInt (current), |
Integer.parseInt(current), |
152 |
Integer.parseInt (limit)); |
Integer.parseInt(limit)); |
153 |
} |
} |
154 |
|
|
155 |
/** |
/** |
156 |
* Returns the quota root. All mailboxes that share the same named |
* Returns the quota root. All mailboxes that share the same named |
157 |
* quota root share the resource limits of the quota root. |
* quota root share the resource limits of the quota root. |
158 |
*/ |
*/ |
159 |
public String getQuotaRoot () |
public String getQuotaRoot() |
160 |
{ |
{ |
161 |
return quotaRoot; |
return quotaRoot; |
162 |
} |
} |
164 |
/** |
/** |
165 |
* Returns the list of quota resources. |
* Returns the list of quota resources. |
166 |
*/ |
*/ |
167 |
public Resource[] getResources () |
public Resource[] getResources() |
168 |
{ |
{ |
169 |
Resource[] ret = new Resource[resources.size ()]; |
Resource[] ret = new Resource[resources.size()]; |
170 |
resources.toArray (ret); |
resources.toArray(ret); |
171 |
return ret; |
return ret; |
172 |
} |
} |
173 |
|
|
174 |
/** |
/** |
175 |
* Debugging. |
* Debugging. |
176 |
*/ |
*/ |
177 |
public String toString () |
public String toString() |
178 |
{ |
{ |
179 |
StringBuffer buf = new StringBuffer (); |
StringBuffer buf = new StringBuffer(); |
180 |
buf.append (IMAPConnection.quote (UTF7imap.encode (quotaRoot))); |
buf.append(IMAPConnection.quote(UTF7imap.encode(quotaRoot))); |
181 |
int len = resources.size (); |
int len = resources.size(); |
182 |
for (int i = 0; i < len; i++) |
for (int i = 0; i < len; i++) |
183 |
{ |
{ |
184 |
buf.append (' '); |
buf.append(' '); |
185 |
buf.append (resources.get (i)); |
buf.append(resources.get(i)); |
186 |
} |
} |
187 |
return buf.toString (); |
return buf.toString(); |
188 |
} |
} |
189 |
|
|
190 |
} |
} |
191 |
|
|