ewe.database
Class FoundEntriesObject

java.lang.Object
  extended byewe.database.FoundEntriesObject
All Implemented Interfaces:
DatabaseTypes, FoundEntries
Direct Known Subclasses:
RecordFoundEntries

public abstract class FoundEntriesObject
extends Object
implements FoundEntries


Field Summary
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  Lock lock
           
protected  int mySortID
           
protected  boolean needCompact
           
protected  DatabaseEntryObject searcher
           
protected  Comparer sortComparer
           
protected  int[] sortCriteria
           
protected  boolean sortState
           
protected  WeakSet views
           
 
Fields inherited from interface ewe.database.DatabaseTypes
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, 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
 
Constructor Summary
protected FoundEntriesObject(Database database)
           
 
Method Summary
 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.
 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.
 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.
 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.
 boolean validateEntries()
           
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, an ewe.sys.Long object holding the number of bytes written.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 
Methods inherited from interface ewe.database.FoundEntries
indexOf
 

Field Detail

ids

protected IntArray ids

database

protected Database database

buffer

protected DatabaseEntryObject buffer

searcher

protected DatabaseEntryObject searcher

sortState

protected boolean sortState

mySortID

protected int mySortID

sortCriteria

protected int[] sortCriteria

sortComparer

protected Comparer sortComparer

addNewOnesFirst

protected boolean addNewOnesFirst

lock

protected Lock lock

isAllInclusive

protected boolean isAllInclusive

views

protected WeakSet views

dispatcher

protected EventDispatcher dispatcher

indexName

protected String indexName

indexRecorder

protected OutputStream indexRecorder

needCompact

protected boolean needCompact
Constructor Detail

FoundEntriesObject

protected FoundEntriesObject(Database database)
Method Detail

validateEntries

public boolean validateEntries()

getDatabase

public Database getDatabase()
Get the database associated with the FoundEntries.

Specified by:
getDatabase in interface FoundEntries

getNew

public DatabaseEntry getNew()
Create a new DatabaseEntry for this FoundEntries.

Specified by:
getNew in interface FoundEntries

getCurrentState

public long getCurrentState()
Get the current changed state of the FoundEntries. You can check if the FoundEntries have been changed later by calling hasChangedSince(). The changed state does not have to do with the data stored in the database but rather whether the internal index table has changed. If this FoundEntries is stored in a file then if it has changed since the last state then it would need to be saved again.

Specified by:
getCurrentState in interface FoundEntries
Returns:
a reference to its current state.

hasChangedSince

public boolean hasChangedSince(long previousState)
Return if the FoundEntries has changed since the previous state.

Specified by:
hasChangedSince in interface FoundEntries

change

public void change()
Mark the FoundEntries as having been changed in some way.

Specified by:
change in interface FoundEntries

setAddNewEntriesFirst

public void setAddNewEntriesFirst(boolean addFirst)
Description copied from interface: FoundEntries
If you add a new entry to a sorted FoundEntries, then that new entry may match exactly other entries already in the FoundEntries. The FoundEntries then must decide whether to add the new one before the other matching entries or after the other matching entries. This method tells the FoundEntries whether to add the new one before or after(the default).

Specified by:
setAddNewEntriesFirst in interface FoundEntries
Parameters:
addFirst - if this is true then the new entry is added before the matching entries.

doSortMe

protected abstract boolean doSortMe(Handle h,
                                    Comparer c)
                             throws IOException
Throws:
IOException

setSort

protected void setSort(int sortID,
                       Comparer c)

sortMe

protected boolean sortMe(Handle h,
                         Comparer c,
                         int sortID)
                  throws IOException
Throws:
IOException

sort

public Handle sort(int sortID)
            throws IllegalArgumentException
Description copied from interface: FoundEntries
Sort the found entries in a separate thread.

Specified by:
sort in interface FoundEntries
Parameters:
sortID - The sortID in the database to sort by.
Returns:
a Handle that you can use to monitor the sorting. When the Handle reports success the returnValue of the handle will hold a new FoundEntries object which contains the entries re-sorted by the specified id.
Throws:
IllegalArgumentException

