List.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Jun 2019 14:28:51 +0200
changeset 5050 44fa8672d102
parent 5009 eedec11e58f7
child 5137 5dd0d9a21576
permissions -rw-r--r--
#DOCUMENTATION by cg class: SharedQueue comment/format in: #next #nextWithTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4683
dfcc81b5bc10 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4632
diff changeset
     1
"{ Encoding: utf8 }"
dfcc81b5bc10 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4632
diff changeset
     2
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 1996 by eXept Software AG
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
    15
3836
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
    16
"{ NameSpace: Smalltalk }"
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
    17
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
OrderedCollection subclass:#List
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    19
	instanceVariableNames:'dependents optionalAccessLock'
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Collections-Sequenceable'
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!List class methodsFor:'documentation'!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
copyright
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 1996 by eXept Software AG
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
              All Rights Reserved
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
documentation
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
"
737
c76130b05afb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 673
diff changeset
    44
    Lists are mostly like OrderedCollections, but keep their dependents
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    locally (which is adding a bit of performance - not functionality).
737
c76130b05afb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 673
diff changeset
    46
    In addition, special change notifications are emitted, whenever
4815
ed3795b51878 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
    47
    a list's contents is changed.
737
c76130b05afb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 673
diff changeset
    48
    Some views (SelectionIn*View and DataSetView) react specially on
3968
590c6d311872 #DOCUMENTATION by mawalch
mawalch
parents: 3836
diff changeset
    49
    those messages and perform optimized updates.
737
c76130b05afb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 673
diff changeset
    50
    (the change messages pass the range-of-change as parameter).
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    In ST/X, most functionality is already provided by OrderedCollection,
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    so there is not much new stuff found here.
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    It has been mostly provided, for ST-80 compatibility,
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    where it adds sorting capabilities.
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    57
    New: 
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    58
        if the optional optionalAccessLock is set, all operations
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    59
        are protected by a critical region.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    60
        (i.e. the List is a SynchronizedCollection)
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    61
        
4147
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    62
    [caveat:]
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    63
        'List' is probably a bad name, which may confuse beginners.
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    64
        I have nothing in common with LinkedLists.
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    65
        Instances are just regular ordered collections, with the added benefit of
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    66
        sending out information about changes, and an optional synchronization lock.
4147
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    67
        Thus, they can be used as a model of textviews or selection list views,
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    68
        which need to redraw whenever the contents of the list changes.
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    69
        (and Lists not only send out change notifications when modified,
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    70
         but also include information about the range of changed elements.
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    71
         So the view can optimize its redraws)
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    72
        
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    [see also:]
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
        Array OrderedCollection
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    [author:]
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
        Claus Gittinger
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
! !
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
!List methodsFor:'accessing'!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
    83
at:anIndex put:anObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
    84
    "set the element at index, to be anIndex.
608
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    85
     Return anObject (sigh).
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    86
     In contrast to OrderedCollection, Lists allow putting an object
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    87
     right after the last element and auto-grow in this case;
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    88
     however, putting 2 or more indices after the last element is 
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    89
     reported as an error."
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    90
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    91
    |idx "{ Class: SmallInteger }"|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
    92
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    93
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    94
        idx := anIndex + firstIndex - 1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    95
        ((anIndex < 1) or:[idx > lastIndex]) ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    96
            idx == (lastIndex+1) ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    97
                self makeRoomAtLast.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    98
                lastIndex := lastIndex + 1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
    99
            ] ifFalse:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   100
                ^ self subscriptBoundsError:anIndex
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   101
            ]
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   102
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   103
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   104
        contentsArray basicAt:idx put:anObject.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   105
        dependents notNil ifTrue:[self changed:#at: with:anIndex].
608
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
   106
    ].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   107
    ^ anObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   108
4683
dfcc81b5bc10 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4632
diff changeset
   109
    "Modified: / 28-01-1998 / 16:44:49 / cg"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   110
    "Modified: / 01-08-2018 / 11:46:40 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   111
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   112
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   113
list
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   114
    ^ self
