1 package org.rosuda.REngine;
3 /** Represents a pairlist in R. Unlike the actual internal R implementation this one
4 does not use CAR/CDR/TAG linked representation but a @link{RList} object. */
5 public class REXPList extends REXPVector {
8 /* create a new pairlist with the contents of a named R list and no attributes.
9 @param list named list with the contents */
10 public REXPList(RList list) {
12 payload=(list==null)?new RList():list;
15 /* create a new pairlist with the contents of a named R list and attributes.
16 @param list named list with the contents
17 @param attr attributes */
18 public REXPList(RList list, REXPList attr) {
20 payload=(list==null)?new RList():list;
23 /* create a pairlist containing just one pair comprising of one value and one name.
24 This is a convenience constructor most commonly used to create attribute pairlists.
25 @param value of the element in the pairlist (must not be <code>null</code>)
26 @param name of the element in the pairlist (must not be <code>null</code>) */
27 public REXPList(REXP value, String name) {
29 payload = new RList(new REXP[] { value }, new String[] { name });
32 public Object asNativeJavaObject() throws REXPMismatchException {
33 // since REXPGenericVector does the hard work, we just cheat and use it in turn
34 REXPGenericVector v = new REXPGenericVector(payload);
35 return v.asNativeJavaObject();
38 public int length() { return payload.size(); }
40 public boolean isList() { return true; }
41 public boolean isPairList() { return true; }
43 public boolean isRecursive() { return true; }
45 public RList asList() { return payload; }
47 public String toString() {
48 return super.toString()+(asList().isNamed()?"named":"");
51 public String toDebugString() {
52 StringBuffer sb = new StringBuffer(super.toDebugString()+"{");
54 while (i < payload.size() && i < maxDebugItems) {
55 if (i>0) sb.append(",\n");
56 String name = payload.keyAt(i);
57 if (name!=null) sb.append(name+"=");
58 sb.append(payload.at(i).toDebugString());
61 if (i < payload.size()) sb.append(",..");
62 return sb.toString()+"}";