Skip to content

Package: Quota

Quota

nameinstructionbranchcomplexitylinemethod
Quota(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setResourceLimit(String, long)
M: 74 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2021 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: * @since JavaMail 1.4
27: * @author Bill Shannon
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:         /** The name of the resource. */
39:         public String name;
40:         /** The current usage of the resource. */
41:         public long usage;
42:         /** The usage limit for the resource. */
43:         public long limit;
44:
45:         /**
46:          * Construct a Resource object with the given name,
47:          * usage, and limit.
48:          *
49:          * @param        name        the resource name
50:          * @param        usage        the current usage of the resource
51:          * @param        limit        the usage limit for the resource
52:          */
53:         public Resource(String name, long usage, long limit) {
54:          this.name = name;
55:          this.usage = usage;
56:          this.limit = limit;
57:         }
58: }
59:
60: /**
61: * The name of the quota root.
62: */
63: public String quotaRoot;
64:
65: /**
66: * The set of resources associated with this quota root.
67: */
68: public Quota.Resource[] resources;
69:
70: /**
71: * Create a Quota object for the named quotaroot with no associated
72: * resources.
73: *
74: * @param        quotaRoot        the name of the quota root
75: */
76: public Quota(String quotaRoot) {
77:         this.quotaRoot = quotaRoot;
78: }
79:
80: /**
81: * Set a resource limit for this quota root.
82: *
83: * @param        name        the name of the resource
84: * @param        limit        the resource limit
85: */
86: public void setResourceLimit(String name, long limit) {
87:•        if (resources == null) {
88:          resources = new Quota.Resource[1];
89:          resources[0] = new Quota.Resource(name, 0, limit);
90:          return;
91:         }
92:•        for (int i = 0; i < resources.length; i++) {
93:•         if (resources[i].name.equalsIgnoreCase(name)) {
94:                 resources[i].limit = limit;
95:                 return;
96:          }
97:         }
98:         Quota.Resource[] ra = new Quota.Resource[resources.length + 1];
99:         System.arraycopy(resources, 0, ra, 0, resources.length);
100:         ra[ra.length - 1] = new Quota.Resource(name, 0, limit);
101:         resources = ra;
102: }
103: }