4707
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   115
!
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   116
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   117
synchronizationSemaphore
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   118
    "return a synchronization semaphore for myself"
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   119
    
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   120
    optionalAccessLock notNil ifTrue:[
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   121
        ^ optionalAccessLock
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   122
    ].
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   123
    ^ super synchronizationSemaphore.
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   124
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   125
    "Created: / 01-08-2018 / 13:22:45 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   126
! !
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   127
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   128
!List methodsFor:'adding & removing'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   129
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   130
add:anObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   131
    "add the argument, anObject to the end of the collection
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   132
     Return the argument, anObject."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   133
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   134
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   135
        super add:anObject.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   136
        dependents notNil ifTrue:[self changed:#insert: with:(self size)].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   137
    ].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   138
    ^ anObject
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   139
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   140
    "Modified: / 29-01-1998 / 10:52:32 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   141
    "Modified: / 01-08-2018 / 11:46:58 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   142
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   143
4816
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   144
add:anObject after:oldObject
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   145
    "insert the argument, newObject after oldObject.
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   146
     If oldObject is not in the receiver, report an error,
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   147
     otherwise return the argument, anObject."
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   148
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   149
    self possiblySynchronized:[
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   150
        super add:anObject after:oldObject.
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   151
    ].
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   152
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   153
    "Created: / 19-02-2019 / 23:48:35 / Claus Gittinger"
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   154
!
efece2a6d28b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4815
diff changeset
   155
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   156
add:anObject beforeIndex:index
1922
be14f1a04953 #add:beforeIndex: - make immune against redefinition of #add: using
Stefan Vogel <sv@exept.de>
parents: 1916
diff changeset
   157
    "add the argument, anObject to the end of the collection.
be14f1a04953 #add:beforeIndex: - make immune against redefinition of #add: using
Stefan Vogel <sv@exept.de>
parents: 1916
diff changeset
   158
     Return the receiver (sigh - ST-80 compatibility)."
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   159
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   160
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   161
        super add:anObject beforeIndex:index.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   162
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   163
            self changed:#insert: with:index
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   164
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   165
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   166
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   167
    "Modified (format): / 01-08-2018 / 11:47:24 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   168
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   169
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   170
addAll:aCollection beforeIndex:index
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   171
    "insert all elements of the argument
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   172
     Return the receiver."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   173
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   174
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   175
        super addAll:aCollection beforeIndex:index.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   176
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   177
            self changed: #insertCollection: with:(Array with:index with:(aCollection size))
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   178
        ]
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   179
    ]
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   180
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   181
    "Modified: / 01-08-2018 / 11:47:17 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   182
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   183
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   184
addAll:aCollection from:startIndex to:endIndex beforeIndex:index
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   185
    "insert elements start to stop from the argument
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   186
     Return the receiver."
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   187
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   188
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   189
        super addAll:aCollection from:startIndex to:endIndex beforeIndex:index.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   190
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   191
            self changed: #insertCollection: with:(Array with:index with:(endIndex - startIndex + 1))
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   192
        ]
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   193
    ]
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   194
4697
1ac02e269555 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4683
diff changeset
   195
    "Modified: / 29-01-1998 / 10:52:57 / cg"
1ac02e269555 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4683
diff changeset
   196
    "Modified: / 30-07-2018 / 11:16:31 / Stefan Vogel"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   197
    "Modified: / 01-08-2018 / 11:47:38 / Claus Gittinger"
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   198
!
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   199
1142
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   200
addAllLast:aCollection
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   201
    "add all elements of the argument, aCollection to the end of the collection.
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   202
     Return the argument, aCollection."
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   203
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   204
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   205
        self addAll:aCollection beforeIndex:self size + 1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   206
    ].    
1142
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   207
    ^ aCollection
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   208
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   209
    "Modified: / 01-08-2018 / 11:47:55 / Claus Gittinger"