sort

public Handle sort(int[] criteria)
Description copied from interface: FoundEntries
Sort the found entries in a separate thread. If there is an error or the sorting is aborted the FoundEntries will be in its original state.

Specified by:
sort in interface FoundEntries
Parameters:
criteria - The criteria for sorting.
Returns:
a Handle that you can use to monitor the sorting. When the Handle reports success the returnValue of the handle will hold a new FoundEntries object which contains the entries re-sorted by the specified criteria.

sort

public Handle sort(Comparer comparer)
Description copied from interface: FoundEntries
Sort the found entries in a separate thread.

Specified by:
sort in interface FoundEntries
Parameters:
comparer - a Comparer used to compare each entry.
Returns:
a Handle that you can use to monitor the sorting. When the Handle reports success the returnValue of the handle will hold a new FoundEntries object which contains the entries re-sorted by the specified comparer.

sort

public FoundEntries sort(Handle h,
                         int sortID)
                  throws IOException
Description copied from interface: FoundEntries
This sorts the FoundEntries in the current thread using the specified sortID. Other threads will be allowed to run and can monitor the progress and stop the sort by calling stop() on the handle (if it is not null).

Specified by:
sort in interface FoundEntries
Parameters:
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.
Returns:
a new FoundEntries or null if the sort was aborted.
Throws:
IOException - if there was an error reading data for sorting.

sort

public FoundEntries sort(Handle h,
                         int[] criteria)
                  throws IOException
Description copied from interface: FoundEntries
This sorts the FoundEntries in the current thread using the specified sortID. Other threads will be allowed to run and can monitor the progress and stop the sort by calling stop() on the handle (if it is not null).

Specified by:
sort in interface FoundEntries
Parameters:
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.
Returns:
a new FoundEntries or null if the sort was aborted.
Throws:
IOException - if there was an error reading data for sorting.

sort

public FoundEntries sort(Handle h,
                         Comparer comparer)
                  throws IOException
Description copied from interface: FoundEntries
This sorts the FoundEntries in the current thread using the specified Comparer. Other threads will be allowed to run and can monitor the progress and stop the sort by calling stop() on the handle (if it is not null).

Specified by:
sort in interface FoundEntries
Parameters:
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.
Returns:
a new FoundEntries or null if the sort was aborted.
Throws:
IOException - if there was an error reading data for sorting.

isSorted

public boolean isSorted()
Description copied from interface: FoundEntries
Return if the entries are sorted.

Specified by:
isSorted in interface FoundEntries

getSortEntry

public int getSortEntry()
Description copied from interface: FoundEntries
Return the ID of the sort used to sort the database by if one was used. If a non-standard Comparer was used, or if the entries are not sorted, this will return 0.

Specified by:
getSortEntry in interface FoundEntries

getSortCriteria

public int[] getSortCriteria()
Description copied from interface: FoundEntries
Return the current sort criteria if one was used. If a non-standard Comparer was used, or if the entries are not sorted, this will return null.

Specified by:
getSortCriteria in interface FoundEntries

getSortComparer

public Comparer getSortComparer()
Description copied from interface: FoundEntries
Return the current sort Comparer. This will always return a valid object as long as the FoundEntries was sorted via some method.

Specified by:
getSortComparer in interface FoundEntries

size

public int size()
Description copied from interface: FoundEntries
Return the number of entries in the FoundEntries.

Specified by:
size in interface FoundEntries

get

public DatabaseEntry get(int index,
                         DatabaseEntry data)
                  throws IOException
Get the data at the specified index.

Specified by:
get in interface FoundEntries
Parameters:
index - The index to read from.
data - a destination DatabaseEntry, which can be null.
Returns:
the destination DatabaseEntry or a newly created one.
Throws:
IOException - on error.

get

public DatabaseEntry get(int index)
                  throws IOException
Get the data at the specified index, creating a new DatabaseEntry to get it from.

