Skip to content

Commit

Permalink
Add STON support to OrderedDictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli committed Feb 27, 2024
1 parent 1ea8fd3 commit fca0097
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions source/Buoy-Collections-GS64-Extensions/OrderedDictionary.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ OrderedDictionary class >> newFromPairs: aSequenceableCollection [
^ newDictionary
]

{ #category : 'STON' }
OrderedDictionary class >> fromSton: stonReader [

| dictionary |
dictionary := self new.
stonReader parseMapDo: [ :key :value |
dictionary at: key put: value ].
^ dictionary
]

{ #category : 'comparing' }
OrderedDictionary >> = anObject [
self == anObject
Expand Down Expand Up @@ -558,6 +568,13 @@ OrderedDictionary >> size [
^ dictionary size
]

{ #category : 'STON' }
OrderedDictionary >> stonOn: stonWriter [
stonWriter
writeObject: self
do: [ stonWriter encodeMap: self ]
]

{ #category : 'printing' }
OrderedDictionary >> storeOn: aStream [
aStream << '((' << self class name << ' new)'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,3 +1082,12 @@ OrderedDictionaryExtensionsTest >> testValuesDo [
should: [:block | dictionary valuesDo: block]
enumerate: (self orderedValuesFirst: i)]
]

{ #category : 'tests - STON' }
OrderedDictionaryExtensionsTest >> testSTONSerializationAndMaterialization [
| dictionary string |

dictionary := self dictionaryWithOrderedAssociations.
string := STON toString: dictionary.
self assertDictionary: dictionary equals: (STON fromString: string)
]

0 comments on commit fca0097

Please sign in to comment.