1142
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   210
!
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   211
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   212
addFirst:anObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   213
    "add the argument, anObject to the beginning of the collection.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   214
     Return the argument, anObject."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   215
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   216
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   217
        super addFirst:anObject.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   218
        dependents notNil ifTrue:[self changed:#insert: with:1].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   219
    ].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   220
    ^ anObject
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   221
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   222
    "Modified: / 29-01-1998 / 10:53:09 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   223
    "Modified: / 01-08-2018 / 11:48:05 / Claus Gittinger"
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   224
!
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   225
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   226
clearContents
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   227
    "remove all elements from the collection but keep the contentsArray.
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   228
     Useful for huge lists, if the contents will be rebuild soon (using #add:) 
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   229
     to a size which is similar to the lists current size.
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   230
     Returns the receiver."
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   231
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   232
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   233
        |prevSize|
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   234
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   235
        prevSize := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   236
        super clearContents.
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   237
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   238
        dependents notNil ifTrue:[
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   239
            prevSize ~~ 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   240
                self changed:#removeFrom: with:(Array with:1 with:prevSize)
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   241
            ]
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   242
        ]
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   243
     ]
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   244
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   245
    "Modified (format): / 01-08-2018 / 11:51:29 / Claus Gittinger"
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   246
!
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   247
4934
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   248
dropLast:n
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   249
    "remove the last n elements from the receiver collection. 
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   250
     Return the receiver."
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   251
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   252
    self possiblySynchronized:[
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   253
        | stop |
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   254
        stop := self size.
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   255
        super dropLast:n.
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   256
        dependents notNil ifTrue:[
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   257
            self changed:#removeFrom: with:(Array with:(stop - n + 1) with:stop).
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   258
        ].
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   259
    ].
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   260
    ^ self
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   261
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   262
    "Created: / 03-04-2019 / 12:40:35 / Claus Gittinger"
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   263
!
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   264
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   265
removeAll
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   266
    "remove all elements from the collection.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   267
     Returns the receiver."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   268
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   269
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   270
        |prevSize|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   271
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   272
        prevSize := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   273
        super removeAll.
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   274
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   275
        dependents notNil ifTrue:[
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   276
            prevSize ~~ 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   277
               self changed:#removeFrom: with:(Array with:1 with:prevSize)
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   278
           ]
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   279
        ]
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   280
    ]
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   281
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   282
    "Modified: / 29-01-1998 / 10:53:28 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   283
    "Modified (format): / 01-08-2018 / 11:51:21 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   284
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   285
3301
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   286
removeAllSuchThat:aBlock
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   287
    "remove all elements that meet a test criteria as specified in aBlock.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   288
     The argument, aBlock is evaluated for successive elements and all those,
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   289
     for which it returns true, are removed.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   290
     Destructive: modifies the receiver.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   291
     Return a collection containing the removed elements."
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   292
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   293
    |removedElements|
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   294
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   295
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   296
        removedElements := super removeAllSuchThat:aBlock.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   297
        removedElements notEmpty ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   298
            self changed.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   299
        ].
3836
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
   300
    ].
3301
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   301
    ^ removedElements.
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   302
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   303
    "Modified: / 01-08-2018 / 11:49:44 / Claus Gittinger"
