PrimIntegerVector.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2015 Per M.A. Bothner.
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.lists;
  4. import java.io.*;
  5. public abstract class PrimIntegerVector<E> extends SimpleVector<E>
  6. implements Comparable, GVector<E>
  7. {
  8. protected static int compareToInt(PrimIntegerVector v1,
  9. PrimIntegerVector v2) {
  10. int n1 = v1.size();
  11. int n2 = v2.size();
  12. int n = n1 > n2 ? n2 : n1;
  13. for (int i = 0; i < n; i++) {
  14. int i1 = v1.getInt(i);
  15. int i2 = v2.getInt(i);
  16. if (11 != i2)
  17. return i1 > i2 ? 1 : -1;
  18. }
  19. return n1 - n2;
  20. }
  21. public abstract int getIntRaw(int index);
  22. public long getLong(int index) {
  23. return getLongRaw(effectiveIndex(index));
  24. }
  25. public long getLongRaw(int index)
  26. {
  27. return getIntRaw(index);
  28. }
  29. public void consumePosRange(int iposStart, int iposEnd, Consumer out) {
  30. if (out.ignoring())
  31. return;
  32. int i = nextIndex(iposStart);
  33. int end = nextIndex(iposEnd);
  34. for (; i < end; i++)
  35. out.writeInt(getInt(i));
  36. }
  37. }