List.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5237 3c1a727eb448
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
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
5237
3c1a727eb448 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5137
diff changeset
   171
    "insert all elements of the argument, anObject to become located at index.
3c1a727eb448 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5137
diff changeset
   172
     The collection may be unordered, but then the order of the sliced-in elements
3c1a727eb448 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5137
diff changeset
   173
     is undefined.
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   174
     Return the receiver."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   175
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   176
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   177
        super addAll:aCollection beforeIndex:index.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   178
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   179
            self changed: #insertCollection: with:(Array with:index with:(aCollection size))
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   180
        ]
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   181
    ]
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   182
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   183
    "Modified: / 01-08-2018 / 11:47:17 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   184
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   185
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   186
addAll:aCollection from:startIndex to:endIndex beforeIndex:index
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   187
    "insert elements start to stop from the argument
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   188
     Return the receiver."
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   189
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   190
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   191
        super addAll:aCollection from:startIndex to:endIndex beforeIndex:index.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   192
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   193
            self changed: #insertCollection: with:(Array with:index with:(endIndex - startIndex + 1))
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   194
        ]
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   195
    ]
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   196
4697
1ac02e269555 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4683
diff changeset
   197
    "Modified: / 29-01-1998 / 10:52:57 / cg"
1ac02e269555 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4683
diff changeset
   198
    "Modified: / 30-07-2018 / 11:16:31 / Stefan Vogel"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   199
    "Modified: / 01-08-2018 / 11:47:38 / Claus Gittinger"
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   200
!
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   201
1142
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   202
addAllLast:aCollection
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   203
    "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
   204
     Return the argument, aCollection."
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   205
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   206
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   207
        self addAll:aCollection beforeIndex:self size + 1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   208
    ].    
1142
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   209
    ^ aCollection
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   210
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   211
    "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
   212
!
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   213
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   214
addFirst:anObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   215
    "add the argument, anObject to the beginning of the collection.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   216
     Return the argument, anObject."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   217
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   218
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   219
        super addFirst:anObject.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   220
        dependents notNil ifTrue:[self changed:#insert: with:1].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   221
    ].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   222
    ^ anObject
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   223
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   224
    "Modified: / 29-01-1998 / 10:53:09 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   225
    "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
   226
!
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   227
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   228
clearContents
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   229
    "remove all elements from the collection but keep the contentsArray.
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   230
     Useful for huge lists, if the contents will be rebuild soon (using #add:) 
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   231
     to a size which is similar to the lists current size.
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   232
     Returns the receiver."
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   233
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   234
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   235
        |prevSize|
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   236
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   237
        prevSize := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   238
        super clearContents.
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   239
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   240
        dependents notNil ifTrue:[
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   241
            prevSize ~~ 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   242
                self changed:#removeFrom: with:(Array with:1 with:prevSize)
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   243
            ]
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   244
        ]
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   245
     ]
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   246
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   247
    "Modified (format): / 01-08-2018 / 11:51:29 / Claus Gittinger"
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   248
!
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   249
4934
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   250
dropLast:n
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   251
    "remove the last n elements from the receiver collection. 
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   252
     Return the receiver."
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   253
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   254
    self possiblySynchronized:[
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   255
        | stop |
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   256
        stop := self size.
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   257
        super dropLast:n.
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   258
        dependents notNil ifTrue:[
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   259
            self changed:#removeFrom: with:(Array with:(stop - n + 1) with:stop).
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   260
        ].
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
    ^ self
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
    "Created: / 03-04-2019 / 12:40:35 / Claus Gittinger"
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   265
!
91b2585d2cba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4816
diff changeset
   266
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   267
removeAll
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   268
    "remove all elements from the collection.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   269
     Returns the receiver."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   270
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   271
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   272
        |prevSize|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   273
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   274
        prevSize := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   275
        super removeAll.
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   276
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   277
        dependents notNil ifTrue:[
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   278
            prevSize ~~ 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   279
               self changed:#removeFrom: with:(Array with:1 with:prevSize)
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   280
           ]
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   281
        ]
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   282
    ]
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   283
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   284
    "Modified: / 29-01-1998 / 10:53:28 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   285
    "Modified (format): / 01-08-2018 / 11:51:21 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   286
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   287
3301
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   288
removeAllSuchThat:aBlock
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   289
    "remove all elements that meet a test criteria as specified in aBlock.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   290
     The argument, aBlock is evaluated for successive elements and all those,
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   291
     for which it returns true, are removed.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   292
     Destructive: modifies the receiver.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   293
     Return a collection containing the removed elements."
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   294
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   295
    |removedElements|
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   296
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   297
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   298
        removedElements := super removeAllSuchThat:aBlock.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   299
        removedElements notEmpty ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   300
            self changed.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   301
        ].
