SharedCollection.st
author Claus Gittinger <cg@exept.de>
Sat, 18 Feb 2017 10:49:20 +0100
changeset 4336 f330feaa0125
parent 4291 a67c299b4c60
child 4355 9d6595f00a6e
permissions -rw-r--r--
#DOCUMENTATION by cg class: SharedCollection comment/format in: #for:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2006 by eXept Software AG
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
    14
"{ NameSpace: Smalltalk }"
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
    15
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Collection subclass:#SharedCollection
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'accessLock realCollection'
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
    20
	category:'Collections-Support'
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!SharedCollection class methodsFor:'documentation'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2006 by eXept Software AG
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    Instances of this class provide synchronized access (of multiple processes) 
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    to a collection.
1636
a3e5703901c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
    43
4148
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    44
    Notice: 
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    45
        the message-forwarding is done by catching subclassResponsibility and
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    46
        doesNotUnderstand errors.
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    47
1636
a3e5703901c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
    48
    For performance, and for more complex operation-atomicy, more messages might need
4148
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    49
    an explicit handling. 
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    50
    See the implementation of #at: / #at:put: and #size for examples.
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    51
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    52
    [auhor:]
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    53
        Claus Gittinger
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    54
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    55
    [see also:]
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    56
        Semaphore RecursionLock
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    57
        SharedQueue
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    58
        #synchronized: method in Object.
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
examples
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
                                        [exBegin]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
        |c|
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
        c := SharedCollection for:(OrderedCollection new).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
        c add:1.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
        c add:2.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
        c add:3.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
        c addAll:#(4 5 6).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
        c removeFirst.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
        c removeLast.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
        c inspect.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
                                        [exEnd]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
                                        [exBegin]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
        |c|
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
        c := SharedCollection for:(Array new:10).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
        c at:1 put:5.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
        c replaceFrom:2 to:5 with:#(20 30 40 50).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
        c inspect.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
                                        [exEnd]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
!SharedCollection class methodsFor:'instance creation'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
for:aCollection
4336
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    91
    "create and return a new shareCollection which protects
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    92
     access to aCollection.
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    93
     I.e. to return a threadSave accessor on it."
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    94
     
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    ^ self new initializeFor:aCollection
4336
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    96
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    97
    "Modified (comment): / 18-02-2017 / 10:49:03 / cg"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
1634
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   100
!SharedCollection methodsFor:'converting'!
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   101
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   102
asSharedCollection
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   103
    ^ self.
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   104
! !
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   105
3212
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   106
!SharedCollection methodsFor:'copying'!
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   107
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   108
shallowCopy
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   109
    "analog to species - copy the real collection"
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   110
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   111
    ^ accessLock critical:[
3213
53857e1b18a4 class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3212
diff changeset
   112
        "get a consistent copy"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   113
        realCollection shallowCopy
3213
53857e1b18a4 class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3212
diff changeset
   114
    ].
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   115
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   116
    "Modified: / 02-02-2017 / 17:03:55 / stefan"
3212
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   117
! !
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   118
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
!SharedCollection methodsFor:'initialization'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
initializeFor:aCollection
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
    accessLock := RecursionLock new.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    realCollection := aCollection.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
!SharedCollection methodsFor:'message forwarding'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
1929
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   128
add:anElement
2927
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   129
    "add the argument, anObject to the receiver.
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   130
     Return the added element."
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   131
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   132
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   133
        realCollection add:anElement
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   134
    ].
1929
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   135
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   136
    "Modified: / 02-02-2017 / 17:01:08 / stefan"
1929
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   137
!
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   138
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
at:index
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   140
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   141
        realCollection at:index
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   142
    ].
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   144
    "Modified: / 02-02-2017 / 17:01:23 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
at:index put:value
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   148
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   149
        realCollection at:index put:value
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   150
    ].
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   152
    "Modified: / 02-02-2017 / 17:01:35 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   155
do:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   156
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   157
        realCollection do:aBlock
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   158
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   159
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   160
    "Created: / 22-11-2010 / 21:01:21 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   161
    "Modified: / 02-02-2017 / 17:02:00 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   162
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   163
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
doesNotUnderstand:aMessage
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    "catches everything not understood by the collection protocol"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   167
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   168
        aMessage sendTo:realCollection
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    ].
1794
603885d999ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1637
diff changeset
   170
603885d999ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1637
diff changeset
   171
    "Modified: / 07-12-2006 / 17:38:30 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   172
    "Modified: / 02-02-2017 / 17:02:18 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   175
isEmpty
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   176
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   177
        realCollection isEmpty
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   178
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   179
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   180
    "Created: / 22-11-2010 / 20:59:01 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   181
    "Modified: / 02-02-2017 / 11:40:56 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   182
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   183
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   184
notEmpty
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   185
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   186
        realCollection notEmpty
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   187
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   188
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   189
    "Created: / 22-11-2010 / 20:59:06 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   190
    "Modified: / 02-02-2017 / 17:00:36 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   191
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   192
4286
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   193
remove:someElement ifAbsent:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   194
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   195
        realCollection remove:someElement ifAbsent:aBlock
4286
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   196
    ].
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   197
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   198
    "Created: / 25-01-2017 / 22:57:32 / stefan"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   199
    "Modified: / 02-02-2017 / 17:00:54 / stefan"
4286
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   200
!
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   201
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   202
removeAllSuchThat:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   203
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   204
        realCollection removeAllSuchThat:aBlock
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   205
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   206
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   207
    "Created: / 22-11-2010 / 20:59:27 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   208
    "Modified: / 02-02-2017 / 17:02:38 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   209
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   210
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   211
removeIdentical:someElement ifAbsent:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   212
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   213
       realCollection removeIdentical:someElement ifAbsent:aBlock
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   214
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   215
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   216
    "Created: / 22-11-2010 / 21:00:33 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   217
    "Modified: / 02-02-2017 / 17:02:52 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   218
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   219
1635
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   220
size
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   221
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   222
        realCollection size
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   223
    ].
1635
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   224
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   225
    "Modified: / 02-02-2017 / 17:03:06 / stefan"
1635
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   226
!
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   227
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
subclassResponsibility
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
    "catches every required message of the collection protocol"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   231
    |msg|
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    msg := thisContext sender message.
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   234
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   235
        msg sendTo:realCollection
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    ].
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   237
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   238
    "Modified: / 02-02-2017 / 17:03:25 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
3212
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   241
!SharedCollection methodsFor:'queries'!
1637
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   242
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   243
species
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
   244
    "returns non shared collection's species"
1637
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   245
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   246
    ^ realCollection species
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   247
! !
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   248
3013
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   249
!SharedCollection methodsFor:'testing'!
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   250
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   251
isFixedSize
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   252
    "return true if the receiver cannot grow"
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   253
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   254
    ^ realCollection isFixedSize
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   255
! !
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   256
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
!SharedCollection class methodsFor:'documentation'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
version
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
   260
    ^ '$Header$'
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   261
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   262
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   263
version_CVS
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
   264
    ^ '$Header$'
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
! !
2927
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   266