3301
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   304
!
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   305
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   306
removeFirst
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   307
    "remove the first element from the collection; return the element."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   308
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   309
    |deletedObject|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   310
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   311
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   312
        deletedObject := super removeFirst.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   313
        dependents notNil ifTrue:[self changed:#remove: with:1].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   314
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   315
    ^ deletedObject
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   316
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   317
    "Modified: / 29-01-1998 / 10:53:36 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   318
    "Modified: / 01-08-2018 / 11:49:58 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   319
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   320
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   321
removeFirst:n
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   322
    "remove the first n elements from the collection; 
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   323
     Return a collection containing the removed elements."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   324
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   325
    |deletedObjects|
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   326
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   327
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   328
        deletedObjects := super removeFirst:n.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   329
        dependents notNil ifTrue:[self changed:#removeFrom: with:(Array with:1 with:n)].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   330
    ].
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   331
    ^ deletedObjects
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   332
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   333
    "Modified: / 29-01-1998 / 10:53:40 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   334
    "Modified: / 01-08-2018 / 11:50:10 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   335
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   336
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   337
removeFirstIfAbsent:exceptionBlock
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   338
    "remove the first element from the collection; return the element.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   339
     If there is no element in the receiver collection, return the value from
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   340
     exceptionBlock."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   341
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   342
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   343
        self notEmpty ifTrue:[ ^ self removeFirst ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   344
    ].
1778
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   345
    ^ exceptionBlock value
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   346
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   347
    "Modified: / 21-10-2006 / 23:03:46 / cg"
4632
78bc0134bc30 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4147
diff changeset
   348
    "Modified: / 11-04-2018 / 11:52:30 / stefan"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   349
    "Modified: / 01-08-2018 / 11:50:26 / Claus Gittinger"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   350
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   351
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   352
removeFromIndex:startIndex toIndex:stopIndex
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   353
    "remove the elements stored under startIndex up to and including
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   354
     the elements under stopIndex.
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   355
     Return the receiver.
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   356
     Returning the receiver here is a historic leftover - it may change."
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   357
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   358
    |ret|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   359
2004
e9ee1c2930b0 dont send out change-notifications, if there was no change
ab
parents: 1922
diff changeset
   360
    stopIndex < startIndex ifTrue:[^ self].
e9ee1c2930b0 dont send out change-notifications, if there was no change
ab
parents: 1922
diff changeset
   361
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   362
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   363
        ret := super removeFromIndex:startIndex toIndex:stopIndex.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   364
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   365
            self changed:#removeFrom: with:(Array with:startIndex with:stopIndex).
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   366
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   367
    ].    
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   368
    ^ ret
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   369
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   370
    "Modified: / 29-01-1998 / 10:54:03 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   371
    "Modified: / 01-08-2018 / 11:50:42 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   372
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   373
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   374
removeIdentical:anObject ifAbsent:exceptionBlock
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   375
    "remove the first element which is identical to anObject;
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   376
     if found, remove and return it; 
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   377
     if not, return the value from evaluating exceptionBlock.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   378
     Uses identity compare (==) to search for the element."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   379
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   380
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   381
        |index|
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   382
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   383
        index := self identityIndexOf:anObject.
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   384
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   385
        index == 0 ifTrue:[ ^ exceptionBlock value ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   386
        self removeFromIndex:index toIndex:index.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   387
    ].    
1778
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   388
    ^ anObject
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   389
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   390
    "Modified: / 21-10-2006 / 23:03:29 / cg"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   391
    "Modified (format): / 01-08-2018 / 11:51:07 / Claus Gittinger"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   392
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   393
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   394
removeLast
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   395
    "remove the last element from the collection; return the element"
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   396
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   397
    |deletedObject|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   398
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   399
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   400
        deletedObject :=  super removeLast.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   401
        dependents notNil ifTrue:[self changed:#remove: with:(1 + self size)].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   402
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   403
    ^ deletedObject
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   404
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   405
    "Modified: / 29-01-1998 / 10:54:15 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   406
    "Modified: / 01-08-2018 / 11:51:51 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   407
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   408
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   409
removeLast:n
2054
c78f3c579b5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
   410
    "remove the last n elements from the receiver collection. 
c78f3c579b5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
   411
     Return a collection of removed elements."
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   412
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   413
    |deletedObjects|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   414
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   415
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   416
        | stop |
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   417
        stop := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   418
        deletedObjects := super removeLast:n.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   419
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   420
            self changed:#removeFrom: with:(Array with:(stop - n + 1) with:stop).
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   421
        ].
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   422
    ].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   423
    ^ deletedObjects
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   424
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   425
    "Modified: / 29-01-1998 / 10:54:25 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   426
    "Modified: / 01-08-2018 / 11:52:10 / Claus Gittinger"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   427
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   428
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   429
removeLastIfAbsent:exceptionBlock
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   430
    "remove the last element from the collection; return the element.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   431
     If there is no element in the receiver collection, return the value from
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   432
     exceptionBlock."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   433
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   434
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   435
        self notEmpty ifTrue:[ ^ self removeLast ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   436
    ].    
