Skip to content

Commit

Permalink
rework explicit identity normalizer feenkcom/gtoolkit#4140
Browse files Browse the repository at this point in the history
  • Loading branch information
girba committed Nov 4, 2024
1 parent 38127dd commit cab3ee3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 43 deletions.
50 changes: 36 additions & 14 deletions src/Brick-Glamorous/BrExplicitIdentityNormalizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ Class {
#name : #BrExplicitIdentityNormalizer,
#superclass : #BrIdentityNormalizer,
#instVars : [
'colors',
'defaultColor'
'candidates',
'defaultCandidate'
],
#category : 'Brick-Glamorous-Normalizer'
#category : #'Brick-Glamorous-Normalizer'
}

{ #category : #'instance creation' }
BrExplicitIdentityNormalizer class >> startingWithBlue [
^ self new
setIndexTo: Color blue;
yourself
]

{ #category : #'instance creation' }
BrExplicitIdentityNormalizer class >> startingWithRed [
^ self new
setIndexTo: Color red;
yourself
]

{ #category : #'instance creation' }
BrExplicitIdentityNormalizer class >> withCommand: aBlock withColors: aCollection withDefaultColor: aColor [

Expand All @@ -18,34 +32,42 @@ BrExplicitIdentityNormalizer class >> withCommand: aBlock withColors: aCollectio
]

{ #category : #accessing }
BrExplicitIdentityNormalizer >> colors [

^colors
BrExplicitIdentityNormalizer >> candidates [
^ candidates
]

{ #category : #accessing }
BrExplicitIdentityNormalizer >> candidates: aCollection [
candidates := aCollection
]

{ #category : #accessing }
BrExplicitIdentityNormalizer >> colors: anObject [
candidates := anObject
]

{ #category : #accessing }
BrExplicitIdentityNormalizer >> defaultCandidate: anObject [

colors := anObject
defaultCandidate := anObject
]

{ #category : #accessing }
BrExplicitIdentityNormalizer >> defaultColor [

^defaultColor
^defaultCandidate
]

{ #category : #accessing }
BrExplicitIdentityNormalizer >> defaultColor: anObject [

defaultColor := anObject
defaultCandidate := anObject
]

{ #category : #private }
BrExplicitIdentityNormalizer >> nextColor [

colorIndex := colorIndex + 1.
^colorIndex > self colors size
BrExplicitIdentityNormalizer >> nextResult [
resultIndex := resultIndex + 1.
^resultIndex > self candidates size
ifTrue: [ self defaultColor ]
ifFalse: [ self colors at: colorIndex ]
ifFalse: [ self candidates at: resultIndex ]
]
37 changes: 11 additions & 26 deletions src/Brick-Glamorous/BrIdentityNormalizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,11 @@ Class {
#superclass : #BrGlamorousNormalizer,
#instVars : [
'dictionary',
'colorIndex'
'resultIndex'
],
#category : 'Brick-Glamorous-Normalizer'
#category : #'Brick-Glamorous-Normalizer'
}

{ #category : #'instance creation' }
BrIdentityNormalizer class >> startingWithBlue [
^ self new
setIndexTo: Color blue;
yourself
]

{ #category : #'instance creation' }
BrIdentityNormalizer class >> startingWithRed [
^ self new
setIndexTo: Color red;
yourself
]

{ #category : #'instance creation' }
BrIdentityNormalizer class >> withCommand: aBlock [

Expand All @@ -31,38 +17,37 @@ BrIdentityNormalizer class >> withCommand: aBlock [
]

{ #category : #'initialize-release' }
BrIdentityNormalizer >> colors [
BrIdentityNormalizer >> candidates [
^ BrGlamorousColors distinctTenStrongColors
]

{ #category : #'initialize-release' }
BrIdentityNormalizer >> initialize [

super initialize.
colorIndex := 0.
resultIndex := 0.
dictionary := Dictionary new.
command := #yourself
]

{ #category : #private }
BrIdentityNormalizer >> nextColor [
BrIdentityNormalizer >> nextResult [

colorIndex := colorIndex \\ self colors size + 1.
^self colors at: colorIndex
resultIndex := resultIndex \\ self candidates size + 1.
^self candidates at: resultIndex
]

{ #category : #private }
BrIdentityNormalizer >> setIndexTo: aColor [
"colorAsSymbol has to be one of Color colorNames.
The method set the current index to the color given in parameter"
BrIdentityNormalizer >> setIndexTo: aCandidate [
"The method set the current index to the candidate given in parameter"

colorIndex := (self colors indexOf: aColor) - 1
resultIndex := (self candidates indexOf: aCandidate) - 1
]

{ #category : #accessing }
BrIdentityNormalizer >> value: anEntity [

^ dictionary
at: (command cull: anEntity)
ifAbsentPut: [ self nextColor ]
ifAbsentPut: [ self nextResult ]
]
6 changes: 3 additions & 3 deletions src/Brick-Glamorous/BrNormalizerExamples.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #BrNormalizerExamples,
#superclass : #Object,
#category : 'Brick-Glamorous-Normalizer'
#category : #'Brick-Glamorous-Normalizer'
}

{ #category : #'explicit identity' }
Expand Down Expand Up @@ -75,15 +75,15 @@ BrNormalizerExamples >> identityStartingWithBlue [
<gtExample>
| n |
n := BrIdentityNormalizer startingWithBlue.
self assert: n nextColor = Color blue
self assert: n nextResult = Color blue
]

{ #category : #identity }
BrNormalizerExamples >> identityStartingWithRed [
<gtExample>
| n |
n := BrIdentityNormalizer startingWithRed.
self assert: n nextColor = Color red
self assert: n nextResult = Color red
]

{ #category : #identity }
Expand Down

0 comments on commit cab3ee3

Please sign in to comment.