org.rosuda.ibase
Class SVar

java.lang.Object
  extended by org.rosuda.ibase.Notifier
      extended by org.rosuda.ibase.SVar
Direct Known Subclasses:
SVarDouble, SVarFact, SVarFixDouble, SVarFixFact, SVarFixInt, SVarInt, SVarObj

public abstract class SVar
extends Notifier

Statistical Variable This abstract class defines an interface to variables. There are various implementations (fixed size/flexible, fixed type/objects etc.

Version:
$Id: SVar.java 2822 2007-08-21 20:26:21Z urbanek $

Field Summary
 boolean cacheRanks
          if false then ranks are not cached
protected  boolean cat
          type of variable, true if categorial variable
protected  int contentsType
          type of the contents
static int CT_Map
           
static int CT_Number
           
static int CT_String
           
static int CT_Tree
           
static double double_NA
          this value is returned by atD(int) if the value is missing (null) or if the variable is not numerical.
protected  boolean guessing
          if set to true then the type of the variable is not yet known and can be guessed
static int int_NA
          this value is returned by atI(int) if the value is missing (null) or if the variable is not numerical.
protected  boolean isnum
          type of variable, true if numeric (i.e. subclass of Number)
static int IVT_Derived
          derived is not internal (and hence isInternal will return false)
static int IVT_Index
           
static int IVT_LeafID
           
static int IVT_Misclass
           
static int IVT_Normal
           
static int IVT_Prediction
           
static int IVT_RCC
           
static int IVT_Resid
           
static int IVT_ResidStat1
           
static int IVT_ResidStat2
           
 boolean linked
          if true permutation of categories is linked between plots
protected  double max
           
protected  double min
           
static java.lang.String missingCat
          string denoting class of the missings
protected  int missingCount
          # of missing cases in the variable
protected  java.lang.String name
          variable name
 boolean selected
          flag denoting selection in a SVarSet
protected  SCatSequence seq
          permutation of categories
static int SM_lexi
          sort method lexicograph.
static int SM_num
          sort method numerical (all objects are cast to Number, non-castable are assigned -0.01, basically to appear just before zero)
 int tag
          this attribute can be used by external code to store temporary information (tags) - it may not used by SVar or its subclasses.
 
Constructor Summary
SVar(java.lang.String Name, boolean iscat)
          construct new variable. iscat=true defaults to non-numerical, CT_String, whereas iscat=false defaults to numerical, CT_Number
SVar(java.lang.String Name, boolean isnum, boolean iscat)
          construct new variable. iscat=true defaults to non-numerical, CT_String, whereas iscat=false defaults to numerical, CT_Number
 
Method Summary
 boolean add(double d)
           
 boolean add(int d)
           
abstract  boolean add(java.lang.Object o)
          adds a new case to the variable. the exact behavior is implementation-dependent.
abstract  java.lang.Object at(int i)
           
 double atD(int i)
           
 double atF(int i)
           
 int atI(int i)
           
 java.lang.String atS(int i)
           
 void categorize()
          define the variable explicitely as categorial (equals to calling categorize(false))
abstract  void categorize(boolean rebuild)
          define the variable explicitely as categorical
abstract  void dropCat()
          define the variable explicitely as non-categorial (drop category list)
 java.lang.Object elementAt(int i)
          for compatibility with old code that used Vector class
static int[] filterRanksByID(int[] r, int[] ids)
           
static int[] filterRanksByMap(int[] r, int[] map, int mapEntry)
           
abstract  java.lang.Object getCatAt(int i)
          returns the category with index ID or null if variable is not categorial
abstract  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
abstract  int getCatIndex(java.lang.Object o)
          returns the ID of the category
 int getContentsType()
          retrieves contents type of the variable
 int getInternalType()
          returns the internal type of the variable
 double getMax()
           
 double getMin()
           
 int getMissingCount()
          returs the # of missing values in this variable
 java.lang.String getName()
          returns name of the variable
 Notifier getNotifier()
          since the current implemantation is a Notifier itef, it returns "this"
abstract  int getNumCats()
          returns the number of categories for this variable or 0 if the variable is not categorial
 int[] getRanked()
          returns list of indexes ordered by rank.
abstract  int[] getRanked(SMarker m, int markspec)
           
abstract  int getSizeCat(java.lang.Object o)
          returns size of the category o.
abstract  int getSizeCatAt(int i)
          returns size of the category with index ID or -1 if variable is not categorial or index oob
 boolean hasMissing()
          returns true if there are missing values
 boolean insert(double d, int index)
           
 boolean insert(int d, int index)
           
abstract  boolean insert(java.lang.Object o, int index)
          inserts a new case to the variable at specified index. the exact behavior is implementation-dependent.
 boolean isCat()
          returns true if it's a categorial variable
 boolean isEmpty()
           
 boolean isInternal()
          returns true if the variable is internal, i.e. generated on-the fly. note that derived variables are NOT internal. use (getInterrnalType()==SVar.IVT_Normal) to check for original, non-derived variables.
 boolean isMissingAt(int i)
           
static boolean isNA(double d)
          checks for a missing value.
static boolean isNA(int i)
          checks for a missing value.
 boolean isNum()
          returns true if the variable has numerical content (i.e. it can be casted to Number)
 boolean isSelected()
          returns true the selected flag is set
 SCatSequence mainSeq()
          returns the main category sequence for this variable.
abstract  boolean remove(int index)
          removes a case from the variable at specified index. the exact behavior is implementation-dependent.
 boolean replace(int index, double d)
           
 boolean replace(int index, int i)
           
abstract  boolean replace(int index, java.lang.Object o)
          replaces an element at specified position
 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
 boolean setContentsType(int ct)
          If it is to be used then is should be used BEFORE first data entries are inserted.
 void setInternalType(int it)
          sets type of an internal variable. internal variables are variables that were not contained in the original dataset. derived variables are also internal if they were derived in klimt and not loaded with the dataset.
 void setName(java.lang.String nn)
          warning!
 void setSelected(boolean setit)
          sets the selected flag to the specified state
 void setSeq(SCatSequence newSeq)
           
abstract  int size()
          returns the size (number of cases) of the variable
 void sortCategories()
          sort caregotires, using default method which is numerical for num. variables, lexicogr. otherwise
abstract  void sortCategories(int method)
          sort categories by specifeid method
 java.lang.String toString()
           
 
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
 

Field Detail

CT_String

public static final int CT_String
See Also:
Constant Field Values

CT_Number

public static final int CT_Number
See Also:
Constant Field Values

CT_Map

public static final int CT_Map
See Also:
Constant Field Values

CT_Tree

public static final int CT_Tree
See Also:
Constant Field Values

IVT_Derived

public static final int IVT_Derived
derived is not internal (and hence isInternal will return false)

See Also:
Constant Field Values

IVT_Normal

public static final int IVT_Normal
See Also:
Constant Field Values

IVT_Prediction

public static final int IVT_Prediction
See Also:
Constant Field Values

IVT_Misclass

public static final int IVT_Misclass
See Also:
Constant Field Values

IVT_LeafID

public static final int IVT_LeafID
See Also:
Constant Field Values

IVT_Index

public static final int IVT_Index
See Also:
Constant Field Values

IVT_Resid

public static final int IVT_Resid
See Also:
Constant Field Values

IVT_RCC

public static final int IVT_RCC
See Also:
Constant Field Values

IVT_ResidStat1

public static final int IVT_ResidStat1
See Also:
Constant Field Values

IVT_ResidStat2

public static final int IVT_ResidStat2
See Also:
Constant Field Values

SM_lexi

public static final int SM_lexi
sort method lexicograph.

See Also:
Constant Field Values

SM_num

public static final int SM_num
sort method numerical (all objects are cast to Number, non-castable are assigned -0.01, basically to appear just before zero)

See Also:
Constant Field Values

int_NA

public static int int_NA
this value is returned by atI(int) if the value is missing (null) or if the variable is not numerical. This variable should not be changed except on startup. (Note: R uses -2147483648)


double_NA

public static double double_NA
this value is returned by atD(int) if the value is missing (null) or if the variable is not numerical. This variable should not be changed except on startup.


missingCat

public static final java.lang.String missingCat
string denoting class of the missings

See Also:
Constant Field Values

min

protected double min

max

protected double max

name

protected java.lang.String name
variable name


cat

protected boolean cat
type of variable, true if categorial variable


isnum

protected boolean isnum
type of variable, true if numeric (i.e. subclass of Number)


guessing

protected boolean guessing
if set to true then the type of the variable is not yet known and can be guessed


contentsType

protected int contentsType
type of the contents


selected

public boolean selected
flag denoting selection in a SVarSet


missingCount

protected int missingCount
# of missing cases in the variable


cacheRanks

public boolean cacheRanks
if false then ranks are not cached


tag

public int tag
this attribute can be used by external code to store temporary information (tags) - it may not used by SVar or its subclasses. This attribute should not be used in environments that use SVar across multiple threads.


seq

protected SCatSequence seq
permutation of categories


linked

public boolean linked
if true permutation of categories is linked between plots

Constructor Detail

SVar

public SVar(java.lang.String Name,
            boolean iscat)
construct new variable. iscat=true defaults to non-numerical, CT_String, whereas iscat=false defaults to numerical, CT_Number

Parameters:
Name - variable name
iscat - true if categorial variable

SVar

public SVar(java.lang.String Name,
            boolean isnum,
            boolean iscat)
construct new variable. iscat=true defaults to non-numerical, CT_String, whereas iscat=false defaults to numerical, CT_Number

Parameters:
Name - variable name
isnum - true if numeric variable
iscat - true if categorial variable
Method Detail

setAllEmpty

public 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). remove abstract and define a fallback using replace/add/remove in case the subclass doesn't provide its optimized version (SU 19.1.04)


