org.rosuda.ibase
Class SVarObj

java.lang.Object
  extended by org.rosuda.ibase.Notifier
      extended by org.rosuda.ibase.SVar
          extended by org.rosuda.ibase.SVarObj

public class SVarObj
extends SVar

Statistical Variable

IMPORTANT NOTES:

 NOTE: do NOT remove any elements from SVar !! Any Vector methods that modify contents
       except for "add" are NOT safe (for categorized vars) as they DON'T update categories!!

 The "is number" property is set accoding to the first added (non-null) element - thus you should NOT mix
 numeric and non-numeric objects. It is safe to insert numbers in non-numeric value, but NOT
 vice-versa as for numeric variables the detection of min/max casts any object to Number.

Version:
$Id: SVarObj.java 2185 2006-04-05 13:28:42Z wichtreyt $

Field Summary
 
Fields inherited from class org.rosuda.ibase.SVar
cacheRanks, cat, contentsType, CT_Map, CT_Number, CT_String, CT_Tree, double_NA, guessing, int_NA, isnum, IVT_Derived, IVT_Index, IVT_LeafID, IVT_Misclass, IVT_Normal, IVT_Prediction, IVT_RCC, IVT_Resid, IVT_ResidStat1, IVT_ResidStat2, linked, max, min, missingCat, missingCount, name, selected, seq, SM_lexi, SM_num, tag
 
Constructor Summary
SVarObj(java.lang.String Name)
          construct new variable (equals to SVar(Name,false,null))
SVarObj(java.lang.String Name, boolean iscat)
          construct new variable and add first element