3836
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
   302
    ].
3301
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   303
    ^ removedElements.
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   304
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   305
    "Modified: / 01-08-2018 / 11:49:44 / Claus Gittinger"
3301
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   306
!
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   307
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   308
removeFirst
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   309
    "remove the first element from the collection; return the element."
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
    |deletedObject|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   312
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   313
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   314
        deletedObject := super removeFirst.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   315
        dependents notNil ifTrue:[self changed:#remove: with:1].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   316
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   317
    ^ deletedObject
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   318
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   319
    "Modified: / 29-01-1998 / 10:53:36 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   320
    "Modified: / 01-08-2018 / 11:49:58 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   321
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   322
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   323
removeFirst:n
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   324
    "remove the first n elements from the collection; 
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   325
     Return a collection containing the removed elements."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   326
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   327
    |deletedObjects|
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   328
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   329
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   330
        deletedObjects := super removeFirst:n.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   331
        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
   332
    ].
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   333
    ^ deletedObjects
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   334
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   335
    "Modified: / 29-01-1998 / 10:53:40 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   336
    "Modified: / 01-08-2018 / 11:50:10 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   337
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   338
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   339
removeFirstIfAbsent:exceptionBlock
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   340
    "remove the first element from the collection; return the element.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   341
     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
   342
     exceptionBlock."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   343
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   344
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   345
        self notEmpty ifTrue:[ ^ self removeFirst ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   346
    ].
1778
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   347
    ^ exceptionBlock value
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   348
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   349
    "Modified: / 21-10-2006 / 23:03:46 / cg"
4632
78bc0134bc30 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4147
diff changeset
   350
    "Modified: / 11-04-2018 / 11:52:30 / stefan"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   351
    "Modified: / 01-08-2018 / 11:50:26 / Claus Gittinger"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   352
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   353
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   354
removeFromIndex:startIndex toIndex:stopIndex
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   355
    "remove the elements stored under startIndex up to and including
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   356
     the elements under stopIndex.
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   357
     Return the receiver.
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   358
     Returning the receiver here is a historic leftover - it may change."
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   359
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   360
    |ret|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   361
2004
e9ee1c2930b0 dont send out change-notifications, if there was no change
ab
parents: 1922
diff changeset
   362
    stopIndex < startIndex ifTrue:[^ self].
e9ee1c2930b0 dont send out change-notifications, if there was no change
ab
parents: 1922
diff changeset
   363
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   364
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   365
        ret := super removeFromIndex:startIndex toIndex:stopIndex.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   366
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   367
            self changed:#removeFrom: with:(Array with:startIndex with:stopIndex).
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   368
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   369
    ].    
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   370
    ^ ret
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   371
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   372
    "Modified: / 29-01-1998 / 10:54:03 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   373
    "Modified: / 01-08-2018 / 11:50:42 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   374
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   375
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   376
removeIdentical:anObject ifAbsent:exceptionBlock
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   377
    "remove the first element which is identical to anObject;
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   378
     if found, remove and return it; 
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   379
     if not, return the value from evaluating exceptionBlock.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   380
     Uses identity compare (==) to search for the element."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   381
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   382
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   383
        |index|
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 := self identityIndexOf:anObject.
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   386
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   387
        index == 0 ifTrue:[ ^ exceptionBlock value ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   388
        self removeFromIndex:index toIndex:index.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   389
    ].    
