1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package javax.mail; 21 22 /** 23 * A representation of a Quota item for a given quota root. 24 * 25 * @version $Rev: 578802 $ $Date: 2007-09-24 09:16:44 -0400 (Mon, 24 Sep 2007) $ 26 */ 27 public class Quota { 28 /** 29 * The name of the quota root. 30 */ 31 public String quotaRoot; 32 33 /** 34 * The resources associated with this quota root. 35 */ 36 public Resource[] resources; 37 38 39 /** 40 * Create a Quota with the given name and no resources. 41 * 42 * @param quotaRoot The quota root name. 43 */ 44 public Quota(String quotaRoot) { 45 this.quotaRoot = quotaRoot; 46 } 47 48 /** 49 * Set a limit value for a resource. If the resource is not 50 * currently associated with this Quota, a new Resource item is 51 * added to the resources list. 52 * 53 * @param name The target resource name. 54 * @param limit The new limit value for the resource. 55 */ 56 public void setResourceLimit(String name, long limit) { 57 Resource target = findResource(name); 58 target.limit = limit; 59 } 60 61 /** 62 * Locate a particular named resource, adding one to the list 63 * if it does not exist. 64 * 65 * @param name The target resource name. 66 * 67 * @return A Resource item for this named resource (either existing or new). 68 */ 69 private Resource findResource(String name) { 70 // no resources yet? Make it so. 71 if (resources == null) { 72 Resource target = new Resource(name, 0, 0); 73 resources = new Resource[] { target }; 74 return target; 75 } 76 77 // see if this one exists and return it. 78 for (int i = 0; i < resources.length; i++) { 79 Resource current = resources[i]; 80 if (current.name.equalsIgnoreCase(name)) { 81 return current; 82 } 83 } 84 85 // have to extend the array...this is a pain. 86 Resource[] newResources = new Resource[resources.length + 1]; 87 System.arraycopy(resources, 0, newResources, 0, resources.length); 88 Resource target = new Resource(name, 0, 0); 89 newResources[resources.length] = target; 90 resources = newResources; 91 return target; 92 } 93 94 95 96 /** 97 * A representation of a given resource definition. 98 */ 99 public static class Resource { 100 /** 101 * The resource name. 102 */ 103 public String name; 104 /** 105 * The current resource usage. 106 */ 107 public long usage; 108 /** 109 * The limit value for this resource. 110 */ 111 public long limit; 112 113 114 /** 115 * Construct a Resource object from the given name and usage/limit 116 * information. 117 * 118 * @param name The Resource name. 119 * @param usage The current resource usage. 120 * @param limit The Resource limit value. 121 */ 122 public Resource(String name, long usage, long limit) { 123 this.name = name; 124 this.usage = usage; 125 this.limit = limit; 126 } 127 } 128 }