This project has retired. For details please refer to its Attic page.
CollectionUtil xref
View Javadoc

1   /*
2    * $Id: CollectionUtil.java 1229087 2012-01-09 10:35:14Z mck $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.tiles.request.collection;
22  
23  import java.util.Enumeration;
24  
25  /**
26   * Utilities for requests.
27   *
28   * @version $Rev: 1064782 $ $Date: 2011-01-28 18:08:52 +0100 (Fri, 28 Jan 2011) $
29   */
30  public final class CollectionUtil {
31  
32      /**
33       * Constructor.
34       */
35      private CollectionUtil() {
36  
37      }
38  
39      /**
40       * Returns the string representation of the key.
41       *
42       * @param key The key.
43       * @return The string representation of the key.
44       * @throws IllegalArgumentException If the key is <code>null</code>.
45       */
46      public static String key(Object key) {
47          if (key == null) {
48              throw new IllegalArgumentException();
49          } else if (key instanceof String) {
50              return ((String) key);
51          } else {
52              return (key.toString());
53          }
54      }
55  
56      /**
57       * Returns the number of elements in an enumeration, by iterating it.
58       *
59       * @param keys The enumeration.
60       * @return The number of elements.
61       */
62      public static int enumerationSize(Enumeration<?> keys) {
63          int n = 0;
64          while (keys.hasMoreElements()) {
65              keys.nextElement();
66              n++;
67          }
68          return n;
69      }
70  }