File: RVector.java

package info (click to toggle)
rjava 0.9-3-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,196 kB
  • sloc: java: 7,733; ansic: 4,947; sh: 2,878; makefile: 137; perl: 33
file content (48 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.rosuda.JRI;

import java.util.Vector;
import java.util.Enumeration;

/** class encapsulating named generic vectors in R - do NOT use add/remove directly as names are not synchronized with the contents. The reason for this implementation is for historical compatibility and it may change in the future.
<p>
It is now used in <code>REXP</code> where <code>Vector</code> type was used previously for contents storage.
@since JRI 0.3
*/
public class RVector extends java.util.Vector {
	Vector names = null;
	public RVector() { super(); }
	
	/** replace the names vector - do NOT use directly!
		@param nam list of names */
	public void setNames(String[] nam) {
		names=new Vector(nam.length);
		int i=0;
		while (i<nam.length)
			names.addElement(nam[i++]);
	}
	
	/** return the vector containg all names
		@return vector containing all names */
	public Vector getNames() {
		return names;
	}

	/** return contents by name or <code>null</code> if not found
		@param name key (name)
		@return contents or <code>null</code> if not found
		*/
	public REXP at(String name) {
		if (names==null) return null;
		int i=0;
		for (Enumeration e = names.elements() ; e.hasMoreElements() ;) {
			String n = (String)e.nextElement();
			if (n.equals(name)) return (REXP) elementAt(i);
			i++;
		}
		return null;
	}
	
	public REXP at(int i) {
		return (REXP)elementAt(i);
	}
}