PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/util/IntegerArray.java

#
Java | 77 lines | 36 code | 9 blank | 32 comment | 1 complexity | d34f24cf4dbd5251c1f0f2ff7f2a3c45 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. array = new int[100];
  32. } //}}}
  33. //{{{ add() method
  34. public void add(int num)
  35. {
  36. if(len >= array.length)
  37. {
  38. int[] arrayN = new int[len * 2];
  39. System.arraycopy(array,0,arrayN,0,len);
  40. array = arrayN;
  41. }
  42. array[len++] = num;
  43. } //}}}
  44. //{{{ get() method
  45. public final int get(int index)
  46. {
  47. return array[index];
  48. } //}}}
  49. //{{{ getSize() method
  50. public final int getSize()
  51. {
  52. return len;
  53. } //}}}
  54. //{{{ setSize() method
  55. public final void setSize(int len)
  56. {
  57. this.len = len;
  58. } //}}}
  59. //{{{ clear() method
  60. public final void clear()
  61. {
  62. len = 0;
  63. } //}}}
  64. //{{{ Private members
  65. private int[] array;
  66. private int len;
  67. //}}}
  68. }