setInternalType

public void setInternalType(int it)
sets type of an internal variable. internal variables are variables that were not contained in the original dataset. derived variables are also internal if they were derived in klimt and not loaded with the dataset.


mainSeq

public SCatSequence mainSeq()
returns the main category sequence for this variable.


getInternalType

public int getInternalType()
returns the internal type of the variable


isInternal

public boolean isInternal()
returns true if the variable is internal, i.e. generated on-the fly. note that derived variables are NOT internal. use (getInterrnalType()==SVar.IVT_Normal) to check for original, non-derived variables.


isSelected

public boolean isSelected()
returns true the selected flag is set


setSelected

public void setSelected(boolean setit)
sets the selected flag to the specified state


categorize

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

Parameters:
rebuild - if set to true force rebuild even if the variable is already categorial.

categorize

public void categorize()
define the variable explicitely as categorial (equals to calling categorize(false))


getNotifier

public Notifier getNotifier()
since the current implemantation is a Notifier itef, it returns "this"


getContentsType

public int getContentsType()
retrieves contents type of the variable

Returns:
contents type (see CT_xxx constants)

setContentsType

public boolean setContentsType(int ct)
If it is to be used then is should be used BEFORE first data entries are inserted. A call to this method implicitely disables any type guessing. The results of calling this method on non-empty SVar is undefined, but the current implementation allows such use for custom types.

