001 /*--------------------------------------------------------------------------+ 002 $Id: IntList.java 26283 2010-02-18 11:18:57Z juergens $ 003 | | 004 | Copyright 2005-2010 Technische Universitaet Muenchen | 005 | | 006 | Licensed under the Apache License, Version 2.0 (the "License"); | 007 | you may not use this file except in compliance with the License. | 008 | You may obtain a copy of the License at | 009 | | 010 | http://www.apache.org/licenses/LICENSE-2.0 | 011 | | 012 | Unless required by applicable law or agreed to in writing, software | 013 | distributed under the License is distributed on an "AS IS" BASIS, | 014 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 015 | See the License for the specific language governing permissions and | 016 | limitations under the License. | 017 +--------------------------------------------------------------------------*/ 018 package edu.tum.cs.commons.collections; 019 020 /** 021 * A really simple list for storing ints. This exists as it is both more 022 * efficient and uses way less memory than a List of Integers. 023 * 024 * @author hummelb 025 * @author $Author: juergens $ 026 * @version $Rev: 26283 $ 027 * @levd.rating GREEN Hash: 98A63662009CD83FB4E7243830757973 028 */ 029 public class IntList extends ManagedIntArray { 030 031 /** Returns the size of the list. */ 032 public int getSize() { 033 return size; 034 } 035 036 /** 037 * Returns the element at the given index. No range checking is performed, 038 * thus you might sometimes get an {@link ArrayIndexOutOfBoundsException}, 039 * and sometimes just 0 returned, depending on if you reached existing 040 * memory by chance. 041 */ 042 public int get(int index) { 043 return array[index]; 044 } 045 046 /** 047 * Set the element at the given index. No range checking is performed, thus 048 * you might sometimes get an {@link ArrayIndexOutOfBoundsException}, and 049 * sometimes not for illegal indexes, depending on whether you hit memory 050 * allocated by the exponential growth strategy by chance. 051 */ 052 public void set(int index, int value) { 053 array[index] = value; 054 } 055 056 /** Adds an element to the end of the list. */ 057 public void add(int value) { 058 int index = size; 059 addArrayElement(); 060 array[index] = value; 061 } 062 }