public abstract class FoundEntriesObject extends Object implements FoundEntries
Modifier and Type | Field and Description |
---|---|
protected boolean |
addNewOnesFirst |
protected DatabaseEntryObject |
buffer |
protected Database |
database |
protected EventDispatcher |
dispatcher |
protected IntArray |
ids |
protected String |
indexName |
protected OutputStream |
indexRecorder |
protected boolean |
isAllInclusive |
protected int |
mySortID |
protected boolean |
needCompact |
protected DatabaseEntryObject |
searcher |
protected Comparer |
sortComparer |
protected int[] |
sortCriteria |
protected boolean |
sortState |
protected WeakSet |
views |
BOOLEAN, BYTE_ARRAY, CREATED_FIELD, DATE, DATE_TIME, DECIMAL, DOUBLE, FIRST_SPECIAL_FIELD, FLAG_SYNCHRONIZED, FLAGS_FIELD, INTEGER, JAVA_OBJECT, LONG, MAX_ID, MODIFIED_BY_FIELD, MODIFIED_FIELD, NAME_FIELD, OBJECT_BYTES_FIELD, OBJECT_TEXT_FIELD, OID_FIELD, OPTION_ERROR_ON_NEED_REINDEX, PLAIN_DATE, PLAIN_TIME, reservedFieldHeaders, reservedFieldIDs, reservedFieldNames, reservedFieldTypes, SORT_DATE_ONLY, SORT_IGNORE_CASE, SORT_TIME_ONLY, SORT_UNKNOWN_IS_GREATER_THAN_KNOWN, SORT_UNKNOWN_IS_LESS_THAN_KNOWN, STRING, TIME, TIMESTAMP
Modifier | Constructor and Description |
---|---|
protected |
FoundEntriesObject(Database database) |
Modifier and Type | Method and Description |
---|---|
int |
add(DatabaseEntry entry)
This saves a new entry to the database AND adds it to this FoundEntries
object.
|
int |
addData(Object data)
Add a new entry using the data object.
|
protected abstract void |
addEntriesFrom(FoundEntriesObject other,
int first,
int num) |
void |
change()
Mark the FoundEntries as having been changed in some way.
|
protected void |
checkView(EntriesView view) |
protected abstract void |
clearEntries() |
protected abstract void |
copyEntriesFrom(FoundEntriesObject other,
int first,
int num) |
protected void |
copyStateFrom(FoundEntriesObject fe) |
void |
delete(int index)
This deletes the data AND removes it from this FoundEntries list.
|
protected void |
deleted(int index) |
protected void |
dispatchEvent(int type) |
protected abstract int |
doAdd(DatabaseEntryObject entry) |
protected abstract int |
doChange(int index,
DatabaseEntryObject entry) |
protected abstract void |
doDelete(int index,
DatabaseEntryObject entry) |
protected abstract void |
doErase(int index,
DatabaseEntryObject entry) |
protected abstract void |
doExclude(int index) |
protected abstract int |
doInclude(DatabaseEntryObject entry) |
protected abstract void |
doLoad(int index,
DatabaseEntryObject entry) |
protected abstract boolean |
doSortMe(Handle h,
Comparer c) |
protected abstract int |
doStore(int index,
DatabaseEntryObject entry) |
protected abstract void |
doUpdate(int index,
DatabaseEntryObject entry) |
void |
erase(int index)
This erases the data without marking it as deleted AND removes it from this FoundEntries list.
|
void |
exclude(DatabaseEntry entry)
Exclude the entry from this FoundEntries if it is in it.
|
void |
exclude(int index)
Exclude the entry from this FoundEntries.
|
boolean |
excludeAll(Handle h,
EntriesView viewFromOtherFoundEntries)
Exclude all the entries as specified from the view of another FoundEntries
from this FoundEntries.
|
IntArray |
filterAll(Handle h,
ObjectFinder finder,
IntArray dest)
Find, using an entry by entry sequential search, all entries in the FoundEntries that match the
criteria as specified by the selector.
|
long |
findAll(Handle h,
EntrySelector selector)
Find, using a binary chop search, all entries in the FoundEntries that match the
criteria as specified by the selector.
|
IntArray |
findAll(Handle h,
EntrySelector selector,
IntArray dest)
Find, using a binary chop search, all entries in the FoundEntries that match the
criteria as specified by the selector.
|
long |
findAll(Handle h,
Object find,
boolean hasWildCards)
Find, using a binary chop search, all entries in the FoundEntries that match the
criteria as specified by the selector.
|
long |
findAll(Handle h,
Object find,
Comparer comparer)
This finds the last index of the entry which (according to the provided
Comparer) matches a search criteria.
|
int |
findFirst(Handle h,
Object searchData,
boolean hasWildCards)
Find the index of the first entry that matches a search criteria.
|
int |
findFirst(Handle h,
Object searchData,
Comparer comparer)
This finds the first index of the entry which (according to the provided
Comparer) matches a search criteria.
|
int |
findInsertIndex(DatabaseEntry toAdd)
Find the index where the specified entry would be added in the FoundEntries.
|
int |
findLast(Handle h,
Object searchData,
boolean hasWildCards)
Find the index of the last entry that matches a search criteria.
|
int |
findLast(Handle h,
Object searchData,
Comparer comparer)
This finds the last index of the entry which (according to the provided
ObjectFinder) matches a search criteria.
|
Range |
findRange(Handle h,
EntrySelector selector,
Range dest)
Find the range of indexes which match the search criteria as specified in the EntrySelector
parameter.
|
DatabaseEntry |
get(int index)
Get the data at the specified index, creating a new DatabaseEntry to get it from.
|
DatabaseEntry |
get(int index,
DatabaseEntry data)
Get the data at the specified index.
|
void |
get(int index,
int[] fieldIDs,
Object[] destinationObjectsAndWrappers)
A convenience method for retrieving only a limited set of field values for
a particular entry.
|
FoundEntries |
getCopy()
Get a full copy of this FoundEntries, including the entries themselves.
|
long |
getCurrentState()
Get the current changed state of the FoundEntries.
|
Object |
getData(int index)
Get the data object from the specified index.
|
Object |
getData(int index,
Object destination)
Get the data object from the specified index.
|
Database |
getDatabase()
Get the database associated with the FoundEntries.
|
EntriesView |
getEmptyView()
Get a new EntriesView for this FoundEntries that is initially empty.
|
EntrySelector |
getEntrySelector(Object searchData,
boolean hasWildCards)
Get an EntrySelector for the data given the search data.
|
EventDispatcher |
getEventDispatcher()
Get the EventDispatcher for this FoundEntries.
|
EntriesView |
getFullView(EntriesView dest)
Get an EntriesView that contains all the entries in this FoundEntries.
|
DatabaseEntry |
getNew()
Create a new DatabaseEntry for this FoundEntries.
|
protected FoundEntriesObject |
getNewFoundEntries() |
Comparer |
getSortComparer()
Return the current sort Comparer.
|
int[] |
getSortCriteria()
Return the current sort criteria if one was used.
|
int |
getSortEntry()
Return the ID of the sort used to sort the database by if one was used.
|
FoundEntries |
getSubSet(EntriesView view)
Get a SubSet of this FoundEntries using the indexes included in the view.
|
boolean |
hasChangedSince(long previousState)
Return if the FoundEntries has changed since the previous state.
|
int |
include(DatabaseEntry entry)
Add an entry to the FoundEntries if it was not added before.
|
boolean |
includeAll(Handle h,
EntriesView viewFromOtherFoundEntries)
Include all the entries as specified from the view of another FoundEntries
in this FoundEntries.
|
boolean |
includeExclude(Handle h,
EntriesView viewFromOtherFoundEntries,
boolean isInclude) |
protected abstract void |
indexFromFoundEntries(FoundEntries entries) |
boolean |
isAllInclusive()
If a FoundEntries is all inclusive then adding entries to the database will automatically
add the new entries to the FoundEntries.
|
boolean |
isSorted()
Return if the entries are sorted.
|
protected abstract boolean |
readFrom(InputStream stream,
Handle h,
int size) |
protected void |
recordChange(int oldIndex,
int newIndex,
DatabaseEntry e)
If new Index is -1 the entry at oldIndex was deleted and the entry e will be null.
|
boolean |
searchIsCompatibleWithSortState(int[] criteria)
Check if the proposed search criteria is compatible with the FoundEntries current sort.
|
boolean |
searchWillFilter(Object searchCriteria) |
int |
set(int index,
DatabaseEntry entry)
Add a new entry using the data object to the end of the FoundEntries.
|
void |
setAddNewEntriesFirst(boolean addFirst)
If you add a new entry to a sorted FoundEntries, then that new entry may match
exactly other entries already in the FoundEntries.
|
void |
setAllInclusive(boolean allInclusive)
If a FoundEntries is all inclusive then adding entries to the database will automatically
add the new entries to the FoundEntries.
|
int |
setData(int index,
Object data)
Set the data at the specified index using the data object.
|
protected void |
setSort(int sortID,
Comparer c) |
int |
size()
Return the number of entries in the FoundEntries.
|
Handle |
sort(Comparer comparer)
Sort the found entries in a separate thread.
|
FoundEntries |
sort(Handle h,
Comparer comparer)
This sorts the FoundEntries in the current thread using the specified Comparer.
|
FoundEntries |
sort(Handle h,
int sortID)
This sorts the FoundEntries in the current thread using the specified sortID.
|
FoundEntries |
sort(Handle h,
int[] criteria)
This sorts the FoundEntries in the current thread using the specified sortID.
|
Handle |
sort(int sortID)
Sort the found entries in a separate thread.
|
Handle |
sort(int[] criteria)
Sort the found entries in a separate thread.
|
protected boolean |
sortMe(Handle h,
Comparer c,
int sortID) |
int |
store(int index,
DatabaseEntry entry)
This saves changes to the entry but does not modify its special synchronization fields.
|
String |
toString()
Return a String representation of this object.
|
boolean |
validateEntries()
This is used for debugging only.
|
protected boolean |
writeAndReturnTrue(OutputStream stream,
ByteArray out,
Handle h) |
protected abstract boolean |
writeTo(OutputStream stream,
Handle h)
Write the FoundEntries to an OutputStream and put in the returnValue of the Handle,
a Long object holding the number of bytes written.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
indexOf
protected IntArray ids
protected Database database
protected DatabaseEntryObject buffer
protected DatabaseEntryObject searcher
protected boolean sortState
protected int mySortID
protected int[] sortCriteria
protected Comparer sortComparer
protected boolean addNewOnesFirst
protected boolean isAllInclusive
protected WeakSet views
protected EventDispatcher dispatcher
protected String indexName
protected OutputStream indexRecorder
protected boolean needCompact
protected FoundEntriesObject(Database database)
public boolean validateEntries()
public long findAll(Handle h, Object find, boolean hasWildCards) throws IOException, StoppedException
FoundEntries
findAll
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the search.hasWildCards
- set this true if the search data has wildcard data (e.g. '*' characters).StoppedException
- if the provided handle is not null and stop() was called on the handle.IOException
public long findAll(Handle h, Object find, Comparer comparer) throws IOException, StoppedException
FoundEntries
During the search the comparer will have its compare() method called with the searchData parameter object as the first parameter and a DatabaseEntry object as the second parameter. The comparer should return
<0 if the DatabaseEntry is considered greater than the search data. 0 if the DatabaseEntry is considered to match the search data. >0 if the DatabaseEntry is considered less than the search data.The Comparer should NOT take into account if the SORT_DESCENDING option is set - that will be taken care of by the search routine.
findAll
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the process.find
- search data possibly used by the comparer.comparer
- a comparer to compare the search data with the data in records of the FoundEntries.IOException
- on an I/O Error.StoppedException
- if the provided handle is not null and stop() was called on the handle.public long findAll(Handle h, EntrySelector selector) throws IOException, StoppedException
FoundEntries
findAll
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the search.selector
- an EntrySelector created using getEntrySelector().IOException
- on an I/O Error.StoppedException
- if the provided handle is not null and stop() was called on the handle.public Database getDatabase()
getDatabase
in interface FoundEntries
public DatabaseEntry getNew()
getNew
in interface FoundEntries
public long getCurrentState()
getCurrentState
in interface FoundEntries
public boolean hasChangedSince(long previousState)
hasChangedSince
in interface FoundEntries
public void change()
change
in interface FoundEntries
public void setAddNewEntriesFirst(boolean addFirst)
FoundEntries
setAddNewEntriesFirst
in interface FoundEntries
addFirst
- if this is true then the new entry is added before the matching entries.protected abstract boolean doSortMe(Handle h, Comparer c) throws IOException
IOException
protected void setSort(int sortID, Comparer c)
protected boolean sortMe(Handle h, Comparer c, int sortID) throws IOException
IOException
public Handle sort(int sortID) throws IllegalArgumentException
FoundEntries
sort
in interface FoundEntries
sortID
- The sortID in the database to sort by.IllegalArgumentException
public Handle sort(int[] criteria)
FoundEntries
sort
in interface FoundEntries
criteria
- The criteria for sorting.public Handle sort(Comparer comparer)
FoundEntries
sort
in interface FoundEntries
comparer
- a Comparer used to compare each entry.public FoundEntries sort(Handle h, int sortID) throws IOException
FoundEntries
sort
in interface FoundEntries
h
- the Handle for monitoring the sort. This can be null but if it is the possibility
exists that the sort may run natively thereby not giving other threads a chance to run.sortID
- The sortID in the database to sort by.IOException
- if there was an error reading data for sorting.public FoundEntries sort(Handle h, int[] criteria) throws IOException
FoundEntries
sort
in interface FoundEntries
h
- the Handle for monitoring the sort. This can be null but if it is the possibility
exists that the sort may run natively thereby not giving other threads a chance to run.criteria
- the sort criteria.IOException
- if there was an error reading data for sorting.public FoundEntries sort(Handle h, Comparer comparer) throws IOException
FoundEntries
sort
in interface FoundEntries
h
- the Handle for monitoring the sort. This can be null but if it is the possibility
exists that the sort may run natively thereby not giving other threads a chance to run.comparer
- a Comparer used to compare each entry.IOException
- if there was an error reading data for sorting.public boolean isSorted()
FoundEntries
isSorted
in interface FoundEntries
public int getSortEntry()
FoundEntries
getSortEntry
in interface FoundEntries
public int[] getSortCriteria()
FoundEntries
getSortCriteria
in interface FoundEntries
public Comparer getSortComparer()
FoundEntries
getSortComparer
in interface FoundEntries
public int size()
FoundEntries
size
in interface FoundEntries
public DatabaseEntry get(int index, DatabaseEntry data) throws IOException
get
in interface FoundEntries
index
- The index to read from.data
- a destination DatabaseEntry, which can be null.IOException
- on error.public DatabaseEntry get(int index) throws IOException
get
in interface FoundEntries
index
- The index to read from.data
- a destination DatabaseEntry, which can be null.IOException
- on error.public Object getData(int index, Object destination) throws IllegalStateException, IllegalArgumentException, IOException
getData
in interface FoundEntries
index
- the index in the FoundEntries object.destination
- a destination object. If this is null a new one will be created if
possible.IllegalArgumentException
- if the destination object is not the right type.IllegalStateException
- if a new object was requested but could not be created.IOException
- if there is an error reading the data.public Object getData(int index) throws IllegalStateException, IOException
getData
in interface FoundEntries
index
- the index in the FoundEntries object.IllegalStateException
- if a new object could not be created.IOException
- if there is an error reading the data.public int setData(int index, Object data) throws IllegalArgumentException, IOException
setData
in interface FoundEntries
index
- the index in the FoundEntries object.data
- the data object.IllegalArgumentException
- if the destination object is not the right type.IOException
- if there is an error writing the data.public int addData(Object data) throws IllegalArgumentException, IOException
addData
in interface FoundEntries
data
- the data object.IllegalArgumentException
- if the destination object is not the right type.IOException
- if there is an error writing the data.public int set(int index, DatabaseEntry entry) throws IOException
set
in interface FoundEntries
data
- the data object.IllegalArgumentException
- if the destination object is not the right type.IOException
- if there is an error writing the data.public int store(int index, DatabaseEntry entry) throws IOException
FoundEntries
store
in interface FoundEntries
index
- The index of the entry.entry
- the changed entry.IOException
- on error.public int add(DatabaseEntry entry) throws IOException
add
in interface FoundEntries
IOException
public void delete(int index) throws IOException
FoundEntries
delete
in interface FoundEntries
IOException
public void erase(int index) throws IOException
FoundEntries
erase
in interface FoundEntries
IOException
public int include(DatabaseEntry entry) throws IllegalArgumentException, IOException
FoundEntries
include
in interface FoundEntries
entry
- the entry to include.IllegalArgumentException
- if the entry is not a valid saved entry.IOException
- on error.public void exclude(DatabaseEntry entry) throws IllegalArgumentException, IOException
FoundEntries
exclude
in interface FoundEntries
entry
- the entry to exclude.IllegalArgumentException
- if the entry is not a valid saved entry.IOException
- on error.public void exclude(int index) throws IOException
FoundEntries
exclude
in interface FoundEntries
index
- the index of the entry.IOException
- on error.protected void deleted(int index) throws IOException
IOException
protected abstract int doAdd(DatabaseEntryObject entry) throws IOException
IOException
protected abstract int doChange(int index, DatabaseEntryObject entry) throws IOException
IOException
protected abstract int doStore(int index, DatabaseEntryObject entry) throws IOException
IOException
protected abstract void doDelete(int index, DatabaseEntryObject entry) throws IOException
IOException
protected abstract void doErase(int index, DatabaseEntryObject entry) throws IOException
IOException
protected abstract int doInclude(DatabaseEntryObject entry) throws IOException
IOException
protected abstract void doExclude(int index) throws IOException
IOException
protected abstract void doUpdate(int index, DatabaseEntryObject entry) throws IOException
IOException
protected abstract void doLoad(int index, DatabaseEntryObject entry) throws IOException
IOException
protected abstract void indexFromFoundEntries(FoundEntries entries)
protected abstract boolean readFrom(InputStream stream, Handle h, int size) throws IOException
IOException
protected abstract boolean writeTo(OutputStream stream, Handle h) throws IOException
IOException
protected boolean writeAndReturnTrue(OutputStream stream, ByteArray out, Handle h) throws IOException
IOException
public boolean isAllInclusive()
FoundEntries
isAllInclusive
in interface FoundEntries
public void setAllInclusive(boolean allInclusive)
FoundEntries
setAllInclusive
in interface FoundEntries
allInclusive
- true to set the FoundEntries to all inclusive, false to set to be not
all inclusive.public boolean searchIsCompatibleWithSortState(int[] criteria)
searchIsCompatibleWithSortState
in interface FoundEntries
criteria
- the proposed sort criteria.public boolean searchWillFilter(Object searchCriteria)
public Range findRange(Handle h, EntrySelector selector, Range dest) throws IOException
FoundEntries
findRange
in interface FoundEntries
h
- An optional handle that can be used to monitor the progress of the operation.selector
- An EntrySelector used to determine which entries to include in the range.dest
- An optional destination Range object.IOException
- On error reading the database.public IntArray findAll(Handle h, EntrySelector selector, IntArray dest) throws IOException
FoundEntries
findAll
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the search.selector
- an EntrySelector created using getEntrySelector().dest
- an optional destination IntArray.IOException
public IntArray filterAll(Handle h, ObjectFinder finder, IntArray dest) throws IOException
FoundEntries
filterAll
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the search.finder
- an ObjectFinder used to select the entries.dest
- an optional destination IntArray.IOException
protected void checkView(EntriesView view) throws IllegalArgumentException
IllegalArgumentException
public EntriesView getEmptyView()
FoundEntries
getEmptyView
in interface FoundEntries
protected void recordChange(int oldIndex, int newIndex, DatabaseEntry e) throws IOException
IOException
public EntriesView getFullView(EntriesView dest)
FoundEntries
getFullView
in interface FoundEntries
dest
- an optional EntriesView object to hold the data.public boolean includeExclude(Handle h, EntriesView viewFromOtherFoundEntries, boolean isInclude) throws IOException
IOException
public boolean includeAll(Handle h, EntriesView viewFromOtherFoundEntries) throws IOException
FoundEntries
includeAll
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the process.viewFromOtherFoundEntries
- a view into another FoundEntries object.IOException
public boolean excludeAll(Handle h, EntriesView viewFromOtherFoundEntries) throws IOException
FoundEntries
excludeAll
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the process.viewFromOtherFoundEntries
- a view into another FoundEntries object.IOException
protected abstract void copyEntriesFrom(FoundEntriesObject other, int first, int num)
protected abstract void clearEntries()
protected abstract void addEntriesFrom(FoundEntriesObject other, int first, int num)
protected void copyStateFrom(FoundEntriesObject fe)
protected FoundEntriesObject getNewFoundEntries()
public FoundEntries getCopy()
FoundEntries
getCopy
in interface FoundEntries
public FoundEntries getSubSet(EntriesView view) throws IllegalArgumentException
FoundEntries
getSubSet
in interface FoundEntries
IllegalArgumentException
public int findInsertIndex(DatabaseEntry toAdd) throws IOException
FoundEntries
findInsertIndex
in interface FoundEntries
IOException
public int findFirst(Handle h, Object searchData, Comparer comparer) throws IOException, IllegalStateException, HandleStoppedException
During the search the comparer will have its compare() method called with the searchData parameter object as the first parameter and a DatabaseEntry object as the second parameter. The comparer should return
<0 if the DatabaseEntry is considered greater than the search data. 0 if the DatabaseEntry is considered to match the search data. >0 if the DatabaseEntry is considered less than the search data.The Comparer should NOT take into account if the SORT_DESCENDING option is set - that will be taken care of by the search routine.
findFirst
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the process.searchData
- search data possibly used by the comparer - this can be null.comparer
- a comparer to compare the search data with the data in records of the FoundEntries.IOException
IllegalStateException
- if this FoundEntries is not sorted.HandleStoppedException
- if the operation was aborted.public int findLast(Handle h, Object searchData, Comparer comparer) throws IOException, IllegalStateException, HandleStoppedException
<0 if the DatabaseEntry is considered greater than the search data. 0 if the DatabaseEntry is considered to match the search data. >0 if the DatabaseEntry is considered less than the search data.The Comparer should NOT take into account if the SORT_DESCENDING option is set - that will be taken care of by the search routine.
findLast
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the process.searchData
- search data possibly used by the comparer.comparer
- a comparer to compare the search data with the data in records of the FoundEntries.IOException
IllegalStateException
- if this FoundEntries is not sorted.HandleStoppedException
- if the operation was aborted.public EntrySelector getEntrySelector(Object searchData, boolean hasWildCards) throws IllegalStateException
FoundEntries
getEntrySelector
in interface FoundEntries
searchData
- the data to search for.hasWildCards
- this should be true if the data contains wild cards.IllegalStateException
public int findFirst(Handle h, Object searchData, boolean hasWildCards) throws IOException, IllegalStateException, HandleStoppedException
FoundEntries
findFirst
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the process.searchData
- search data possibly used by the comparer.hasWildCards
- set this true if the search data has wildcard data (e.g. '*' characters).IOException
IllegalStateException
- if this FoundEntries is not sorted.HandleStoppedException
- if the operation was aborted.public int findLast(Handle h, Object searchData, boolean hasWildCards) throws IOException, IllegalStateException, HandleStoppedException
FoundEntries
findLast
in interface FoundEntries
h
- an optional handle used to monitor and possibly abort the process.searchData
- search data possibly used by the comparer.hasWildCards
- set this true if the search data has wildcard data (e.g. '*' characters).IOException
IllegalStateException
- if this FoundEntries is not sorted.HandleStoppedException
- if the operation was aborted.public EventDispatcher getEventDispatcher()
FoundEntries
getEventDispatcher
in interface FoundEntries
protected void dispatchEvent(int type)
public String toString()
Object
public void get(int index, int[] fieldIDs, Object[] destinationObjectsAndWrappers) throws IOException
FoundEntries
get
in interface FoundEntries
index
- the index of the entry.fieldIDs
- the field IDs.IOException