1 /*
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
178 * that matches the specified key.
179 * @param key the AccessibleRelation key
180 * @return true if the relation is in the relation set; otherwise false
181 */
182 public boolean contains(String key) {
183 return get(key) != null;
184 }
185
186 /**
187 * Returns the relation that matches the specified key.
188 * @param key the AccessibleRelation key
189 * @return the relation, if one exists, that matches the specified key.
190 * Otherwise, null is returned.
191 */
192 public AccessibleRelation get(String key) {
193 if (relations == null) {
194 return null;
195 } else {
196 int len = relations.size();
197 for (int i = 0; i < len; i++) {
198 AccessibleRelation relation =
199 (AccessibleRelation)relations.elementAt(i);
200 if (relation != null && relation.getKey().equals(key)) {
201 return relation;
202 }
203 }
204 return null;
205 }
206 }
207
208 /**
209 * Returns the current relation set as an array of AccessibleRelation
210 * @return AccessibleRelation array contacting the current relation.
211 */
212 public AccessibleRelation[] toArray() {
213 if (relations == null) {
214 return new AccessibleRelation[0];
215 } else {
216 AccessibleRelation[] relationArray
217 = new AccessibleRelation[relations.size()];
218 for (int i = 0; i < relationArray.length; i++) {
219 relationArray[i] = (AccessibleRelation) relations.elementAt(i);
220 }
221 return relationArray;
222 }
223 }
224
225 /**
226 * Creates a localized String representing all the relations in the set
227 * using the default locale.
228 *
229 * @return comma separated localized String
230 * @see AccessibleBundle#toDisplayString
231 */
232 public String toString() {
233 String ret = "";
234 if ((relations != null) && (relations.size() > 0)) {
235 ret = ((AccessibleRelation) (relations.elementAt(0))).toDisplayString();
236 for (int i = 1; i < relations.size(); i++) {
237 ret = ret + ","
238 + ((AccessibleRelation) (relations.elementAt(i))).
239 toDisplayString();
240 }
241 }
242 return ret;
243 }
244 }
|
1 /*
2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
178 * that matches the specified key.
179 * @param key the AccessibleRelation key
180 * @return true if the relation is in the relation set; otherwise false
181 */
182 public boolean contains(String key) {
183 return get(key) != null;
184 }
185
186 /**
187 * Returns the relation that matches the specified key.
188 * @param key the AccessibleRelation key
189 * @return the relation, if one exists, that matches the specified key.
190 * Otherwise, null is returned.
191 */
192 public AccessibleRelation get(String key) {
193 if (relations == null) {
194 return null;
195 } else {
196 int len = relations.size();
197 for (int i = 0; i < len; i++) {
198 AccessibleRelation relation = relations.elementAt(i);
199 if (relation != null && relation.getKey().equals(key)) {
200 return relation;
201 }
202 }
203 return null;
204 }
205 }
206
207 /**
208 * Returns the current relation set as an array of AccessibleRelation
209 * @return AccessibleRelation array contacting the current relation.
210 */
211 public AccessibleRelation[] toArray() {
212 if (relations == null) {
213 return new AccessibleRelation[0];
214 } else {
215 AccessibleRelation[] relationArray
216 = new AccessibleRelation[relations.size()];
217 for (int i = 0; i < relationArray.length; i++) {
218 relationArray[i] = relations.elementAt(i);
219 }
220 return relationArray;
221 }
222 }
223
224 /**
225 * Creates a localized String representing all the relations in the set
226 * using the default locale.
227 *
228 * @return comma separated localized String
229 * @see AccessibleBundle#toDisplayString
230 */
231 public String toString() {
232 String ret = "";
233 if ((relations != null) && (relations.size() > 0)) {
234 ret = (relations.elementAt(0)).toDisplayString();
235 for (int i = 1; i < relations.size(); i++) {
236 ret = ret + ","
237 + (relations.elementAt(i)).toDisplayString();
238 }
239 }
240 return ret;
241 }
242 }
|