11import 'package:iapetus/src/common/entities/pandora_type.dart' ;
22
3- abstract class PandoraEntity {
3+ abstract interface class PandoraEntity {
44 PandoraType get pandoraType;
55
66 String get pandoraId;
77
8+ factory PandoraEntity .parse (String pandoraId) = _ReconstructedPandoraEntity ;
9+
810 /// A equality function useful for keeping Pandora entities in sets.
911 static bool setEquals (
1012 PandoraEntity pandoraEntity1,
@@ -16,3 +18,34 @@ abstract class PandoraEntity {
1618 static int setHashCode (PandoraEntity pandoraEntity) =>
1719 pandoraEntity.pandoraId.hashCode;
1820}
21+
22+ /// A [PandoraEntity] constructed from a raw Pandora ID with type inference.
23+ class _ReconstructedPandoraEntity implements PandoraEntity {
24+ @override
25+ final PandoraType pandoraType;
26+
27+ @override
28+ final String pandoraId;
29+
30+ _ReconstructedPandoraEntity (this .pandoraId)
31+ : pandoraType = _idTable[pandoraId.substring (0 , 2 )] ??
32+ (throw FormatException ('Unknown Pandora type!' , pandoraId, 0 ));
33+
34+ @override
35+ String toString () {
36+ return '_ReconstructedPandoraEntity{pandoraType: $pandoraType , pandoraId: $pandoraId }' ;
37+ }
38+
39+ @override
40+ bool operator == (Object other) =>
41+ identical (this , other) ||
42+ other is _ReconstructedPandoraEntity &&
43+ runtimeType == other.runtimeType &&
44+ pandoraId == other.pandoraId;
45+
46+ @override
47+ int get hashCode => pandoraId.hashCode;
48+
49+ static final _idTable =
50+ pandoraTypeEnumMap.map ((key, value) => MapEntry (value, key));
51+ }
0 commit comments