1778
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   437
    ^ exceptionBlock value
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   438
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   439
    "Modified: / 21-10-2006 / 23:03:53 / cg"
4697
1ac02e269555 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4683
diff changeset
   440
    "Modified: / 30-07-2018 / 11:12:56 / Stefan Vogel"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   441
    "Modified: / 01-08-2018 / 11:52:25 / Claus Gittinger"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   442
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   443
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   444
reset
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   445
    "logically remove all elements from the collection.
4089
43143bac2181 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3968
diff changeset
   446
     That's almost the same as #removeAll, but keeps the contentsArray.
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   447
     Returns the receiver."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   448
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   449
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   450
        |prevSize|
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   451
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   452
        prevSize := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   453
        super reset.
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   454
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   455
        dependents notNil ifTrue:[
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   456
            prevSize ~~ 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   457
               self changed:#removeFrom: with:(Array with:1 with:prevSize)
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   458
           ]
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   459
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   460
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   461
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   462
    "Modified: / 01-08-2018 / 11:52:46 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   463
! !
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   464
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   465
!List methodsFor:'converting'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   466
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   467
asList
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   468
    ^ self
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   469
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   470
    "Created: 14.2.1997 / 16:25:55 / cg"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   471
!
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   472
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   473
asSharedCollection
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   474
    optionalAccessLock notNil ifTrue:[
4793
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   475
        "I am alreay protected against concurrent access"
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   476
        ^ self
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   477
    ].
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   478
    
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   479
    ^ (List withAll:self)
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   480
            beSynchronized;
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   481
            yourself.
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   482
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   483
    "Created: / 01-08-2018 / 11:54:26 / Claus Gittinger"
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   484
    "Modified (format): / 01-08-2018 / 15:07:20 / Stefan Vogel"
4793
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   485
    "Modified (format): / 02-02-2019 / 19:26:04 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   486
! !
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   487
810
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   488
!List methodsFor:'copying'!
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   489
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   490
skipInstvarIndexInDeepCopy:index
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   491
    "a helper for deepCopy; only indices for which this method returns
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   492
     false are copied in a deep copy."
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   493
2858
aeacd9c755ae class: List
Stefan Vogel <sv@exept.de>
parents: 2054
diff changeset
   494
    ^ index == 4    "/ skip dependents
810
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   495
! !
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   496
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   497
!List methodsFor:'dependents access'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   498
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   499
addDependent:anObject
1615
a37350aa843e oops - back to previous
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   500
    "make the argument, anObject be a dependent of the receiver."
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   501
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   502
    ^ self addNonWeakDependent:anObject
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   503
!
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   504
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
dependents 
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
    "return the dependents of the receiver"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
584
319da69edba2 dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
   508
    ^ dependents ? #()
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
584
319da69edba2 dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
   510
    "Created: / 14.2.1997 / 16:05:49 / cg"
319da69edba2 dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
   511
    "Modified: / 27.10.1997 / 19:37:33 / cg"
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
dependents:aCollection
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
    "set the dependents of the receiver"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   517
    aCollection size == 0 ifTrue:[
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   518
        dependents := nil
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   519
    ] ifFalse:[
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   520
        dependents := aCollection.
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   521
    ].
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   523
    "Created: / 14.2.1997 / 16:05:58 / cg"
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   524
    "Modified: / 29.1.1998 / 10:54:52 / cg"
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   525
!
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   526
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   527
nonWeakDependents
612
cc2d6bd50cdc #nonWeakDependents always returns a collection.
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   528
    "return a Collection of dependents - empty if there is none.
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   529
     Since all dependencies are nonWeak in List, this is a dummy."
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   530
1604
7f5c64c4fd90 dependencies fix
Claus Gittinger <cg@exept.de>
parents: 1567
diff changeset
   531
    ^ dependents ? #()
