|
Class: SharedCollection
Object
|
+--Collection
|
+--SharedCollection
- Package:
- stx:libbasic2
- Category:
- Collections-Support
- Version:
- rev:
1.25
date: 2019/05/06 16:51:41
- user: cg
- file: SharedCollection.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
Instances of this class provide synchronized access (of multiple processes)
to a collection.
Notice:
the message-forwarding is done by catching subclassResponsibility and
doesNotUnderstand errors.
For performance, and for more complex operation-atomicy, more messages might need
an explicit handling.
See the implementation of #at: / #at:put: and #size for examples.
[auhor:]
Claus Gittinger
Semaphore
RecursionLock
SharedQueue
[synchronized]
method
in
Object.
instance creation
-
for: aCollection
-
create and return a new shareCollection which protects
access to aCollection.
I.e. to return a threadSave accessor on it.
accessing
-
accessLock
-
for protocol compatibility with SharedQueue
-
synchronizationSemaphore
-
converting
-
asSharedCollection
-
copying
-
shallowCopy
-
analog to species - copy the real collection
initialization
-
initializeFor: aCollection
-
message forwarding
-
add: anElement
-
add the argument, anObject to the receiver.
Return the added element.
-
at: index
-
(comment from inherited method)
return the indexed instance variable with index, anInteger;
this method can be redefined in subclasses.
-
at: index put: value
-
(comment from inherited method)
store the 2nd arg, anObject as indexed instvar with index, anInteger.
this method can be redefined in subclasses. Returns anObject (sigh)
-
do: aBlock
-
(comment from inherited method)
evaluate the argument, aBlock for each element
-
doesNotUnderstand: aMessage
-
catches everything not understood by the collection protocol
-
isEmpty
-
(comment from inherited method)
return true, if the receiver is empty
-
last
-
(comment from inherited method)
return the last element of the collection.
This is a slow fallback implementation,
and should be redefined in subclasses which can do indexed accesses.
-
notEmpty
-
(comment from inherited method)
return true, if the receiver is not empty
-
remove: someElement ifAbsent: aBlock
-
(comment from inherited method)
search for the first element, which is equal to anObject;
if found, remove and return it.
If not found, return the value of the exceptionBlock.
Uses equality compare (=) to search for the occurrence.
An error is raised here - it is to be implemented by a concrete subclass.
-
removeAllSuchThat: aBlock
-
(comment from inherited method)
Apply the condition to each element and remove it if the condition is true.
Return a collection of removed elements.
First elements-to-remove are collected, then removed in one operation.
-
removeIdentical: someElement ifAbsent: aBlock
-
(comment from inherited method)
search for the first element, which is identical to anObject;
if found, remove and return it.
If not found, return the value of the exceptionBlock.
Uses identity compare (==) to search for the occurrence.
An error is raised here - it is to be implemented by a concrete subclass.
-
size
-
(comment from inherited method)
return the number of elements in the receiver.
This is usually redefined in subclasses for more performance.
-
subclassResponsibility
-
catches every required message of the collection protocol
queries
-
species
-
returns non shared collection's species
testing
-
isFixedSize
-
return true if the receiver cannot grow
|c|
c := SharedCollection for:(OrderedCollection new).
c add:1.
c add:2.
c add:3.
c addAll:#(4 5 6).
c removeFirst.
c removeLast.
c inspect.
|
|c|
c := SharedCollection for:(Array new:10).
c at:1 put:5.
c replaceFrom:2 to:5 with:#(20 30 40 50).
c inspect.
|
|