U32Vector.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // This file is generated from PrimVector.template. DO NOT EDIT!
  2. // Copyright (c) 2001, 2002, 2015 Per M.A. Bothner and Brainfood Inc.
  3. // This is free software; for terms and warranty disclaimer see ./COPYING.
  4. package gnu.lists;
  5. import java.io.*;
  6. import gnu.math.UInt;
  7. /** Simple adjustable-length vector of unsigned 32-bit integers (ints). */
  8. public class U32Vector extends IntVector<UInt>
  9. {
  10. public U32Vector() {
  11. data = empty;
  12. }
  13. public U32Vector(int size, int value) {
  14. int[] array = new int[size];
  15. data = array;
  16. if (value != 0) {
  17. while (--size >= 0)
  18. array[size] = value;
  19. }
  20. }
  21. public U32Vector(int size) {
  22. this(new int[size]);
  23. }
  24. /** Reuses the argument without making a copy. */
  25. public U32Vector(int[] data) {
  26. this.data = data;
  27. }
  28. /** Makes a copy of (part of) the argument array. */
  29. public U32Vector(int[] values, int offset, int length) {
  30. this(length);
  31. System.arraycopy(values, offset, data, 0, length);
  32. }
  33. public final long getLongRaw(int index) {
  34. return (long) data[index] & 0xffffffffL;
  35. }
  36. public final UInt get(int index) {
  37. return UInt.valueOf(data[effectiveIndex(index)]);
  38. }
  39. public final UInt getRaw(int index) {
  40. return UInt.valueOf(data[index]);
  41. }
  42. @Override
  43. public final void setRaw(int index, UInt value) {
  44. data[index] = value.intValue();
  45. }
  46. @Override
  47. protected U32Vector newInstance(int newLength) {
  48. return new U32Vector(newLength < 0 ? data : new int[newLength]);
  49. }
  50. public static U32Vector castOrNull(Object obj) {
  51. if (obj instanceof int[])
  52. return new U32Vector((int[]) obj);
  53. if (obj instanceof U32Vector)
  54. return (U32Vector) obj;
  55. return null;
  56. }
  57. public static U32Vector cast(Object value) {
  58. U32Vector vec = castOrNull(value);
  59. if (vec == null) {
  60. String msg;
  61. if (value == null)
  62. msg = "cannot convert null to U32Vector";
  63. else
  64. msg = "cannot convert a "+value.getClass().getName()+" to U32Vector";
  65. throw new ClassCastException(msg);
  66. }
  67. return vec;
  68. }
  69. public int getElementKind() { return INT_U32_VALUE; }
  70. public String getTag() { return "u32"; }
  71. public void consumePosRange(int iposStart, int iposEnd, Consumer out) {
  72. if (out.ignoring())
  73. return;
  74. int i = nextIndex(iposStart);
  75. int end = nextIndex(iposEnd);
  76. for (; i < end; i++)
  77. Sequences.writeUInt(getInt(i), out);
  78. }
  79. public int compareTo(Object obj) {
  80. return compareToInt(this, (U32Vector) obj);
  81. }
  82. }