673
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   532
!
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   533
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   534
nonWeakDependents:newDeps
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   535
    "return a Collection of dependents - empty if there is none.
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   536
     Since all dependencies are nonWeak in List, this is a dummy."
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   537
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   538
    ^ self dependents:newDeps
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   539
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   540
    "Created: / 19.4.1996 / 10:29:43 / cg"
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   541
    "Modified: / 30.1.1998 / 14:06:12 / cg"
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   542
!
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   543
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   544
removeDependent:anObject
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   545
    "make the argument, anObject be independent of the receiver.
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   546
     Since all dependencies are nonWeak in Model, this is simply
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   547
     forwarded to removeDependent:"
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   548
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   549
    ^ self removeNonWeakDependent:anObject
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
! !
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   552
!List methodsFor:'filling & replacing'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   553
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   554
contents:aCollection
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   555
    "replace all elements in the receiver by aCollection,
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   556
     Redefined - can be done faster"
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   557
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   558
    |oldSize newSize|
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   559
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   560
    aCollection isSequenceable ifFalse:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   561
       ^ super contents:aCollection
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   562
    ].
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   563
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   564
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   565
        oldSize := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   566
        newSize := aCollection size.
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   567
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   568
        newSize < oldSize ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   569
           self replaceFrom:1 to:newSize with:aCollection startingAt:1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   570
           self removeFromIndex:newSize+1 toIndex:oldSize.
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   571
        ] ifFalse:[
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   572
           newSize > oldSize ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   573
               oldSize == 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   574
                   self addAll:aCollection       
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   575
               ] ifFalse:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   576
                   self replaceFrom:1 to:oldSize with:aCollection startingAt:1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   577
                   self addAll:aCollection from:oldSize+1 to:newSize beforeIndex:oldSize+1        
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   578
               ]
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   579
           ] ifFalse:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   580
               "/ same size
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   581
               oldSize ~~ 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   582
                   self replaceFrom:1 to:newSize with:aCollection startingAt:1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   583
               ]
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   584
           ]
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   585
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   586
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   587
    
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   588
    "
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   589
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   590
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   591
      l contents:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   592
      l        
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   593
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   594
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   595
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   596
      l addAll:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   597
      l contents:#(10 20 30).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   598
      l       
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   599
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   600
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   601
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   602
      l addAll:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   603
      l contents:#(10 20 30 40 50 60 70 80).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   604
      l      
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   605
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   606
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   607
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   608
      l addAll:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   609
      l contents:#(10 20 30 40 50).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   610
      l      
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   611
    "
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   612
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   613
    "Modified: / 01-08-2018 / 11:55:20 / Claus Gittinger"
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   614
!
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   615
1033
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   616
list:aCollection
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   617
    "replace all elements in the receiver by aCollection.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   618
     For compatibility with other smalltalks 
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   619
     (allows List to be sometimes used as a ListPresenter in ported Dolphin apps)"
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   620
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   621
    self contents:aCollection
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   622
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   623
    "
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   624
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   625
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   626
     l list:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   627
     l        
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   628
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   629
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   630
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   631
     l addAll:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   632
     l list:#(10 20 30).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   633
     l       
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   634
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   635
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   636
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   637
     l addAll:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   638
     l list:#(10 20 30 40 50 60 70 80).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   639
     l      
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   640
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   641
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   642
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   643
     l addAll:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   644
     l list:#(10 20 30 40 50).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   645
     l      
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   646
    "
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   647
!
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   648
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   649
replaceFrom:start to:stop with:aCollection startingAt:repStart
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   650
    "replace elements in the receiver between index start and stop,
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   651
     with elements  taken from replacementCollection starting at repStart.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   652
     Redefined - can be done faster"
481
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   653
2999
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   654
    stop < start ifTrue:[^ self].