Specified by:
get in interface FoundEntries
Parameters:
index - The index to read from.
Returns:
the destination DatabaseEntry or a newly created one.
Throws:
IOException - on error.

getData

public Object getData(int index,
                      Object destination)
               throws IllegalStateException,
                      IllegalArgumentException,
                      IOException
Get the data object from the specified index.

Specified by:
getData in interface FoundEntries
Parameters:
index - the index in the FoundEntries object.
destination - a destination object. If this is null a new one will be created if possible.
Returns:
the destination or new object.
Throws:
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.

getData

public Object getData(int index)
               throws IllegalStateException,
                      IOException
Get the data object from the specified index.

Specified by:
getData in interface FoundEntries
Parameters:
index - the index in the FoundEntries object.
Returns:
the data in a new Object.
Throws:
IllegalStateException - if a new object could not be created.
IOException - if there is an error reading the data.

setData

public int setData(int index,
                   Object data)
            throws IllegalArgumentException,
                   IOException
Set the data at the specified index using the data object. This will maintain the sort order.

Specified by:
setData in interface FoundEntries
Parameters:
index - the index in the FoundEntries object.
data - the data object.
Returns:
the new index of the data.
Throws:
IllegalArgumentException - if the destination object is not the right type.
IOException - if there is an error writing the data.

addData

public int addData(Object data)
            throws IllegalArgumentException,
                   IOException
Add a new entry using the data object. This maintains the sort order.

Specified by:
addData in interface FoundEntries
Parameters:
data - the data object.
Returns:
the index of the new entry.
Throws:
IllegalArgumentException - if the destination object is not the right type.
IOException - if there is an error writing the data.

set

public int set(int index,
               DatabaseEntry entry)
        throws IOException
Add a new entry using the data object to the end of the FoundEntries. This does not maintains the sort order.

Specified by:
set in interface FoundEntries
Parameters:
index - The index of the entry.
entry - the changed entry.
Returns:
the index of the new entry.
Throws:
IllegalArgumentException - if the destination object is not the right type.
IOException - if there is an error writing the data.

store

public int store(int index,
                 DatabaseEntry entry)
          throws IOException
Description copied from interface: FoundEntries
This saves changes to the entry but does not modify its special synchronization fields. It will rearrange current entries to maintain its sort order.

Specified by:
store in interface FoundEntries
Parameters:
index - The index of the entry.
entry - the changed entry.
Returns:
the index where the entry is now.
Throws:
IOException - on error.

add

public int add(DatabaseEntry entry)
        throws IOException
This saves a new entry to the database AND adds it to this FoundEntries object. It returns the index at which the new value was placed such that it maintains the sort order.

Specified by:
add in interface FoundEntries
Throws:
IOException

delete

public void delete(int index)
            throws IOException
Description copied from interface: FoundEntries
This deletes the data AND removes it from this FoundEntries list.

Specified by:
delete in interface FoundEntries
Throws:
IOException

erase

public void erase(int index)
           throws IOException
Description copied from interface: FoundEntries
This erases the data without marking it as deleted AND removes it from this FoundEntries list.

Specified by:
erase in interface FoundEntries
Throws:
IOException

include

public int include(DatabaseEntry entry)
            throws IllegalArgumentException,
                   IOException
Description copied from interface: FoundEntries
Add an entry to the FoundEntries if it was not added before. This does not change the data in the database.

Specified by:
include in interface FoundEntries
Parameters:
entry - the entry to include.
Returns:
the index of the entry as it is now in the database.
Throws:
IOException - on error.
IllegalArgumentException - if the entry is not a valid saved entry.

exclude

public void exclude(DatabaseEntry entry)
             throws IllegalArgumentException,
                    IOException
Description copied from interface: FoundEntries
Exclude the entry from this FoundEntries if it is in it.

Specified by:
exclude in interface FoundEntries
Parameters:
entry - the entry to exclude.
Throws:
IllegalArgumentException - if the entry is not a valid saved entry.
IOException - on error.

exclude

