Skip to content

Commit

Permalink
Merge pull request #73 from moosetechnology/72-Make-FMSlotMultivalueL…
Browse files Browse the repository at this point in the history
…ink-inherit-OrderedCollection

Close #72: FMSlotMultivalueLink inherits from OrderedCollection
  • Loading branch information
Gabriel-Darbord authored Jan 29, 2024
2 parents ad77571 + 267f228 commit 8f04d63
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 142 deletions.
2 changes: 1 addition & 1 deletion src/Fame-Core/FMRelationSlot.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ FMRelationSlot >> removeAssociationFrom: ownerObject to: otherObject [

realInverseSlot isToOne
ifTrue: [ realInverseSlot writeInverse: nil to: otherObject ]
ifFalse: [ (realInverseSlot read: otherObject) inverseRemove: ownerObject ]
ifFalse: [ (realInverseSlot read: otherObject) unsafeRemove: ownerObject ]
]

{ #category : #accessing }
Expand Down
170 changes: 29 additions & 141 deletions src/Fame-Core/FMSlotMultivalueLink.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ I'll be wrapped by the slot and manage the content of the many slot.
"
Class {
#name : #FMSlotMultivalueLink,
#superclass : #Collection,
#superclass : #OrderedCollection,
#instVars : [
'values',
'owner',
'slot'
],
Expand All @@ -24,193 +23,82 @@ FMSlotMultivalueLink class >> on: anObject slot: aFMRelationSlot [

]

{ #category : #copying }
FMSlotMultivalueLink >> , aCollection [
^ self asOrderedCollection , aCollection
]

{ #category : #comparing }
FMSlotMultivalueLink >> = otherCollection [
"Answer true if the receiver is equivalent to the otherCollection.
First test for identity, then rule out different species and sizes of
collections. As a last resort, examine each element of the receiver
and the otherCollection."

self == otherCollection ifTrue: [^ true].
self species == otherCollection species ifFalse: [^ false].
^ values hasEqualElements: otherCollection asOrderedCollection
]

{ #category : #accessing }
FMSlotMultivalueLink >> add: anElement [
{ #category : #adding }
FMSlotMultivalueLink >> addLast: anElement [

slot add: anElement to: owner.
self unsafeAdd: anElement.
^ anElement
]

{ #category : #accessing }
FMSlotMultivalueLink >> at: index [

^values at: index
]

{ #category : #iterators }
FMSlotMultivalueLink >> basicIterator [
^ values basicIterator
]

{ #category : #accessing }
FMSlotMultivalueLink >> byName: name [

^ self byName: name ifAbsent: [ self errorNotFound: name ]
]

{ #category : #accessing }
FMSlotMultivalueLink >> byName: name ifAbsent: exceptionBlock [
^ values
detect: [ :each | each name asString = name asString ]
ifNone: exceptionBlock

^ self
detect: [ :each | each name asString = name asString ]
ifNone: exceptionBlock
]

{ #category : #accessing }
FMSlotMultivalueLink >> byName: name ifPresent: aBlock ifAbsent: exceptionBlock [
^ values
detect: [ :each | each name asString = name asString ]
ifFound: aBlock
ifNone: exceptionBlock
]

{ #category : #enumerating }
FMSlotMultivalueLink >> do: aBlock [

values do: aBlock
]

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> eighth [
^ self at: 8
]

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> fifth [
^ self at: 5
]

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> first [
^ self at: 1
]

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> fourth [
^ self at: 4
]

{ #category : #comparing }
FMSlotMultivalueLink >> hash [
"From sequenceable collection"
| hash |
hash := self species hash.
1 to: self size do: [ :i | hash := (hash + (self at: i) hash) hashMultiply ].
^ hash
]

{ #category : #private }
FMSlotMultivalueLink >> inverseRemove: anObject [

^values remove: anObject
]

{ #category : #iterators }
FMSlotMultivalueLink >> iterator [
^ values iterator
]

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> last [
^ values last
]

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> ninth [
^ self at: 9
^ self
detect: [ :each | each name asString = name asString ]
ifFound: aBlock
ifNone: exceptionBlock
]

{ #category : #private }
FMSlotMultivalueLink >> owner: anObject slot: aFMRelationSlot [

owner := anObject.
slot := aFMRelationSlot.
values := OrderedCollection new.

]

{ #category : #copying }
FMSlotMultivalueLink >> postCopy [

super postCopy.
values := values copy.
slot := aFMRelationSlot
]

{ #category : #removing }
FMSlotMultivalueLink >> remove: anElement ifAbsent: exceptionBlock [

values remove: anElement ifAbsent: [ ^exceptionBlock value ].
slot remove: anElement from: owner.
^anElement
]
FMSlotMultivalueLink >> remove: anElement ifAbsent: exceptionBlock [

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> second [
^ self at: 2
]

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> seventh [
^ self at: 7
]

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> sixth [
^ self at: 6
super remove: anElement ifAbsent: [ ^ exceptionBlock value ].
slot remove: anElement from: owner.
^ anElement
]

{ #category : #accessing }
FMSlotMultivalueLink >> size [
{ #category : #removing }
FMSlotMultivalueLink >> removeAll [
"The collection is reversed to make a copy, to avoid trying to remove while iterating,
and to remove items from last to first, which is faster."

^values size
self reversed do: [ :anElement | self remove: anElement ]
]

{ #category : #private }
FMSlotMultivalueLink >> species [

^OrderedCollection
]

{ #category : #'accessing-computed' }
FMSlotMultivalueLink >> third [
^ self at: 3
^ OrderedCollection
]

{ #category : #private }
FMSlotMultivalueLink >> unsafeAdd: element [
(values includes: element) ifFalse: [ values add: element ]

(self includes: element) ifFalse: [ super addLast: element ]
]

{ #category : #private }
FMSlotMultivalueLink >> unsafeRemove: element [

values remove: element ifAbsent: nil
super remove: element ifAbsent: nil
]

{ #category : #accessing }
FMSlotMultivalueLink >> value: aCollection [

^self removeAll: values copy; addAll: aCollection
]

{ #category : #enumerating }
FMSlotMultivalueLink >> withIndexDo: aBlock [

values withIndexDo: aBlock
^ self
removeAll;
addAll: aCollection
]

0 comments on commit 8f04d63

Please sign in to comment.