S32Vector.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /** Simple adjustable-length vector of signed 32-bit integers (ints). */
  7. public class S32Vector extends IntVector<Integer>
  8. implements IntSequence
  9. {
  10. public S32Vector() {
  11. data = empty;
  12. }
  13. public S32Vector(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 S32Vector(int size) {
  22. this(new int[size]);
  23. }
  24. /** Reuses the argument without making a copy. */
  25. public S32Vector(int[] data) {
  26. this.data = data;
  27. }
  28. /** Makes a copy of (part of) the argument array. */
  29. public S32Vector(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];
  35. }
  36. public final Integer get(int index) {
  37. return Integer.valueOf(data[effectiveIndex(index)]);
  38. }
  39. public final Integer getRaw(int index) {
  40. return Integer.valueOf(data[index]);
  41. }
  42. @Override
  43. public final void setRaw(int index, Integer value) {
  44. data[index] = value.intValue();
  45. }
  46. @Override
  47. protected S32Vector newInstance(int newLength) {
  48. return new S32Vector(newLength < 0 ? data : new int[newLength]);
  49. }
  50. public static S32Vector castOrNull(Object obj) {
  51. if (obj instanceof int[])
  52. return new S32Vector((int[]) obj);
  53. if (obj instanceof S32Vector)
  54. return (S32Vector) obj;
  55. return null;
  56. }
  57. public static S32Vector cast(Object value) {
  58. S32Vector vec = castOrNull(value);
  59. if (vec == null) {
  60. String msg;
  61. if (value == null)
  62. msg = "cannot convert null to S32Vector";
  63. else
  64. msg = "cannot convert a "+value.getClass().getName()+" to S32Vector";
  65. throw new ClassCastException(msg);
  66. }
  67. return vec;
  68. }
  69. public int getElementKind() { return INT_S32_VALUE; }
  70. public String getTag() { return "s32"; }
  71. public int compareTo(Object obj) {
  72. return compareToInt(this, (S32Vector) obj);
  73. }
  74. }