481
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   655
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   656
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   657
        "/ see if there is really any change involved
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   658
        (self sameContentsFrom:start to:stop as:aCollection startingAt:repStart) ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   659
            ^ self  "/ avoids useless change notifications
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   660
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   661
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   662
        super replaceFrom:start to:stop with:aCollection startingAt:repStart.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   663
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   664
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   665
            self changed:#replace: with:(Array with:start with:stop)
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   666
        ].
2999
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   667
    ].
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   668
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   669
    "Modified: / 20-05-1998 / 15:20:17 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   670
    "Modified: / 01-08-2018 / 11:55:41 / Claus Gittinger"
2911
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   671
!
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   672
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   673
setContents:aCollection
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   674
    "replace the receiver's underlying collection by aCollection"
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   675
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   676
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   677
        aCollection isSequenceable ifFalse:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   678
           ^ super contents:aCollection
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   679
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   680
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   681
        contentsArray := aCollection.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   682
        firstIndex := 1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   683
        lastIndex := aCollection size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   684
        self changed.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   685
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   686
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   687
    "Modified: / 01-08-2018 / 11:56:01 / Claus Gittinger"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   688
! !
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   689
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   690
!List methodsFor:'private'!
2911
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   691
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   692
possiblySynchronized:aBlock
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   693
    optionalAccessLock notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   694
        ^ optionalAccessLock synchronized:aBlock.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   695
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   696
    ^ aBlock value.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   697
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   698
    "Created: / 01-08-2018 / 11:46:01 / Claus Gittinger"
4793
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   699
!
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   700
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   701
synchronized:aBlock
5009
eedec11e58f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
   702
    "a shortcut, if the sync-sema is already present;
eedec11e58f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
   703
     return the value from aBlock"
4793
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   704
    
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   705
    optionalAccessLock notNil ifTrue:[
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   706
        ^ optionalAccessLock synchronized:aBlock.
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   707
    ].
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   708
    ^ super synchronized:aBlock.
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   709
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   710
    "Created: / 02-02-2019 / 19:23:27 / Claus Gittinger"
5009
eedec11e58f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
   711
    "Modified (comment): / 07-06-2019 / 13:51:10 / Claus Gittinger"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   712
! !
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   713
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   714
!List methodsFor:'setup'!
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   715
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   716
beSynchronized
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   717
    "make the receiver a synchronized List"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   718
    
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   719
    |wasBlocked|
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   720
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   721
    optionalAccessLock isNil ifTrue:[
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   722
        wasBlocked := OperatingSystem blockInterrupts.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   723
        optionalAccessLock isNil ifTrue:[
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   724
            "already a registered synchronizationSemaphore for myself in Object? 
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   725
             - then use it!!"
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   726
            optionalAccessLock := SynchronizationSemaphores removeKey:self ifAbsent:[].
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   727
            optionalAccessLock isNil ifTrue:[
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   728
                optionalAccessLock := RecursionLock name:self className.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   729
            ].
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   730
        ].
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   731
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   732
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   733
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   734
    "
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   735
        |list oldSema|
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   736
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   737
        list := List new.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   738
        list synchronized:[list add:1].
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   739
        oldSema := list synchronizationSemaphore.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   740
        list beSynchronized.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   741
        self assert:oldSema == list synchronizationSemaphore.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   742
        oldSema
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   743
    "
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   744
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   745
    "Created: / 01-08-2018 / 11:44:37 / Claus Gittinger"
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   746
    "Modified (comment): / 01-08-2018 / 15:10:45 / Stefan Vogel"
481
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   747
! !
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   748
881
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   749
!List methodsFor:'testing'!
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   750
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   751
isList
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   752
    "return true, if the receiver is some kind of list collection;
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   753
     true is returned here - the method is redefined from Object."
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   754
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   755
    ^ true
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   756
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   757
    "Modified: / 11.2.2000 / 01:37:36 / cg"
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   758
! !
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   759
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
!List class methodsFor:'documentation'!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
version
3836
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
   763
    ^ '$Header$'
4707
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   764
!
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   765
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   766
version_CVS
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   767
    ^ '$Header$'
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   768
! !
2911
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   769