org.rosuda.REngine
Class RList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.Vector
              extended by org.rosuda.REngine.RList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

public class RList
extends java.util.Vector
implements java.util.List

implementation of R-lists
All lists (dotted-pair lists, language lists, expressions and vectors) are regarded as named generic vectors. Note: This implementation has changed radically in Rserve 0.5! This class inofficially implements the Map interface. Unfortunately a conflict in the Java iterface classes Map and List doesn't allow us to implement both officially. Most prominently the Map 'remove' method had to be renamed to removeByKey.

Version:
$Id: RList.java 3199 2009-09-21 15:53:10Z urbanek $
See Also:
Serialized Form

Field Summary
 java.util.Vector names
           
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
RList()
          constructs an empty list
RList(java.util.Collection contents)
          constructs an initialized, unnamed list
RList(java.util.Collection contents, java.util.Collection names)
          constructs an initialized, named list.
RList(java.util.Collection contents, java.lang.String[] names)
          constructs an initialized, named list.
RList(int initSize, boolean hasNames)
           
RList(REXP[] contents)
          constructs an initialized, unnamed list
RList(REXP[] contents, java.lang.String[] names)
          constructs an initialized, named list.
 
Method Summary
 void add(int index, java.lang.Object element)
           
 boolean add(java.lang.Object element)
           
 boolean addAll(java.util.Collection c)
           
 boolean addAll(int index, java.util.Collection c)
           
 void addElement(java.lang.Object obj)
           
 REXP at(int i)
          get element at the specified position
 REXP at(java.lang.String v)
          get xpression given a key
 void clear()
           
 java.lang.Object clone()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
          NOTE: THIS IS UNIMPLEMENTED and always returns null!
 java.lang.Object get(java.lang.Object key)
           
 void insertElementAt(java.lang.Object obj, int index)
           
 boolean isNamed()
          checks whether this list is named or unnamed
 java.lang.String keyAt(int i)
          return the key (name) at a given index
 java.lang.String[] keys()
          returns all keys of the list
 java.util.Set keySet()
          Note: sinde RList is not really a Map, the returned set is only an approximation as it cannot reference duplicate or null names that may exist in the list
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map t)
           
 void putAll(RList t)
           
 java.lang.Object remove(int index)
           
 boolean remove(java.lang.Object elem)
           
 boolean removeAll(java.util.Collection c)
           
 void removeAllElements()
           
 java.lang.Object removeByKey(java.lang.Object key)
           
 boolean removeElement(java.lang.Object obj)
           
 void removeElementAt(int index)
           
 boolean retainAll(java.util.Collection c)
           
 void setKeyAt(int i, java.lang.String value)
          set key at the given index.
 java.lang.String toString()
           
 java.util.Collection values()
           
 
Methods inherited from class java.util.Vector
capacity, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, isEmpty, lastElement, lastIndexOf, lastIndexOf, removeRange, set, setElementAt, setSize, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, set, size, subList, toArray, toArray
 

Field Detail

names

public java.util.Vector names
Constructor Detail

RList

public RList()
constructs an empty list


RList

public RList(REXP[] contents)
constructs an initialized, unnamed list

Parameters:
contents - - an array of REXPs to use as contents of this list

RList

public RList(int initSize,
             boolean hasNames)

RList

public RList(java.util.Collection contents)
constructs an initialized, unnamed list

Parameters:
contents - - a Collection of REXPs to use as contents of this list

RList

public RList(REXP[] contents,
             java.lang.String[] names)
constructs an initialized, named list. The length of the contents vector determines the length of the list.

Parameters:
contents - - an array of REXPs to use as contents of this list
names - - an array of Strings to use as names

RList

public RList(java.util.Collection contents,
             java.lang.String[] names)
constructs an initialized, named list. The size of the contents collection determines the length of the list.

Parameters:
contents - - a Collection of REXPs to use as contents of this list
names - - an array of Strings to use as names

RList

public RList(java.util.Collection contents,
             java.util.Collection names)
constructs an initialized, named list. The size of the contents collection determines the length of the list.

Parameters:
contents - - a Collection of REXPs to use as contents of this list
names - - an Collection of Strings to use as names
Method Detail

isNamed

public boolean isNamed()
checks whether this list is named or unnamed

Returns:
true if this list is named, false otherwise

at

public REXP at(java.lang.String v)
get xpression given a key

Parameters:
v - key
Returns:
value which corresponds to the given key or null if the list is unnamed or key not found

at

public REXP at(int i)
get element at the specified position

Parameters:
i - index
Returns:
value at the index or null if the index is out of bounds

keyAt

public java.lang.String keyAt(int i)
return the key (name) at a given index

Parameters:
i - index
Returns:
ket at the index - can be null is the list is unnamed or the index is out of range

setKeyAt

public void setKeyAt(int i,
                     java.lang.String value)
set key at the given index. Using this method automatically makes the list a named one even if the key is null. Out of range operations are undefined (currently no-ops)

Parameters:
i - index
value - key name

keys

public java.lang.String[] keys()
returns all keys of the list

Returns:
array containing all keys or null if list unnamed

add

public void add(int index,
                java.lang.Object element)
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.Vector

add

public boolean add(java.lang.Object element)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.Vector

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.Vector

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.Vector

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Overrides:
clear in class java.util.Vector

clone

public java.lang.Object clone()
Overrides:
clone in class java.util.Vector

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.Vector

remove

public boolean remove(java.lang.Object elem)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.Vector

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List
Overrides:
removeAll in class java.util.Vector

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List
Overrides:
retainAll in class java.util.Vector

removeAllElements

public void removeAllElements()
Overrides:
removeAllElements in class java.util.Vector

insertElementAt

public void insertElementAt(java.lang.Object obj,
                            int index)
Overrides:
insertElementAt in class java.util.Vector

addElement

public void addElement(java.lang.Object obj)
Overrides:
addElement in class java.util.Vector

removeElementAt

public void removeElementAt(int index)
Overrides:
removeElementAt in class java.util.Vector

removeElement

public boolean removeElement(java.lang.Object obj)
Overrides:
removeElement in class java.util.Vector

containsKey

public boolean containsKey(java.lang.Object key)

containsValue

public boolean containsValue(java.lang.Object value)

entrySet

public java.util.Set entrySet()
NOTE: THIS IS UNIMPLEMENTED and always returns null! Due to the fact that R lists are not proper maps we canot maintain a set-view of the list


get

public java.lang.Object get(java.lang.Object key)

keySet

public java.util.Set keySet()
Note: sinde RList is not really a Map, the returned set is only an approximation as it cannot reference duplicate or null names that may exist in the list


put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)

putAll

public void putAll(java.util.Map t)

putAll

public void putAll(RList t)

removeByKey

public java.lang.Object removeByKey(java.lang.Object key)

values

public java.util.Collection values()

toString

public java.lang.String toString()
Overrides:
toString in class java.util.Vector