1778
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   390
    ^ anObject
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   391
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   392
    "Modified: / 21-10-2006 / 23:03:29 / cg"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   393
    "Modified (format): / 01-08-2018 / 11:51:07 / Claus Gittinger"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   394
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   395
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   396
removeLast
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   397
    "remove the last element from the collection; return the element"
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
    |deletedObject|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   400
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   401
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   402
        deletedObject :=  super removeLast.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   403
        dependents notNil ifTrue:[self changed:#remove: with:(1 + self size)].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   404
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   405
    ^ deletedObject
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   406
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   407
    "Modified: / 29-01-1998 / 10:54:15 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   408
    "Modified: / 01-08-2018 / 11:51:51 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   409
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   410
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   411
removeLast:n
2054
c78f3c579b5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
   412
    "remove the last n elements from the receiver collection. 
c78f3c579b5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
   413
     Return a collection of removed elements."
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
    |deletedObjects|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   416
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   417
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   418
        | stop |
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   419
        stop := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   420
        deletedObjects := super removeLast:n.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   421
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   422
            self changed:#removeFrom: with:(Array with:(stop - n + 1) with:stop).
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   423
        ].
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   424
    ].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   425
    ^ deletedObjects
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   426
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   427
    "Modified: / 29-01-1998 / 10:54:25 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   428
    "Modified: / 01-08-2018 / 11:52:10 / Claus Gittinger"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   429
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   430
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   431
removeLastIfAbsent:exceptionBlock
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   432
    "remove the last element from the collection; return the element.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   433
     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
   434
     exceptionBlock."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   435
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   436
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   437
        self notEmpty ifTrue:[ ^ self removeLast ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   438
    ].    
1778
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   439
    ^ exceptionBlock value
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   440
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   441
    "Modified: / 21-10-2006 / 23:03:53 / cg"
4697
1ac02e269555 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4683
diff changeset
   442
    "Modified: / 30-07-2018 / 11:12:56 / Stefan Vogel"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   443
    "Modified: / 01-08-2018 / 11:52:25 / Claus Gittinger"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   444
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   445
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   446
reset
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   447
    "logically remove all elements from the collection.
