Class CollatedBaseSearch
- java.lang.Object
-
- com.mckoi.database.SelectableScheme
-
- com.mckoi.database.CollatedBaseSearch
-
- Direct Known Subclasses:
GTPrivMapDataSource.PrivMapSearch
,InsertSearch
public abstract class CollatedBaseSearch extends SelectableScheme
An implementation of SelectableScheme that is based on some collated set of data. This can be used to implement more advanced types of selectable schemes based on presistant indexes (see InsertSearch).The default implementation maintains no state,
Derived classes are required to implement 'copy', 'searchFirst' and 'searchLast' methods. With these basic methods, a selectable scheme can be generated provided the column is sorted in ascending order (value of row i is <= value of row i+1). Overwrite 'firstInCollationOrder', 'lastInCollationOrder' and 'addRangeToSet' methods for non sorted underlying sets.
Assumptions - the underlying column is sorted low to high (value of row i is <= value of row i+1).
-
-
Field Summary
-
Fields inherited from class com.mckoi.database.SelectableScheme
EMPTY_LIST, ONE_LIST
-
-
Constructor Summary
Constructors Constructor Description CollatedBaseSearch(TableDataSource table, int column)
The Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private IntegerVector
addRange(SelectableRange range, IntegerVector ivec)
Adds a range from this set to the given IntegerVector.protected IntegerVector
addRangeToSet(int start, int end, IntegerVector ivec)
Adds the set indexes to the list that represent the range of values between the start (inclusive) and end offset (inclusive) given.void
dispose()
Disposes and invalidates the BlindSearch.protected TObject
firstInCollationOrder()
Returns the first value of this column (in collated order).void
insert(int row)
This scheme doesn't take any notice of insertions or removals.protected TObject
lastInCollationOrder()
Returns the last value of this column (in collated order).private int
positionOfRangePoint(byte flag, TObject val)
Given a flag (FIRST_VALUE, LAST_VALUE, BEFORE_FIRST_VALUE or AFTER_LAST_VALUE) and a value which is either a place marker (first, last in set) or a TObject object, this will determine the position in this set of the range point.void
readFrom(java.io.InputStream in)
Reads the entire state of the scheme from the input stream.void
remove(int row)
This scheme doesn't take any notice of insertions or removals.protected abstract int
searchFirst(TObject val)
Finds the position in the collated set of the first value in the column equal to the given value.protected abstract int
searchLast(TObject val)
Finds the position in the collated set of the last value in the column equal to the given value.IntegerVector
selectAll()
These are the select operations that are the main purpose of the scheme.IntegerVector
selectRange(SelectableRange range)
Selects the given range of values from this index.IntegerVector
selectRange(SelectableRange[] ranges)
Selects a set of ranges from this index.protected int
setSize()
The size of the set (the number of rows in this column).void
writeTo(java.io.OutputStream out)
Writes the entire state of the scheme to the output stream.-
Methods inherited from class com.mckoi.database.SelectableScheme
copy, Debug, getCellContents, getColumn, getSubsetScheme, getSystem, getTable, internalOrderIndexSet, isImmutable, selectAllNonNull, selectBetween, selectEqual, selectFirst, selectGreater, selectGreaterOrEqual, selectLast, selectLess, selectLessOrEqual, selectNotEqual, selectNotFirst, selectNotLast, setImmutable, toString
-
-
-
-
Constructor Detail
-
CollatedBaseSearch
public CollatedBaseSearch(TableDataSource table, int column)
The Constructor.
-
-
Method Detail
-
insert
public void insert(int row)
This scheme doesn't take any notice of insertions or removals.- Specified by:
insert
in classSelectableScheme
-
remove
public void remove(int row)
This scheme doesn't take any notice of insertions or removals.- Specified by:
remove
in classSelectableScheme
-
readFrom
public void readFrom(java.io.InputStream in) throws java.io.IOException
Reads the entire state of the scheme from the input stream. This is a trivial case for BlindSearch which doesn't require any data to be stored.- Specified by:
readFrom
in classSelectableScheme
- Throws:
java.io.IOException
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOException
Writes the entire state of the scheme to the output stream. This is a trivial case for BlindSearch which doesn't require any data to be stored.- Specified by:
writeTo
in classSelectableScheme
- Throws:
java.io.IOException
-
dispose
public void dispose()
Disposes and invalidates the BlindSearch.- Specified by:
dispose
in classSelectableScheme
-
searchFirst
protected abstract int searchFirst(TObject val)
Finds the position in the collated set of the first value in the column equal to the given value. If the value is not to be found in the column, it returns -(insert_position + 1).
-
searchLast
protected abstract int searchLast(TObject val)
Finds the position in the collated set of the last value in the column equal to the given value. If the value is not to be found in the column, it returns -(insert_position + 1).
-
setSize
protected int setSize()
The size of the set (the number of rows in this column).
-
firstInCollationOrder
protected TObject firstInCollationOrder()
Returns the first value of this column (in collated order). For example, if the column contains (1, 4, 8} then '1' is returned.
-
lastInCollationOrder
protected TObject lastInCollationOrder()
Returns the last value of this column (in collated order). For example, if the column contains (1, 4, 8} then '8' is returned.
-
addRangeToSet
protected IntegerVector addRangeToSet(int start, int end, IntegerVector ivec)
Adds the set indexes to the list that represent the range of values between the start (inclusive) and end offset (inclusive) given.
-
selectAll
public IntegerVector selectAll()
Description copied from class:SelectableScheme
These are the select operations that are the main purpose of the scheme. They retrieve the given information from the set. Different schemes will have varying performance on different types of data sets. The select operations must *always* return a resultant row set that is sorted from lowest to highest.- Overrides:
selectAll
in classSelectableScheme
-
positionOfRangePoint
private int positionOfRangePoint(byte flag, TObject val)
Given a flag (FIRST_VALUE, LAST_VALUE, BEFORE_FIRST_VALUE or AFTER_LAST_VALUE) and a value which is either a place marker (first, last in set) or a TObject object, this will determine the position in this set of the range point. For example, we may want to know the index of the last instance of a particular number in a set of numbers which would be 'positionOfRangePoint(SelectableRange.LAST_VALUE, [number TObject])'.Note how the position is determined if the value is not found in the set.
-
addRange
private IntegerVector addRange(SelectableRange range, IntegerVector ivec)
Adds a range from this set to the given IntegerVector. IntegerVector may be null if a list has not yet been allocated for the range.
-
selectRange
public IntegerVector selectRange(SelectableRange range)
Description copied from class:SelectableScheme
Selects the given range of values from this index. The SelectableRange must contain a 'start' value that compares <= to the 'end' value.This must guarentee that the returned set is sorted from lowest to highest value.
- Specified by:
selectRange
in classSelectableScheme
-
selectRange
public IntegerVector selectRange(SelectableRange[] ranges)
Description copied from class:SelectableScheme
Selects a set of ranges from this index. The ranges must not overlap and each range must contain a 'start' value that compares <= to the 'end' value. Every range in the array must represent a range that's lower than the preceeding range (if it exists).If the above rules are enforced (as they must be) then this method will return a set that is sorted from lowest to highest value.
This must guarentee that the returned set is sorted from lowest to highest value.
- Specified by:
selectRange
in classSelectableScheme
-
-