/** creates a new generic vector from a list. Note that the names in the list are ignored as they are expected to be defined by the attributes parameter. * @param list list to create the vector from (names are ignored - use {@link #REXPGenericVector(RList)} or the <code>"names"</code> attribute for named lists * @param attr attributes */ public REXPGenericVector(RList list, REXPList attr) { super(attr); payload=(list==null)?new RList():list; }
/** creates a new generic vector from a list. If the list is named, the <code>"names"</code> attribute is created automatically from it. * @param list list to create the vector from */ public REXPGenericVector(RList list) { super(); payload=(list==null)?new RList():list; // automatically generate 'names' attribute if (payload.isNamed()) attr = new REXPList( new RList(new REXP[] { new REXPString(payload.keys()) }, new String[] { "names" })); }
REXP ca = getAttr().asList().at("class"); REXP ls = getAttr().asList().at("levels"); if (ca != null && ls != null && ca.asString().equals("factor")) { REXPFactory lc = new REXPFactory(); REXPFactory nf = new REXPFactory(); RList l = new RList(); while (o<eox) { String name = null; if (name==null) l.add(lc.cont); else l.put(name, lc.cont); boolean isRoot = false; if (rootList == null) { rootList = new RList(); isRoot = true; REXPFactory tagf = new REXPFactory(); o = headf.parseREXP(buf, o); int elIndex = rootList.size(); rootList.add(headf.cont); rootList.setKeyAt(elIndex, tagf.cont.asString()); if (getAttr()!=null && getAttr().asList().at("names") != null) { REXP nam = getAttr().asList().at("names"); String names[] = null; if (nam.isString()) names = nam.asStrings();
int rxt = type; if (type==XT_LIST || type==XT_LIST_TAG || type==XT_LIST_NOTAG) rxt=(cont.asList()!=null && cont.asList().isNamed())?XT_LIST_TAG:XT_LIST_NOTAG; RList al = null; if (a!=null) al = a.asList(); if (al != null && al.size()>0) hasAttr=true; if (hasAttr) l+=attr.getBinaryLength(); while (i<lst.size()) { REXP x = lst.at(i); l += (x==null)?4:(new REXPFactory(x).getBinaryLength()); if (rxt==XT_LIST_TAG) { int pl=l; String s = lst.keyAt(i); l+=4; // header for a symbol l+=(s==null)?1:(s.length()+1);
/** creates a data frame object from a list object using integer row names * @param l a (named) list of vectors ({@link REXPVector} subclasses), each element corresponds to a column and all elements must have the same length * @return a data frame object * @throws REXPMismatchException if the list is empty or any of the elements is not a vector */ public static REXP createDataFrame(RList l) throws REXPMismatchException { if (l == null || l.size() < 1) throw new REXPMismatchException(new REXPList(l), "data frame (must have dim>0)"); if (!(l.at(0) instanceof REXPVector)) throw new REXPMismatchException(new REXPList(l), "data frame (contents must be vectors)"); REXPVector fe = (REXPVector) l.at(0); return new REXPGenericVector(l, new REXPList( new RList( new REXP[] { new REXPString("data.frame"), new REXPString(l.keys()), new REXPInteger(new int[] { REXPInteger.NA, -fe.length() }) }, new String[] { "class", "names", "row.names" }))); }
public String toDebugString() { StringBuffer sb = new StringBuffer(super.toDebugString()+"{"); int i = 0; while (i < payload.size() && i < maxDebugItems) { if (i>0) sb.append(",\n"); sb.append(payload.at(i).toDebugString()); i++; } if (i < payload.size()) sb.append(",.."); return sb.toString()+"}"; } }
public String toDebugString() { StringBuffer sb = new StringBuffer(super.toDebugString()+"{"); int i = 0; while (i < payload.size() && i < maxDebugItems) { if (i>0) sb.append(",\n"); String name = payload.keyAt(i); if (name!=null) sb.append(name+"="); sb.append(payload.at(i).toDebugString()); i++; } if (i < payload.size()) sb.append(",.."); return sb.toString()+"}"; } }
public int length() { return payload.size(); }
public Object asNativeJavaObject() throws REXPMismatchException { int n = payload.size(); if (payload.isNamed()) { String[] names = payload.keys(); if (names.length == n) { HashMap map = new HashMap(); break; Object value = payload.elementAt(i); if (value != null) value = ((REXP) value).asNativeJavaObject(); Object value = payload.elementAt(i); if (value != null) value = ((REXP) value).asNativeJavaObject();
public Object get(Object key) { return at((String)key); }
public Object put(Object key, Object value) { if (key==null) { add(value); return null; } if (names != null) { int p = names.indexOf(key); if (p >= 0) return super.set(p, value); } int i = size(); super.add(value); if (names==null) names = new Vector(i+1); while (names.size() < i) names.add(null); names.add(key); return null; }
if (directoryNames.at("parent") != null) { mParent = directoryNames.at("parent").asString(); } else { LOG.fine("WARNING: directoryNames at \"parent\" is null!"); if(directoryNames.isEmpty()) { LOG.fine("WARNING: directoryNames is empty!"); } else { Set<String> dirKeySet = directoryNames.keySet(); Iterator iter = dirKeySet.iterator(); String key;
public String toString() { return super.toString()+(asList().isNamed()?"named":""); }