From fca00974233f80a991d45047da9742cfa2be9400 Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Tue, 27 Feb 2024 14:23:39 -0300 Subject: [PATCH] Add STON support to OrderedDictionary --- .../OrderedDictionary.class.st | 17 +++++++++++++++++ .../OrderedDictionaryExtensionsTest.class.st | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/source/Buoy-Collections-GS64-Extensions/OrderedDictionary.class.st b/source/Buoy-Collections-GS64-Extensions/OrderedDictionary.class.st index 1372af6..85d7d2b 100644 --- a/source/Buoy-Collections-GS64-Extensions/OrderedDictionary.class.st +++ b/source/Buoy-Collections-GS64-Extensions/OrderedDictionary.class.st @@ -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 @@ -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)'. diff --git a/source/Buoy-Collections-Tests/OrderedDictionaryExtensionsTest.class.st b/source/Buoy-Collections-Tests/OrderedDictionaryExtensionsTest.class.st index c5a30f2..19edfc0 100644 --- a/source/Buoy-Collections-Tests/OrderedDictionaryExtensionsTest.class.st +++ b/source/Buoy-Collections-Tests/OrderedDictionaryExtensionsTest.class.st @@ -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) +] \ No newline at end of file