public void exclude(int index)
             throws IOException
Description copied from interface: FoundEntries
Exclude the entry from this FoundEntries.

Specified by:
exclude in interface FoundEntries
Parameters:
index - the index of the entry.
Throws:
IOException - on error.

deleted

protected void deleted(int index)
                throws IOException
Throws:
IOException

doAdd

protected abstract int doAdd(DatabaseEntryObject entry)
                      throws IOException
Throws:
IOException

doChange

protected abstract int doChange(int index,
                                DatabaseEntryObject entry)
                         throws IOException
Throws:
IOException

doStore

protected abstract int doStore(int index,
                               DatabaseEntryObject entry)
                        throws IOException
Throws:
IOException

doDelete

protected abstract void doDelete(int index,
                                 DatabaseEntryObject entry)
                          throws IOException
Throws:
IOException

doErase

protected abstract void doErase(int index,
                                DatabaseEntryObject entry)
                         throws IOException
Throws:
IOException

doInclude

protected abstract int doInclude(DatabaseEntryObject entry)
                          throws IOException
Throws:
IOException

doExclude

protected abstract void doExclude(int index)
                           throws IOException
Throws:
IOException

doUpdate

protected abstract void doUpdate(int index,
                                 DatabaseEntryObject entry)
                          throws IOException
Throws:
IOException

doLoad

protected abstract void doLoad(int index,
                               DatabaseEntryObject entry)
                        throws IOException
Throws:
IOException

indexFromFoundEntries

protected abstract void indexFromFoundEntries(FoundEntries entries)

readFrom

protected abstract boolean readFrom(InputStream stream,
                                    Handle h,
                                    int size)
                             throws IOException
Throws:
IOException

writeTo

protected abstract boolean writeTo(OutputStream stream,
                                   Handle h)
                            throws IOException
Write the FoundEntries to an OutputStream and put in the returnValue of the Handle, an ewe.sys.Long object holding the number of bytes written. If stream is null then set the returnValue of the Handle to be an ewe.sys.Long object that holds the number of bytes needed.

Throws:
IOException

writeAndReturnTrue

protected boolean writeAndReturnTrue(OutputStream stream,
                                     ByteArray out,
                                     Handle h)
                              throws IOException
Throws:
IOException

isAllInclusive

public boolean isAllInclusive()
Description copied from interface: FoundEntries
If a FoundEntries is all inclusive then adding entries to the database will automatically add the new entries to the FoundEntries. FoundEntries associated with a DatabaseIndex are all inclusive.

Specified by:
isAllInclusive in interface FoundEntries
Returns:
true if the FoundEntries is considered all inclusive.

setAllInclusive

public void setAllInclusive(boolean allInclusive)
Description copied from interface: FoundEntries
If a FoundEntries is all inclusive then adding entries to the database will automatically add the new entries to the FoundEntries. FoundEntries associated with a DatabaseIndex are all inclusive.

Specified by:
setAllInclusive in interface FoundEntries
Parameters:
allInclusive - true to set the FoundEntries to all inclusive, false to set to be not all inclusive.

searchIsCompatibleWithSortState

public boolean searchIsCompatibleWithSortState(int[] criteria)
Check if the proposed search criteria is compatible with the FoundEntries current sort. If this returns false then a call to search() will have to filter all the data (i.e. step through each one in turn). If it returns true then a search() will perform a quick binary search on the data.

Specified by:
searchIsCompatibleWithSortState in interface FoundEntries
Parameters:
criteria - the proposed sort criteria.
Returns:
true if it is compatible with the current sort, false if not.

searchWillFilter

public boolean searchWillFilter(Object searchCriteria)

findRange

public Range findRange(Handle h,
                       EntrySelector selector,
                       Range dest)
                throws IOException
Description copied from interface: FoundEntries
Find the range of indexes which match the search criteria as specified in the EntrySelector parameter.

