PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/util/IntegerArray.java

#
Java | 89 lines | 44 code | 11 blank | 34 comment | 1 complexity | 3ac5bba63cf5ac608b2522c42af63d2d MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * IntegerArray.java - Automatically growing array of ints
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2001 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.util;
  23. /**
  24. * A simple collection that stores integers and grows automatically.
  25. */
  26. public class IntegerArray
  27. {
  28. //{{{ IntegerArray constructor
  29. public IntegerArray()
  30. {
  31. this(2000);
  32. } //}}}
  33. //{{{ IntegerArray constructor
  34. public IntegerArray(int initialSize)
  35. {
  36. array = new int[initialSize];
  37. } //}}}
  38. //{{{ add() method
  39. public void add(int num)
  40. {
  41. if(len >= array.length)
  42. {
  43. int[] arrayN = new int[len * 2];
  44. System.arraycopy(array,0,arrayN,0,len);
  45. array = arrayN;
  46. }
  47. array[len++] = num;
  48. } //}}}
  49. //{{{ get() method
  50. public final int get(int index)
  51. {
  52. return array[index];
  53. } //}}}
  54. //{{{ getSize() method
  55. public final int getSize()
  56. {
  57. return len;
  58. } //}}}
  59. //{{{ setSize() method
  60. public final void setSize(int len)
  61. {
  62. this.len = len;
  63. } //}}}
  64. //{{{ clear() method
  65. public final void clear()
  66. {
  67. len = 0;
  68. } //}}}
  69. //{{{ getArray() method
  70. public int[] getArray()
  71. {
  72. return array;
  73. } //}}}
  74. //{{{ Private members
  75. private int[] array;
  76. private int len;
  77. //}}}
  78. }