001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import java.util.HashSet;
018    import java.util.Set;
019    
020    /**
021     * @author Michael C. Han
022     */
023    public class PrimitiveIntSet {
024    
025            public PrimitiveIntSet() {
026                    _elements = new HashSet<Integer>();
027            }
028    
029            public PrimitiveIntSet(int capacity) {
030                    _elements = new HashSet<Integer>(capacity);
031            }
032    
033            public void add(int value) {
034                    _elements.add(value);
035            }
036    
037            public void addAll(int[] values) {
038                    for (int value : values) {
039                            _elements.add(value);
040                    }
041            }
042    
043            public int[] getArray() {
044                    int[] values = new int[_elements.size()];
045    
046                    int counter = 0;
047    
048                    for (Integer element : _elements) {
049                            values[counter] = element;
050    
051                            counter++;
052                    }
053    
054                    return values;
055            }
056    
057            public int size() {
058                    return _elements.size();
059            }
060    
061            private Set<Integer> _elements;
062    
063    }