1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.util;
16  
17  import java.util.HashSet;
18  import java.util.Set;
19  
20  /**
21   * <a href="PrimitiveIntSet.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Michael C. Han
24   */
25  public class PrimitiveIntSet {
26  
27      public PrimitiveIntSet() {
28          _elements = new HashSet<Integer>();
29      }
30  
31      public PrimitiveIntSet(int capacity) {
32          _elements = new HashSet<Integer>(capacity);
33      }
34  
35      public void add(int value) {
36          _elements.add(value);
37      }
38  
39      public void addAll(int[] values) {
40          for (int value : values) {
41              _elements.add(value);
42          }
43      }
44  
45      public int[] getArray() {
46          int[] values = new int[_elements.size()];
47  
48          int counter = 0;
49  
50          for (Integer element : _elements) {
51              values[counter] = element;
52  
53              counter++;
54          }
55  
56          return values;
57      }
58  
59      public int size() {
60          return _elements.size();
61      }
62  
63      private Set<Integer> _elements;
64  
65  }