4089
43143bac2181 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3968
diff changeset
   448
     That's almost the same as #removeAll, but keeps the contentsArray.
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   449
     Returns the receiver."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   450
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   451
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   452
        |prevSize|
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   453
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   454
        prevSize := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   455
        super reset.
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   456
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   457
        dependents notNil ifTrue:[
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   458
            prevSize ~~ 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   459
               self changed:#removeFrom: with:(Array with:1 with:prevSize)
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
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   463
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   464
    "Modified: / 01-08-2018 / 11:52:46 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   465
! !
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   466
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   467
!List methodsFor:'converting'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   468
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   469
asList
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   470
    ^ self
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   471
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   472
    "Created: 14.2.1997 / 16:25:55 / cg"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   473
!
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   474
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   475
asSharedCollection
5137
5dd0d9a21576 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5009
diff changeset
   476
    "return a shared collection on the receiver.
5dd0d9a21576 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5009
diff changeset
   477
     If the receiver is already synchronized, itself is returned. 
5dd0d9a21576 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5009
diff changeset
   478
     This implements synchronized (i.e. mutually excluded) access to me.
5dd0d9a21576 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5009
diff changeset
   479
     Use this for safe access when multiple processes access me concurrently."
5dd0d9a21576 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5009
diff changeset
   480
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   481
    optionalAccessLock notNil ifTrue:[
4793
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   482
        "I am alreay protected against concurrent access"
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   483
        ^ self
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   484
    ].
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   485
    
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   486
    ^ (List withAll:self)
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   487
            beSynchronized;
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   488
            yourself.
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   489
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   490
    "Created: / 01-08-2018 / 11:54:26 / Claus Gittinger"
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   491
    "Modified (format): / 01-08-2018 / 15:07:20 / Stefan Vogel"
4793
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   492
    "Modified (format): / 02-02-2019 / 19:26:04 / Claus Gittinger"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   493
! !
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   494
810
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   495
!List methodsFor:'copying'!
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   496
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   497
skipInstvarIndexInDeepCopy:index
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   498
    "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
   499
     false are copied in a deep copy."
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   500
2858
aeacd9c755ae class: List
Stefan Vogel <sv@exept.de>
parents: 2054
diff changeset
   501
    ^ index == 4    "/ skip dependents
810
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   502
! !
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   503
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   504
!List methodsFor:'dependents access'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   505
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   506
addDependent:anObject
1615
a37350aa843e oops - back to previous
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   507
    "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
   508
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   509
    ^ self addNonWeakDependent:anObject
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   510
!
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   511
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
dependents 
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
    "return the dependents of the receiver"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
584
319da69edba2 dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
   515
    ^ dependents ? #()
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
584
319da69edba2 dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
   517
    "Created: / 14.2.1997 / 16:05:49 / cg"
319da69edba2 dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
   518
    "Modified: / 27.10.1997 / 19:37:33 / cg"
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
dependents:aCollection
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
    "set the dependents of the receiver"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   524
    aCollection size == 0 ifTrue:[
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   525
        dependents := nil
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   526
    ] ifFalse:[
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   527
        dependents := aCollection.
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   528
    ].
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   530
    "Created: / 14.2.1997 / 16:05:58 / cg"
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   531
    "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
   532
!
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   533
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   534
nonWeakDependents
612
cc2d6bd50cdc #nonWeakDependents always returns a collection.
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   535
    "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
   536
     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
   537
1604
7f5c64c4fd90 dependencies fix
Claus Gittinger <cg@exept.de>
parents: 1567
diff changeset
   538
    ^ dependents ? #()
673
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   539
!
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   540
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   541
nonWeakDependents:newDeps
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   542
    "return a Collection of dependents - empty if there is none.
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   543
     Since all dependencies are nonWeak in List, this is a dummy."
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   544
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   545
    ^ self dependents:newDeps
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   546
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   547
    "Created: / 19.4.1996 / 10:29:43 / cg"
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   548
    "Modified: / 30.1.1998 / 14:06:12 / cg"
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   549
!
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   550
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   551
removeDependent:anObject
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   552
    "make the argument, anObject be independent of the receiver.
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   553
     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
   554
     forwarded to removeDependent:"
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   555
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   556
    ^ self removeNonWeakDependent:anObject
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
! !
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   559
!List methodsFor:'filling & replacing'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   560
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   561
contents:aCollection
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   562
    "replace all elements in the receiver by aCollection,
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   563
     Redefined - can be done faster"
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   564
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   565
    |oldSize newSize|
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   566
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   567
    aCollection isSequenceable ifFalse:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   568
       ^ super contents:aCollection
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   569
    ].
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   570
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   571
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   572
        oldSize := self size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   573
        newSize := aCollection size.
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   574
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   575
        newSize < oldSize ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   576
           self replaceFrom:1 to:newSize with:aCollection startingAt:1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   577
           self removeFromIndex:newSize+1 toIndex:oldSize.
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   578
        ] ifFalse:[
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   579
           newSize > oldSize ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   580
               oldSize == 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   581
                   self addAll:aCollection       
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   582
               ] ifFalse:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   583
                   self replaceFrom:1 to:oldSize with:aCollection startingAt:1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   584
                   self addAll:aCollection from:oldSize+1 to:newSize beforeIndex:oldSize+1        
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
           ] ifFalse:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   587
               "/ same size
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   588
               oldSize ~~ 0 ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   589
                   self replaceFrom:1 to:newSize with:aCollection startingAt:1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   590
               ]
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   591
           ]
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   592
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   593
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   594
    
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   595
    "
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   596
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   597
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   598
      l contents:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   599
      l        
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   600
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   601
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   602
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   603
      l addAll:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   604
      l contents:#(10 20 30).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   605
      l       
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   606
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   607
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   608
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   609
      l addAll:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   610
      l contents:#(10 20 30 40 50 60 70 80).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   611
      l      
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   612
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   613
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   614
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   615
      l addAll:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   616
      l contents:#(10 20 30 40 50).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   617
      l      
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   618
    "
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   619
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   620
    "Modified: / 01-08-2018 / 11:55:20 / Claus Gittinger"
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   621
!
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   622
1033
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   623
list:aCollection
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   624
    "replace all elements in the receiver by aCollection.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   625
     For compatibility with other smalltalks 
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   626
     (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
   627
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   628
    self contents:aCollection
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   629
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   630
    "
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   631
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   632
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   633
     l list:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   634
     l        
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   635
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   636
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   637
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   638
     l addAll:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   639
     l list:#(10 20 30).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   640
     l       
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   641
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   642
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   643
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   644
     l addAll:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   645
     l list:#(10 20 30 40 50 60 70 80).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   646
     l      
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
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   649
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   650
     l addAll:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   651
     l list:#(10 20 30 40 50).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   652
     l      
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   653
    "
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   654
!
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   655
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   656
replaceFrom:start to:stop with:aCollection startingAt:repStart
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   657
    "replace elements in the receiver between index start and stop,
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   658
     with elements  taken from replacementCollection starting at repStart.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   659
     Redefined - can be done faster"
481
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   660
2999
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   661
    stop < start ifTrue:[^ self].
481
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   662
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   663
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   664
        "/ see if there is really any change involved
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   665
        (self sameContentsFrom:start to:stop as:aCollection startingAt:repStart) ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   666
            ^ self  "/ avoids useless change notifications
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   667
        ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   668
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   669
        super replaceFrom:start to:stop with:aCollection startingAt:repStart.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   670
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   671
        dependents notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   672
            self changed:#replace: with:(Array with:start with:stop)
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   673
        ].
