|
Class: List
Object
|
+--Collection
|
+--SequenceableCollection
|
+--OrderedCollection
|
+--List
|
+--AbstractFileBrowser::DirectoryHistory
|
+--HierarchicalList
|
+--Tools::TagList
- Package:
- stx:libbasic2
- Category:
- Collections-Sequenceable
- Version:
- rev:
1.53
date: 2019/06/07 11:52:30
- user: cg
- file: List.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Claus Gittinger
Lists are mostly like OrderedCollections, but keep their dependents
locally (which is adding a bit of performance - not functionality).
In addition, special change notifications are emitted, whenever
a list's contents is changed.
Some views (SelectionIn*View and DataSetView) react specially on
those messages and perform optimized updates.
(the change messages pass the range-of-change as parameter).
In ST/X, most functionality is already provided by OrderedCollection,
so there is not much new stuff found here.
It has been mostly provided, for ST-80 compatibility,
where it adds sorting capabilities.
New:
if the optional optionalAccessLock is set, all operations
are protected by a critical region.
(i.e. the List is a SynchronizedCollection)
[caveat:]
'List' is probably a bad name, which may confuse beginners.
I have nothing in common with LinkedLists.
Instances are just regular ordered collections, with the added benefit of
sending out information about changes, and an optional synchronization lock.
Thus, they can be used as a model of textviews or selection list views,
which need to redraw whenever the contents of the list changes.
(and Lists not only send out change notifications when modified,
but also include information about the range of changed elements.
So the view can optimize its redraws)
Array
OrderedCollection
accessing
-
at: anIndex put: anObject
-
set the element at index, to be anIndex.
Return anObject (sigh).
In contrast to OrderedCollection, Lists allow putting an object
right after the last element and auto-grow in this case;
however, putting 2 or more indices after the last element is
reported as an error.
-
list
-
-
synchronizationSemaphore
-
return a synchronization semaphore for myself
adding & removing
-
add: anObject
-
add the argument, anObject to the end of the collection
Return the argument, anObject.
-
add: anObject after: oldObject
-
insert the argument, newObject after oldObject.
If oldObject is not in the receiver, report an error,
otherwise return the argument, anObject.
-
add: anObject beforeIndex: index
-
add the argument, anObject to the end of the collection.
Return the receiver (sigh - ST-80 compatibility).
-
addAll: aCollection beforeIndex: index
-
insert all elements of the argument
Return the receiver.
-
addAll: aCollection from: startIndex to: endIndex beforeIndex: index
-
insert elements start to stop from the argument
Return the receiver.
-
addAllLast: aCollection
-
add all elements of the argument, aCollection to the end of the collection.
Return the argument, aCollection.
-
addFirst: anObject
-
add the argument, anObject to the beginning of the collection.
Return the argument, anObject.
-
clearContents
-
remove all elements from the collection but keep the contentsArray.
Useful for huge lists, if the contents will be rebuild soon (using #add:)
to a size which is similar to the lists current size.
Returns the receiver.
-
dropLast: n
-
remove the last n elements from the receiver collection.
Return the receiver.
-
removeAll
-
remove all elements from the collection.
Returns the receiver.
-
removeAllSuchThat: aBlock
-
remove all elements that meet a test criteria as specified in aBlock.
The argument, aBlock is evaluated for successive elements and all those,
for which it returns true, are removed.
Destructive: modifies the receiver.
Return a collection containing the removed elements.
-
removeFirst
-
remove the first element from the collection; return the element.
-
removeFirst: n
-
remove the first n elements from the collection;
Return a collection containing the removed elements.
-
removeFirstIfAbsent: exceptionBlock
-
remove the first element from the collection; return the element.
If there is no element in the receiver collection, return the value from
exceptionBlock.
-
removeFromIndex: startIndex toIndex: stopIndex
-
remove the elements stored under startIndex up to and including
the elements under stopIndex.
Return the receiver.
Returning the receiver here is a historic leftover - it may change.
-
removeIdentical: anObject ifAbsent: exceptionBlock
-
remove the first element which is identical to anObject;
if found, remove and return it;
if not, return the value from evaluating exceptionBlock.
Uses identity compare (==) to search for the element.
-
removeLast
-
remove the last element from the collection; return the element
-
removeLast: n
-
remove the last n elements from the receiver collection.
Return a collection of removed elements.
-
removeLastIfAbsent: exceptionBlock
-
remove the last element from the collection; return the element.
If there is no element in the receiver collection, return the value from
exceptionBlock.
-
reset
-
logically remove all elements from the collection.
That's almost the same as #removeAll, but keeps the contentsArray.
Returns the receiver.
converting
-
asList
-
(comment from inherited method)
return a new List with the receiver collection's elements
-
asSharedCollection
-
I am alreay protected against concurrent access
copying
-
skipInstvarIndexInDeepCopy: index
-
a helper for deepCopy; only indices for which this method returns
false are copied in a deep copy.
dependents access
-
addDependent: anObject
-
make the argument, anObject be a dependent of the receiver.
-
dependents
-
return the dependents of the receiver
-
dependents: aCollection
-
set the dependents of the receiver
-
nonWeakDependents
-
return a Collection of dependents - empty if there is none.
Since all dependencies are nonWeak in List, this is a dummy.
-
nonWeakDependents: newDeps
-
return a Collection of dependents - empty if there is none.
Since all dependencies are nonWeak in List, this is a dummy.
-
removeDependent: anObject
-
make the argument, anObject be independent of the receiver.
Since all dependencies are nonWeak in Model, this is simply
forwarded to removeDependent:
filling & replacing
-
contents: aCollection
-
replace all elements in the receiver by aCollection,
Redefined - can be done faster
-
list: aCollection
-
replace all elements in the receiver by aCollection.
For compatibility with other smalltalks
(allows List to be sometimes used as a ListPresenter in ported Dolphin apps)
-
replaceFrom: start to: stop with: aCollection startingAt: repStart
-
replace elements in the receiver between index start and stop,
with elements taken from replacementCollection starting at repStart.
Redefined - can be done faster
-
setContents: aCollection
-
replace the receiver's underlying collection by aCollection
private
-
possiblySynchronized: aBlock
-
-
synchronized: aBlock
-
a shortcut, if the sync-sema is already present;
return the value from aBlock
setup
-
beSynchronized
-
make the receiver a synchronized List
testing
-
isList
-
return true, if the receiver is some kind of list collection;
true is returned here - the method is redefined from Object.
|