Specified by:
findRange in interface FoundEntries
Parameters:
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.
Returns:
The destination or new Range object. If it returns null then the search was aborted because the stop() method was called on the Handle. If it returns a Range where the "first" field is less than zero then this indicates that no entries match. Otherwise it will return a valid Range where the matching entries are specified by the "first" and "last" fields of the returned Range (first and last are both inclusive).
Throws:
IOException - On error reading the database.

findAll

public IntArray findAll(Handle h,
                        EntrySelector selector,
                        IntArray dest)
                 throws IOException
Description copied from interface: FoundEntries
Find, using a binary chop search, all entries in the FoundEntries that match the criteria as specified by the selector.

Specified by:
findAll in interface FoundEntries
Parameters:
h - an optional handle used to monitor and possibly abort the search.
selector - an EntrySelector created using getEntrySelector().
dest - an optional destination IntArray.
Returns:
the destination IntArray or a new IntArray if dest was null. If the operation was aborted, null will be returned.
Throws:
IOException

filterAll

public IntArray filterAll(Handle h,
                          ObjectFinder finder,
                          IntArray dest)
                   throws IOException
Description copied from interface: FoundEntries
Find, using an entry by entry sequential search, all entries in the FoundEntries that match the criteria as specified by the selector.

Specified by:
filterAll in interface FoundEntries
Parameters:
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.
Returns:
the destination IntArray or a new IntArray if dest was null. If the operation was aborted, null will be returned.
Throws:
IOException

checkView

protected void checkView(EntriesView view)
                  throws IllegalArgumentException
Throws:
IllegalArgumentException

getEmptyView

public EntriesView getEmptyView()
Description copied from interface: FoundEntries
Get a new EntriesView for this FoundEntries that is initially empty.

Specified by:
getEmptyView in interface FoundEntries

recordChange

protected void recordChange(int oldIndex,
                            int newIndex,
                            DatabaseEntry e)
                     throws IOException
If new Index is -1 the entry at oldIndex was deleted and the entry e will be null. If oldIndex was -1, then this is the addition of a new entry. Otherwise this indicates the repositioning of an entry.

Throws:
IOException

getFullView

public EntriesView getFullView(EntriesView dest)
Description copied from interface: FoundEntries
Get an EntriesView that contains all the entries in this FoundEntries.

Specified by:
getFullView in interface FoundEntries
Parameters:
dest - an optional EntriesView object to hold the data.
Returns:
the destination or new EntriesView.

includeExclude

public boolean includeExclude(Handle h,
                              EntriesView viewFromOtherFoundEntries,
                              boolean isInclude)
                       throws IOException
Throws:
IOException

includeAll

public boolean includeAll(Handle h,
                          EntriesView viewFromOtherFoundEntries)
                   throws IOException
Description copied from interface: FoundEntries
Include all the entries as specified from the view of another FoundEntries in this FoundEntries.

Specified by:
includeAll in interface FoundEntries
Parameters:
h - an optional handle used to monitor and possibly abort the process.
viewFromOtherFoundEntries - a view into another FoundEntries object.
Returns:
true if the operation completed successfully, false if it did not.
Throws:
IOException

excludeAll

public boolean excludeAll(Handle h,
                          EntriesView viewFromOtherFoundEntries)
                   throws IOException
Description copied from interface: FoundEntries
Exclude all the entries as specified from the view of another FoundEntries from this FoundEntries.

Specified by:
excludeAll in interface FoundEntries
Parameters:
h - an optional handle used to monitor and possibly abort the process.
viewFromOtherFoundEntries - a view into another FoundEntries object.
Returns:
true if the operation completed successfully, false if it did not.
Throws:
IOException

copyEntriesFrom

protected abstract void copyEntriesFrom(FoundEntriesObject other,
                                        int first,
                                        int num)

clearEntries

protected abstract void clearEntries()

addEntriesFrom

protected abstract void addEntriesFrom(FoundEntriesObject other,
                                       int first,
                                       int num)

copyStateFrom

protected void copyStateFrom(FoundEntriesObject fe)

getNewFoundEntries

protected FoundEntriesObject getNewFoundEntries()