2999
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   674
    ].
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   675
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   676
    "Modified: / 20-05-1998 / 15:20:17 / cg"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   677
    "Modified: / 01-08-2018 / 11:55:41 / Claus Gittinger"
2911
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   678
!
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   679
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   680
setContents:aCollection
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   681
    "replace the receiver's underlying collection by aCollection"
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   682
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   683
    self possiblySynchronized:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   684
        aCollection isSequenceable ifFalse:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   685
           ^ super contents:aCollection
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
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   688
        contentsArray := aCollection.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   689
        firstIndex := 1.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   690
        lastIndex := aCollection size.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   691
        self changed.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   692
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   693
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   694
    "Modified: / 01-08-2018 / 11:56:01 / Claus Gittinger"
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
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   697
!List methodsFor:'private'!
2911
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   698
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   699
possiblySynchronized:aBlock
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   700
    optionalAccessLock notNil ifTrue:[
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   701
        ^ optionalAccessLock synchronized:aBlock.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   702
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   703
    ^ aBlock value.
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   704
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   705
    "Created: / 01-08-2018 / 11:46:01 / Claus Gittinger"
4793
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   706
!
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
synchronized:aBlock
5009
eedec11e58f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
   709
    "a shortcut, if the sync-sema is already present;
eedec11e58f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
   710
     return the value from aBlock"
4793
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   711
    
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   712
    optionalAccessLock notNil ifTrue:[
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   713
        ^ optionalAccessLock synchronized:aBlock.
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   714
    ].
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   715
    ^ super synchronized:aBlock.
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   716
435cf45a47eb #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4708
diff changeset
   717
    "Created: / 02-02-2019 / 19:23:27 / Claus Gittinger"
5009
eedec11e58f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
   718
    "Modified (comment): / 07-06-2019 / 13:51:10 / Claus Gittinger"
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   719
! !
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   720
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   721
!List methodsFor:'setup'!
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   722
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   723
beSynchronized
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   724
    "make the receiver a synchronized List"
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   725
    
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   726
    |wasBlocked|
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   727
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   728
    optionalAccessLock isNil ifTrue:[
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   729
        wasBlocked := OperatingSystem blockInterrupts.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   730
        optionalAccessLock isNil ifTrue:[
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   731
            "already a registered synchronizationSemaphore for myself in Object? 
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   732
             - then use it!!"
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   733
            optionalAccessLock := SynchronizationSemaphores removeKey:self ifAbsent:[].
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   734
            optionalAccessLock isNil ifTrue:[
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   735
                optionalAccessLock := RecursionLock name:self className.
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
        ].
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   738
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   739
    ].
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   740
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   741
    "
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   742
        |list 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
        list := List new.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   745
        list synchronized:[list add:1].
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   746
        oldSema := list synchronizationSemaphore.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   747
        list beSynchronized.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   748
        self assert:oldSema == list synchronizationSemaphore.
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   749
        oldSema
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   750
    "
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   751
4706
19cb0f0edf69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4697
diff changeset
   752
    "Created: / 01-08-2018 / 11:44:37 / Claus Gittinger"
4708
713e81a051ec #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4707
diff changeset
   753
    "Modified (comment): / 01-08-2018 / 15:10:45 / Stefan Vogel"
481
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   754
! !
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   755
881
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   756
!List methodsFor:'testing'!
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   757
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   758
isList
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   759
    "return true, if the receiver is some kind of list collection;
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   760
     true is returned here - the method is redefined from Object."
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   761
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   762
    ^ true
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   763
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   764
    "Modified: / 11.2.2000 / 01:37:36 / cg"
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   765
! !
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   766
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   767
!List class methodsFor:'documentation'!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   768
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
version
3836
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
   770
    ^ '$Header$'
4707
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   771
!
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   772
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   773
version_CVS
e0b53a001864 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4706
diff changeset
   774
    ^ '$Header$'
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
! !
2911
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   776