Returns:
returns true upon success. This method is guaranteed to succeed if setting a custom type when no data were inserted yet. The method may succeed in other cases, but its return value should be checked in that case.

sortCategories

public void sortCategories()
sort caregotires, using default method which is numerical for num. variables, lexicogr. otherwise


sortCategories

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

Parameters:
method - sort method, see SM_xxx constants

dropCat

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


setCategorical

public 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


isNA

public static boolean isNA(double d)
checks for a missing value. Note that for doubles isNA implies isNaN but NOT vice versa!

Parameters:
d - value to check

isNA

public static boolean isNA(int i)
checks for a missing value.

Parameters:
i - value to check

size

public abstract int size()
returns the size (number of cases) of the variable


add

public abstract boolean add(java.lang.Object o)
adds a new case to the variable. the exact behavior is implementation-dependent.


add

public boolean add(double d)

add

public boolean add(int d)

insert

public abstract boolean insert(java.lang.Object o,
                               int index)
inserts a new case to the variable at specified index. the exact behavior is implementation-dependent.


insert

public boolean insert(double d,
                      int index)

insert

public boolean insert(int d,
                      int index)

remove

public abstract boolean remove(int index)
removes a case from the variable at specified index. the exact behavior is implementation-dependent.


replace

public abstract boolean replace(int index,
                                java.lang.Object o)
replaces an element at specified position


replace

public boolean replace(int index,
                       double d)

replace

public boolean replace(int index,
                       int i)

getMin

public double getMin()

getMax

public double getMax()

at

public abstract java.lang.Object at(int i)

elementAt

public java.lang.Object elementAt(int i)
for compatibility with old code that used Vector class


atI

public int atI(int i)

atF

public double atF(int i)

atD

public double atD(int i)

atS

public java.lang.String atS(int i)

isMissingAt

public boolean isMissingAt(int i)

getMissingCount

public int getMissingCount()
returs the # of missing values in this variable


getCatIndex

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

Parameters:
category - (usually string)
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


getCatAt

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


getSizeCatAt

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


getSizeCat

public abstract 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.


getName

public java.lang.String getName()
returns name of the variable


isNum

public boolean isNum()
returns true if the variable has numerical content (i.e. it can be casted to Number)


isCat

public boolean isCat()
returns true if it's a categorial variable


isEmpty

public boolean isEmpty()

setName

public void setName(java.lang.String nn)
warning! use with care! Nameshould not be changed after hte variable was registered with SVarSet. The behavior for doing so is undefined.


getNumCats

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


hasMissing

public boolean hasMissing()
returns true if there are missing values


getCategories

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


getRanked

public int[] getRanked()
returns list of indexes ordered by rank. for details see @link{#getRanked(SVar, SMarker, int)}


getRanked

public abstract int[] getRanked(SMarker m,
                                int markspec)

filterRanksByID

public static int[] filterRanksByID(int[] r,
                                    int[] ids)

filterRanksByMap

public static int[] filterRanksByMap(int[] r,
                                     int[] map,
                                     int mapEntry)

toString

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

setSeq

public void setSeq(SCatSequence newSeq)