1 package org.rosuda.REngine;
3 /** REXPDouble represents a vector of integer values. */
4 public class REXPInteger extends REXPVector {
7 /** NA integer value as defined in R. Unlike its real equivalent this one can be used in comparisons, although {@link #isNA(int) } is provided for consistency. */
8 public static final int NA = -2147483648;
10 public static boolean isNA(int value) {
14 /** create integer vector of the length 1 with the given value as its first (and only) element */
15 public REXPInteger(int load) {
17 payload=new int[] { load };
20 /** create integer vector with the payload specified by <code>load</code> */
21 public REXPInteger(int[] load) {
23 payload=(load==null)?new int[0]:load;
26 /** create integer vector with the payload specified by <code>load</code> and attributes <code>attr</code> */
27 public REXPInteger(int[] load, REXPList attr) {
29 payload=(load==null)?new int[0]:load;
32 public Object asNativeJavaObject() {
36 public int length() { return payload.length; }
38 public boolean isInteger() { return true; }
39 public boolean isNumeric() { return true; }
41 public int[] asIntegers() { return payload; }
43 /** returns the contents of this vector as doubles */
44 public double[] asDoubles() {
45 double[] d = new double[payload.length];
47 while (i < payload.length) { d[i] = (double) payload[i]; i++; }
51 /** returns the contents of this vector as strings */
52 public String[] asStrings() {
53 String[] s = new String[payload.length];
55 while (i < payload.length) { s[i] = ""+payload[i]; i++; }
59 public boolean[] isNA() {
60 boolean a[] = new boolean[payload.length];
62 while (i < a.length) { a[i] = (payload[i]==NA); i++; }
66 public String toDebugString() {
67 StringBuffer sb = new StringBuffer(super.toDebugString()+"{");
69 while (i < payload.length && i < maxDebugItems) {
70 if (i>0) sb.append(",");
71 sb.append(payload[i]);
74 if (i < payload.length) sb.append(",..");
75 return sb.toString()+"}";