Package com.rapidminer.belt.buffer
Class NominalBuffer
- java.lang.Object
-
- com.rapidminer.belt.buffer.NominalBuffer
-
- Direct Known Subclasses:
Int32NominalBuffer
,UInt16NominalBuffer
,UInt2NominalBuffer
,UInt4NominalBuffer
,UInt8NominalBuffer
public abstract class NominalBuffer extends java.lang.Object
Temporary random access buffer that can be used to define aCategoricalColumn
.- Author:
- Gisa Meier
- See Also:
Buffers
-
-
Field Summary
Fields Modifier and Type Field Description protected ColumnType<java.lang.String>
type
-
Constructor Summary
Constructors Modifier Constructor Description protected
NominalBuffer(ColumnType<java.lang.String> type)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
differentValues()
Returns the number of different values that were fed into this buffer.abstract java.lang.String
get(int index)
Retrieves the value at the given index.abstract IntegerFormats.Format
indexFormat()
abstract void
set(int index, java.lang.String value)
Sets the data at the given index to the given value.abstract boolean
setSave(int index, java.lang.String value)
Tries to set the data at the given index to the given value.abstract int
size()
abstract CategoricalColumn
toBooleanColumn(java.lang.String positiveValue)
Creates a boolean column with the given positive value if the dictionary has at most two values.abstract CategoricalColumn
toColumn()
Returns a column of the given type using the buffer's data.java.lang.String
toString()
-
-
-
Field Detail
-
type
protected final ColumnType<java.lang.String> type
-
-
Constructor Detail
-
NominalBuffer
protected NominalBuffer(ColumnType<java.lang.String> type)
-
-
Method Detail
-
get
public abstract java.lang.String get(int index)
Retrieves the value at the given index. This method is thread-safe and can be used alongside invocations ofset(int, java.lang.String)
andsetSave(int, java.lang.String)
. However, this method might not return the latest value set on another thread.- Parameters:
index
- the index to look up- Returns:
- the value at the index
-
set
public abstract void set(int index, java.lang.String value)
Sets the data at the given index to the given value.- Parameters:
index
- the index where the value should be setvalue
- the value to set- Throws:
java.lang.IllegalStateException
- if called after the buffer was used to create aColumn
-
setSave
public abstract boolean setSave(int index, java.lang.String value)
Tries to set the data at the given index to the given value. Returnstrue
if it worked andfalse
if the buffer format cannot hold any more different values.- Parameters:
index
- the index where the value should be setvalue
- the value to set- Returns:
false
if the buffer contained already to many different values to take this value,true
otherwise- Throws:
java.lang.IllegalStateException
- if called after the buffer was used to create aColumn
-
differentValues
public abstract int differentValues()
Returns the number of different values that were fed into this buffer.null
values are not counted.- Returns:
- the number of different values
-
indexFormat
public abstract IntegerFormats.Format indexFormat()
- Returns:
- the category index format of the buffer determining the maximal number of categories
-
size
public abstract int size()
- Returns:
- the size of the buffer
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toColumn
public abstract CategoricalColumn toColumn()
Returns a column of the given type using the buffer's data. The buffer becomes read-only. In contrast to constructing a new buffer from a column this method does not copy the data.- Returns:
- the categorical column
-
toBooleanColumn
public abstract CategoricalColumn toBooleanColumn(java.lang.String positiveValue)
Creates a boolean column with the given positive value if the dictionary has at most two values. The positive value must be either one of the dictionary values, making the other value, if it exists, negative. Or in case of a dictionary with only one value the positive value can benull
making the only value negative.- Parameters:
positiveValue
- the positive value ornull
- Returns:
- a categorical column with a boolean
Dictionary
- Throws:
java.lang.IllegalArgumentException
- if the given positive value is not one of the values, if there are more than two values in the dictionary or if positive value isnull
in case there are two values in the dictionary
-
-