You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LongVector.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. Alternatively, the contents of this file may be used under
  8. * the terms of the GNU Lesser General Public License Version 2.1 or later.
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. */
  15. package javassist.bytecode;
  16. final class LongVector {
  17. private int num;
  18. private Object[] objects;
  19. private LongVector next;
  20. public LongVector(int initialSize) {
  21. num = 0;
  22. objects = new Object[initialSize];
  23. next = null;
  24. }
  25. public void addElement(Object obj) {
  26. LongVector p = this;
  27. while (p.next != null)
  28. p = p.next;
  29. if (p.num < p.objects.length)
  30. p.objects[p.num++] = obj;
  31. else {
  32. LongVector q = p.next = new LongVector(p.objects.length);
  33. q.objects[q.num++] = obj;
  34. }
  35. }
  36. public int size() {
  37. LongVector p = this;
  38. int s = 0;
  39. while (p != null) {
  40. s += p.num;
  41. p = p.next;
  42. }
  43. return s;
  44. }
  45. public Object elementAt(int i) {
  46. LongVector p = this;
  47. while (p != null)
  48. if (i < p.num)
  49. return p.objects[i];
  50. else {
  51. i -= p.num;
  52. p = p.next;
  53. }
  54. return null;
  55. }
  56. /*
  57. public static void main(String [] args) {
  58. LongVector v = new LongVector(4);
  59. int i;
  60. for (i = 0; i < 128; ++i)
  61. v.addElement(new Integer(i));
  62. System.out.println(v.size());
  63. for (i = 0; i < v.size(); ++i) {
  64. System.out.print(v.elementAt(i));
  65. System.out.print(", ");
  66. }
  67. }
  68. */
  69. }