getCopy

public FoundEntries getCopy()
Description copied from interface: FoundEntries
Get a full copy of this FoundEntries, including the entries themselves.

Specified by:
getCopy in interface FoundEntries

getSubSet

public FoundEntries getSubSet(EntriesView view)
                       throws IllegalArgumentException
Description copied from interface: FoundEntries
Get a SubSet of this FoundEntries using the indexes included in the view. If this FoundEntries is sorted the specified view will first be sorted before the new FoundEntries is created.

Specified by:
getSubSet in interface FoundEntries
Throws:
IllegalArgumentException

findInsertIndex

public int findInsertIndex(DatabaseEntry toAdd)
                    throws IOException
Description copied from interface: FoundEntries
Find the index where the specified entry would be added in the FoundEntries.

Specified by:
findInsertIndex in interface FoundEntries
Throws:
IOException

findFirst

public int findFirst(Handle h,
                     Object searchData,
                     Comparer comparer)
              throws IOException,
                     IllegalStateException,
                     HandleStoppedException
This finds the first index of the entry which (according to the provided Comparer) matches a search criteria. A binary search is done so it is assumed that all indexes between the one found by findFirst and by findLast inclusive (for the same finder) will also match. It returns -1 if no match could be found.

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.

Specified by:
findFirst in interface FoundEntries
Parameters:
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.
Returns:
the index of the first matching entry or -1 if no match was found.
Throws:
HandleStoppedException - if the operation was aborted.
IOException
IllegalStateException - if this FoundEntries is not sorted.

findLast

public int findLast(Handle h,
                    Object searchData,
                    Comparer comparer)
             throws IOException,
                    IllegalStateException,
                    HandleStoppedException
This finds the last index of the entry which (according to the provided ObjectFinder) matches a search criteria. A binary search is done so it is assumed that all indexes between the one found by findFirst and by findLast inclusive (for the same finder) will also match. It returns -1 if no match could be found. 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.

Specified by:
findLast in interface FoundEntries
Parameters:
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.
Returns:
the index of the first matching entry or -1 if no match was found.
Throws:
IOException
HandleStoppedException - if the operation was aborted.
IllegalStateException - if this FoundEntries is not sorted.

getEntrySelector

public EntrySelector getEntrySelector(Object searchData,
                                      boolean hasWildCards)
                               throws IllegalStateException
Description copied from interface: FoundEntries
Get an EntrySelector for the data given the search data.

Specified by:
getEntrySelector in interface FoundEntries
Parameters:
searchData - the data to search for.
hasWildCards - this should be true if the data contains wild cards.
Returns:
a new EntrySelector for the data given the search data.
Throws:
IllegalStateException

findFirst

public int findFirst(Handle h,
                     Object searchData,
                     boolean hasWildCards)
              throws IOException,
                     IllegalStateException,
                     HandleStoppedException
Description copied from interface: FoundEntries
Find the index of the first entry that matches a search criteria.

Specified by:
findFirst in interface FoundEntries
Parameters:
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).
Returns:
the index of the first matching entry or -1 if no match was found.
Throws:
HandleStoppedException - if the operation was aborted.
IllegalStateException - if this FoundEntries is not sorted.
IOException

findLast

public int findLast(Handle h,
                    Object searchData,
                    boolean hasWildCards)
             throws IOException,
                    IllegalStateException,
                    HandleStoppedException
Description copied from interface: FoundEntries
Find the index of the last entry that matches a search criteria.

Specified by:
findLast in interface FoundEntries
Parameters:
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).
Returns:
the index of the first matching entry or -1 if no match was found.
Throws:
HandleStoppedException - if the operation was aborted.
IllegalStateException - if this FoundEntries is not sorted.
IOException

getEventDispatcher

public EventDispatcher getEventDispatcher()
Description copied from interface: FoundEntries
Get the EventDispatcher for this FoundEntries.

Specified by:
getEventDispatcher in interface FoundEntries

dispatchEvent

protected void dispatchEvent(int type)