Class StoredCollection<E>
- All Implemented Interfaces:
Cloneable,Iterable<E>,Collection<E>
- Direct Known Subclasses:
StoredEntrySet,StoredKeySet,StoredList,StoredValueSet
StoredContainer, provide implementations of most methods
in the Collection interface. Other methods, such as add(java.lang.Object, java.lang.Object)
and Collection.remove(java.lang.Object), are provided by concrete classes that extend this
class.
In addition, this class provides the following methods for stored collections only. Note that the use of these methods is not compatible with the standard Java collections interface.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default number of records read at one time by iterators. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddAll(Collection<? extends E> coll) Adds all of the elements in the specified collection to this collection (optional operation).booleancontainsAll(Collection<?> coll) Returns true if this collection contains all of the elements in the specified collection.booleanCompares the specified object with this collection for equality.intReturns the number of records read at one time by iterators returned by theiterator()method.inthashCode()iterator()Returns an iterator over the elements in this collection.iterator(boolean writeAllowed) Deprecated.join(StoredContainer[] indices, Object[] indexKeys, JoinConfig joinConfig) Returns an iterator representing an equality join of the indices and index key values specified.booleanremoveAll(Collection<?> coll) Removes all this collection's elements that are also contained in the specified collection (optional operation).booleanretainAll(Collection<?> coll) Retains only the elements in this collection that are contained in the specified collection (optional operation).voidsetIteratorBlockSize(int blockSize) Changes the number of records read at one time by iterators returned by theiterator()method.intsize()Returns a non-transactional count of the records in the collection or map.Returns an iterator over the elements in this collection.storedIterator(boolean writeAllowed) Returns a read or read-write iterator over the elements in this collection.Object[]toArray()Returns an array of all the elements in this collection.<T> T[]toArray(T[] a) Returns an array of all the elements in this collection whose runtime type is that of the specified array.toList()Returns a copy of this collection as an ArrayList.toString()Converts the collection to a string representation for debugging.Methods inherited from class com.sleepycat.collections.StoredContainer
areDuplicatesAllowed, areDuplicatesOrdered, areKeyRangesAllowed, areKeysRenumbered, clear, getCursorConfig, isEmpty, isOrdered, isSecondary, isTransactional, isWriteAllowedMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
add, clear, contains, isEmpty, parallelStream, remove, removeIf, spliterator, stream, toArray
-
Field Details
-
DEFAULT_ITERATOR_BLOCK_SIZE
public static final int DEFAULT_ITERATOR_BLOCK_SIZEThe default number of records read at one time by iterators.- See Also:
-
-
Method Details
-
getIteratorBlockSize
public int getIteratorBlockSize()Returns the number of records read at one time by iterators returned by theiterator()method. By default this value isDEFAULT_ITERATOR_BLOCK_SIZE. -
setIteratorBlockSize
public void setIteratorBlockSize(int blockSize) Changes the number of records read at one time by iterators returned by theiterator()method. By default this value isDEFAULT_ITERATOR_BLOCK_SIZE.- Throws:
IllegalArgumentException- if the blockSize is less than two.
-
iterator
Returns an iterator over the elements in this collection. The iterator will be read-only if the collection is read-only. This method conforms to theCollection.iterator()interface.The iterator returned by this method does not keep a database cursor open and therefore it does not need to be closed. It reads blocks of records as needed, opening and closing a cursor to read each block of records. The number of records per block is 10 by default and can be changed with
setIteratorBlockSize(int).Because this iterator does not keep a cursor open, if it is used without transactions, the iterator does not have cursor stability characteristics. In other words, the record at the current iterator position can be changed or deleted by another thread. To prevent this from happening, call this method within a transaction or use the
storedIterator()method instead. -
storedIterator
Returns an iterator over the elements in this collection. The iterator will be read-only if the collection is read-only. This method does not exist in the standardCollectioninterface.If
Iterator.setorIterator.removewill be called and the underlying Database is transactional, then a transaction must be active when calling this method and must remain active while using the iterator.Warning: The iterator returned must be explicitly closed using
StoredIterator.close()orStoredIterator.close(java.util.Iterator)to release the underlying database cursor resources.- Returns:
- a
StoredIteratorfor this collection. - See Also:
-
storedIterator
Returns a read or read-write iterator over the elements in this collection. This method does not exist in the standardCollectioninterface.If
Iterator.setorIterator.removewill be called and the underlying Database is transactional, then a transaction must be active when calling this method and must remain active while using the iterator.Warning: The iterator returned must be explicitly closed using
StoredIterator.close()orStoredIterator.close(java.util.Iterator)to release the underlying database cursor resources.- Parameters:
writeAllowed- is true to open a read-write iterator or false to open a read-only iterator. If the collection is read-only the iterator will always be read-only.- Returns:
- a
StoredIteratorfor this collection. - Throws:
IllegalStateException- if writeAllowed is true but the collection is read-only.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).- See Also:
-
iterator
Deprecated.Please usestoredIterator()orstoredIterator(boolean)instead. Because the iterator returned must be closed, the method nameiteratoris confusing since standard Java iterators do not need to be closed. -
toArray
Returns an array of all the elements in this collection. This method conforms to theCollection.toArray()interface.- Specified by:
toArrayin interfaceCollection<E>- Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
toArray
public <T> T[] toArray(T[] a) Returns an array of all the elements in this collection whose runtime type is that of the specified array. This method conforms to theCollection.toArray(Object[])interface.- Specified by:
toArrayin interfaceCollection<E>- Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
containsAll
Returns true if this collection contains all of the elements in the specified collection. This method conforms to theCollection.containsAll(java.util.Collection<?>)interface.- Specified by:
containsAllin interfaceCollection<E>- Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
addAll
Adds all of the elements in the specified collection to this collection (optional operation). This method calls theCollection.add(Object)method of the concrete collection class, which may or may not be supported. This method conforms to theCollection.addAll(java.util.Collection<? extends E>)interface.- Specified by:
addAllin interfaceCollection<E>- Throws:
UnsupportedOperationException- if the collection is read-only, or if the collection is indexed, or if the add method is not supported by the concrete collection.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
removeAll
Removes all this collection's elements that are also contained in the specified collection (optional operation). This method conforms to theCollection.removeAll(java.util.Collection<?>)interface.- Specified by:
removeAllin interfaceCollection<E>- Throws:
UnsupportedOperationException- if the collection is read-only.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
retainAll
Retains only the elements in this collection that are contained in the specified collection (optional operation). This method conforms to theCollection.removeAll(java.util.Collection<?>)interface.- Specified by:
retainAllin interfaceCollection<E>- Throws:
UnsupportedOperationException- if the collection is read-only.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
equals
Compares the specified object with this collection for equality. A value comparison is performed by this method and the stored values are compared rather than calling the equals() method of each element. This method conforms to theCollection.equals(java.lang.Object)interface.- Specified by:
equalsin interfaceCollection<E>- Overrides:
equalsin classObject- Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<E>- Overrides:
hashCodein classObject
-
toList
Returns a copy of this collection as an ArrayList. This is the same astoArray()but returns a collection instead of an array.- Returns:
- an
ArrayListcontaining a copy of all elements in this collection. - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
toString
Converts the collection to a string representation for debugging. WARNING: The returned string may be very large.- Overrides:
toStringin classObject- Returns:
- the string representation.
- Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
size
public int size()Description copied from class:StoredContainerReturns a non-transactional count of the records in the collection or map. This method conforms to theCollection.size()andMap.size()interfaces.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classStoredContainer
-
join
Returns an iterator representing an equality join of the indices and index key values specified. This method does not exist in the standardCollectioninterface.Warning: The iterator returned must be explicitly closed using
StoredIterator.close()orStoredIterator.close(java.util.Iterator)to release the underlying database cursor resources.The returned iterator supports only the two methods: hasNext() and next(). All other methods will throw UnsupportedOperationException.
- Parameters:
indices- is an array of indices with elements corresponding to those in the indexKeys array.indexKeys- is an array of index key values identifying the elements to be selected.joinConfig- is the join configuration, or null to use the default configuration.- Returns:
- an iterator over the elements in this collection that match all specified index key values.
- Throws:
IllegalArgumentException- if this collection is indexed or if a given index does not have the same store as this collection.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C Edition).
-
storedIterator()orstoredIterator(boolean)instead.