1+ import 'package:collection/collection.dart' ;
2+
13import '../model/character_set_profile.dart' ;
24import '../model/password_policy.dart' ;
35import 'password_generator_config_builder.dart' ;
@@ -42,7 +44,10 @@ class PasswordGeneratorConfig {
4244 map['policy' ] != null
4345 ? PasswordPolicy .fromMap (map['policy' ] as Map <String , dynamic >)
4446 : null ,
45- extra: (map['extra' ] as Map <String , dynamic >? ) ?? const {},
47+ extra:
48+ map['extra' ] != null
49+ ? Map .unmodifiable (map['extra' ] as Map <String , dynamic >)
50+ : const {},
4651 );
4752 }
4853
@@ -83,6 +88,35 @@ class PasswordGeneratorConfig {
8388 /// Additional configuration parameters for custom strategies.
8489 final Map <String , dynamic > extra;
8590
91+ /// Returns a copy of this configuration with the given fields replaced.
92+ PasswordGeneratorConfig copyWith ({
93+ int ? length,
94+ bool ? useUpperCase,
95+ bool ? useLowerCase,
96+ bool ? useNumbers,
97+ bool ? useSpecialChars,
98+ bool ? excludeAmbiguousChars,
99+ CharacterSetProfile ? characterSetProfile,
100+ int ? maxGenerationAttempts,
101+ Object ? policy = _sentinel,
102+ Map <String , dynamic >? extra,
103+ }) {
104+ return PasswordGeneratorConfig (
105+ length: length ?? this .length,
106+ useUpperCase: useUpperCase ?? this .useUpperCase,
107+ useLowerCase: useLowerCase ?? this .useLowerCase,
108+ useNumbers: useNumbers ?? this .useNumbers,
109+ useSpecialChars: useSpecialChars ?? this .useSpecialChars,
110+ excludeAmbiguousChars:
111+ excludeAmbiguousChars ?? this .excludeAmbiguousChars,
112+ characterSetProfile: characterSetProfile ?? this .characterSetProfile,
113+ maxGenerationAttempts:
114+ maxGenerationAttempts ?? this .maxGenerationAttempts,
115+ policy: policy == _sentinel ? this .policy : policy as PasswordPolicy ? ,
116+ extra: extra ?? this .extra,
117+ );
118+ }
119+
86120 /// Converts this configuration to a map.
87121 Map <String , dynamic > toMap () {
88122 return {
@@ -98,4 +132,43 @@ class PasswordGeneratorConfig {
98132 'extra' : extra,
99133 };
100134 }
135+
136+ @override
137+ bool operator == (Object other) {
138+ if (identical (this , other)) return true ;
139+ final collectionEquals = const DeepCollectionEquality ().equals;
140+
141+ return other is PasswordGeneratorConfig &&
142+ other.length == length &&
143+ other.useUpperCase == useUpperCase &&
144+ other.useLowerCase == useLowerCase &&
145+ other.useNumbers == useNumbers &&
146+ other.useSpecialChars == useSpecialChars &&
147+ other.excludeAmbiguousChars == excludeAmbiguousChars &&
148+ other.characterSetProfile == characterSetProfile &&
149+ other.maxGenerationAttempts == maxGenerationAttempts &&
150+ other.policy == policy &&
151+ collectionEquals (other.extra, extra);
152+ }
153+
154+ @override
155+ int get hashCode {
156+ return length.hashCode ^
157+ useUpperCase.hashCode ^
158+ useLowerCase.hashCode ^
159+ useNumbers.hashCode ^
160+ useSpecialChars.hashCode ^
161+ excludeAmbiguousChars.hashCode ^
162+ characterSetProfile.hashCode ^
163+ maxGenerationAttempts.hashCode ^
164+ policy.hashCode ^
165+ const DeepCollectionEquality ().hash (extra);
166+ }
167+
168+ @override
169+ String toString () {
170+ return 'PasswordGeneratorConfig(length: $length , useUpperCase: $useUpperCase , useLowerCase: $useLowerCase , useNumbers: $useNumbers , useSpecialChars: $useSpecialChars , excludeAmbiguousChars: $excludeAmbiguousChars , characterSetProfile: $characterSetProfile , maxGenerationAttempts: $maxGenerationAttempts , policy: $policy , extra: $extra )' ;
171+ }
101172}
173+
174+ const Object _sentinel = Object ();
0 commit comments