Skip to content

Package: Quota$Resource

Quota$Resource

nameinstructionbranchcomplexitylinemethod
Quota.Resource(String, long, long)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package jakarta.mail;
18:
19: /**
20: * This class represents a set of quotas for a given quota root.
21: * Each quota root has a set of resources, represented by the
22: * <code>Quota.Resource</code> class. Each resource has a name
23: * (for example, "STORAGE"), a current usage, and a usage limit.
24: * See RFC 2087.
25: *
26: * @author Bill Shannon
27: * @since JavaMail 1.4
28: */
29:
30: public class Quota {
31:
32: /**
33: * An individual resource in a quota root.
34: *
35: * @since JavaMail 1.4
36: */
37: public static class Resource {
38: /**
39: * The name of the resource.
40: */
41: public String name;
42: /**
43: * The current usage of the resource.
44: */
45: public long usage;
46: /**
47: * The usage limit for the resource.
48: */
49: public long limit;
50:
51: /**
52: * Construct a Resource object with the given name,
53: * usage, and limit.
54: *
55: * @param name the resource name
56: * @param usage the current usage of the resource
57: * @param limit the usage limit for the resource
58: */
59: public Resource(String name, long usage, long limit) {
60: this.name = name;
61: this.usage = usage;
62: this.limit = limit;
63: }
64: }
65:
66: /**
67: * The name of the quota root.
68: */
69: public String quotaRoot;
70:
71: /**
72: * The set of resources associated with this quota root.
73: */
74: public Quota.Resource[] resources;
75:
76: /**
77: * Create a Quota object for the named quotaroot with no associated
78: * resources.
79: *
80: * @param quotaRoot the name of the quota root
81: */
82: public Quota(String quotaRoot) {
83: this.quotaRoot = quotaRoot;
84: }
85:
86: /**
87: * Set a resource limit for this quota root.
88: *
89: * @param name the name of the resource
90: * @param limit the resource limit
91: */
92: public void setResourceLimit(String name, long limit) {
93: if (resources == null) {
94: resources = new Quota.Resource[1];
95: resources[0] = new Quota.Resource(name, 0, limit);
96: return;
97: }
98: for (int i = 0; i < resources.length; i++) {
99: if (resources[i].name.equalsIgnoreCase(name)) {
100: resources[i].limit = limit;
101: return;
102: }
103: }
104: Quota.Resource[] ra = new Quota.Resource[resources.length + 1];
105: System.arraycopy(resources, 0, ra, 0, resources.length);
106: ra[ra.length - 1] = new Quota.Resource(name, 0, limit);
107: resources = ra;
108: }
109: }