SVarObj(java.lang.String Name, boolean isnum, boolean iscat)
           
 
Method Summary
 boolean add(java.lang.Object o)
          adds a new case to the variable (NEVER use addElement!
 java.lang.Object at(int i)
           
 void categorize(boolean rebuild)
          define the variable explicitely as categorical
 void dropCat()
          define the variable explicitely as non-categorial (drop category list)
 java.lang.Object getCatAt(int i)
          returns the category with index ID or null if variable is not categorial
 java.lang.Object[] getCategories()
          returns new, fixed array of categories
 int getCatIndex(int i)
          returns ID of the category of i-th case in the variable or -1 if i oob
 int getCatIndex(java.lang.Object o)
          returns the ID of the category of the object
 java.lang.String[] getContent()
          Return content as StringArray
 int getNumCats()
          returns the number of categories for this variable or 0 if the variable is not categorial
 int[] getRanked(SMarker m, int markspec)
          returns list of indexes ordered by rank, for non-cat, num vars only. missing values are omitted.
 int getSizeCat(java.lang.Object o)
          returns size of the category o.
 int getSizeCatAt(int i)
          returns size of the category with index ID or -1 if variable is not categorial or index oob
 boolean insert(java.lang.Object o, int index)
          inserts a case to var at any index
 boolean remove(int index)
          remove a case, if it's an NA do missingcount--, what i do not is updating cats
 boolean replace(int i, java.lang.Object o)
          replaces an element at specified position - use with care!.
 void setAllEmpty(int size)
          we want to be able to make an empty SVar with the specified size and null content (added 28.12.03 MH).
 void setCategorical(boolean nc)
          define the type of the variable. note that setting nc to false does not necessarily drop categories information. this method should be used for quick toggling of the variable type
 int size()
          returns the size (number of cases) of the variable
 void sortCategories(int method)
          sort categories by specifeid method
 java.lang.String toString()
           
 void tryToGuessNum(boolean doit)
          sets the #guessNum flag.
 
Methods inherited from class org.rosuda.ibase.SVar
add, add, atD, atF, atI, atS, categorize, elementAt, filterRanksByID, filterRanksByMap, getContentsType, getInternalType, getMax, getMin, getMissingCount, getName, getNotifier, getRanked, hasMissing, insert, insert, isCat, isEmpty, isInternal, isMissingAt, isNA, isNA, isNum, isSelected, mainSeq, replace, replace, setContentsType, setInternalType, setName, setSelected, setSeq, sortCategories
 
Methods inherited from class org.rosuda.ibase.Notifier
addDepend, beginBatch, delDepend, endBatch, NotifyAll, NotifyAll, NotifyAll, NotifyAll, startCascadedNotifyAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SVarObj

public SVarObj(java.lang.String Name,
               boolean iscat)
construct new variable and add first element

Parameters:
Name - variable name
iscat - true if categorial variable
first - first element to be added - see add(java.lang.Object) for details. If null is passed then no element is added. The usage of this constructor is discouraged/deprecated because first entry cannot contain a missing value thus leading to a loss of generality.

SVarObj

public SVarObj(java.lang.String Name,
               boolean isnum,
               boolean iscat)

SVarObj

public SVarObj(java.lang.String Name)
construct new variable (equals to SVar(Name,false,null))

Parameters:
Name - variable name
Method Detail

setAllEmpty

public void setAllEmpty(int size)
Description copied from class: SVar
we want to be able to make an empty SVar with the specified size and null content (added 28.12.03 MH). remove abstract and define a fallback using replace/add/remove in case the subclass doesn't provide its optimized version (SU 19.1.04)

Overrides:
setAllEmpty in class SVar

getContent

public java.lang.String[] getContent()
Return content as StringArray

Returns:
content

tryToGuessNum

public void tryToGuessNum(boolean doit)
sets the #guessNum flag. It must me set before the first add(..) call because the guess is made based on the first added object (hence makes no sense if #SVar(String,boolean,Object) was used).


size

public int size()
Description copied from class: SVar
returns the size (number of cases) of the variable

Specified by:
size in class SVar

categorize

public void categorize(boolean rebuild)
define the variable explicitely as categorical

Specified by:
categorize in class SVar
Parameters:
rebuild - if set to true force rebuild even if the variable is already categorial.

sortCategories

public void sortCategories(int method)
sort categories by specifeid method

Specified by:
sortCategories in class SVar
Parameters:
method - sort method, see SM_xxx constants

dropCat

public void dropCat()
define the variable explicitely as non-categorial (drop category list)

Specified by:
dropCat in class SVar

setCategorical

public void setCategorical(boolean nc)
Description copied from class: SVar
define the type of the variable. note that setting nc to false does not necessarily drop categories information. this method should be used for quick toggling of the variable type

Overrides:
setCategorical in class SVar

add

public boolean add(java.lang.Object o)
adds a new case to the variable (NEVER use addElement! see package header) Also beware, categorial varaibles are classified by object not by value!

Specified by:
add in class SVar
Parameters:
o - object to be added. First call to add (even implicit if an object was specified on the call to the constructor) does also decide whether the variable will be numeric or not. If the first object is a subclass of Number then the variable is defined as numeric. There is a significant difference in handling numeric and non-numeric variabels, see package header.
Returns:
true if element was successfully added, or false upon failure - currently when non-numerical value is inserted in a numerical variable. It is strongly recommended to check the result and act upon it, because failing to do so can result in non-consistent datasets - i.e. mismatched row IDs

insert

public boolean insert(java.lang.Object o,
                      int index)
inserts a case to var at any index

Specified by:
insert in class SVar

remove

public boolean remove(int index)
remove a case, if it's an NA do missingcount--, what i do not is updating cats

Specified by:
remove in class SVar

replace

public boolean replace(int i,
                       java.lang.Object o)
replaces an element at specified position - use with care!. also numerical variables only "grow" their min/max - i.e. if min/max was the removed element, then min/max is not adapted to shrink the range

Specified by:
replace in class SVar

at

public java.lang.Object at(int i)
Specified by:
at in class SVar

getCatIndex

public int getCatIndex(java.lang.Object o)
returns the ID of the category of the object

Specified by:
getCatIndex in class SVar
Parameters:
object -
Returns:
category ID

getCatIndex

public int getCatIndex(int i)
returns ID of the category of i-th case in the variable or -1 if i oob

Overrides:
getCatIndex in class SVar

getCatAt

public java.lang.Object getCatAt(int i)
returns the category with index ID or null if variable is not categorial

Specified by:
getCatAt in class SVar

getSizeCatAt

public int getSizeCatAt(int i)
returns size of the category with index ID or -1 if variable is not categorial or index oob

Specified by:
getSizeCatAt in class SVar

getSizeCat

public int getSizeCat(java.lang.Object o)
returns size of the category o. If category does not exist or variable is not categorial, -1 is returned.

Specified by:
getSizeCat in class SVar

getNumCats

public int getNumCats()
returns the number of categories for this variable or 0 if the variable is not categorial

Specified by:
getNumCats in class SVar

getCategories

public java.lang.Object[] getCategories()
returns new, fixed array of categories

Specified by:
getCategories in class SVar

getRanked

public int[] getRanked(SMarker m,
                       int markspec)
returns list of indexes ordered by rank, for non-cat, num vars only. missing values are omitted.

Specified by:
getRanked in class SVar
Parameters:
v - variable (should be obtained by at(..))
m - marker to use for filtering. if null all cases will be checked
markspec - mark for filtering, i.e. cases with that mark will be used only
Returns:
list of indexes or null is any of the following cases: variable is not numerical or is categorical, no cases matching specification are present

toString

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