Browse Source

dynamite: make TypeResult immutable and add equality operator

pull/370/head
Nikolas Rimikis 2 years ago
parent
commit
cff12fd6cc
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 1
      packages/dynamite/dynamite/lib/src/type_result/base.dart
  2. 12
      packages/dynamite/dynamite/lib/src/type_result/enum.dart
  3. 12
      packages/dynamite/dynamite/lib/src/type_result/list.dart
  4. 12
      packages/dynamite/dynamite/lib/src/type_result/map.dart
  5. 1
      packages/dynamite/dynamite/lib/src/type_result/object.dart
  6. 8
      packages/dynamite/dynamite/lib/src/type_result/type_result.dart
  7. 1
      packages/dynamite/dynamite/pubspec.yaml

1
packages/dynamite/dynamite/lib/src/type_result/base.dart

@ -1,5 +1,6 @@
part of 'type_result.dart';
@immutable
class TypeResultBase extends TypeResult {
TypeResultBase(
super.name, {

12
packages/dynamite/dynamite/lib/src/type_result/enum.dart

@ -1,5 +1,6 @@
part of 'type_result.dart';
@immutable
class TypeResultEnum extends TypeResult {
TypeResultEnum(
super.name,
@ -27,4 +28,15 @@ class TypeResultEnum extends TypeResult {
@override
String decode(final String object) => subType.decode(object);
@override
bool operator ==(final Object other) =>
other is TypeResultEnum &&
other.className == className &&
other.generics == generics &&
other.nullable == nullable &&
other.subType == subType;
@override
int get hashCode => className.hashCode + generics.hashCode + nullable.hashCode + subType.hashCode;
}

12
packages/dynamite/dynamite/lib/src/type_result/list.dart

@ -1,5 +1,6 @@
part of 'type_result.dart';
@immutable
class TypeResultList extends TypeResult {
TypeResultList(
super.name,
@ -27,4 +28,15 @@ class TypeResultList extends TypeResult {
@override
TypeResultList get dartType => TypeResultList('List', subType, nullable: nullable);
@override
bool operator ==(final Object other) =>
other is TypeResultList &&
other.className == className &&
other.generics == generics &&
other.nullable == nullable &&
other.subType == subType;
@override
int get hashCode => className.hashCode + generics.hashCode + nullable.hashCode + subType.hashCode;
}

12
packages/dynamite/dynamite/lib/src/type_result/map.dart

@ -1,5 +1,6 @@
part of 'type_result.dart';
@immutable
class TypeResultMap extends TypeResult {
TypeResultMap(
super.name,
@ -14,4 +15,15 @@ class TypeResultMap extends TypeResult {
@override
TypeResultMap get dartType => TypeResultMap('Map', subType, nullable: nullable);
@override
bool operator ==(final Object other) =>
other is TypeResultMap &&
other.className == className &&
other.generics == generics &&
other.nullable == nullable &&
other.subType == subType;
@override
int get hashCode => className.hashCode + generics.hashCode + nullable.hashCode + subType.hashCode;
}

1
packages/dynamite/dynamite/lib/src/type_result/object.dart

@ -2,6 +2,7 @@ part of 'type_result.dart';
const _contentString = 'ContentString';
@immutable
class TypeResultObject extends TypeResult {
TypeResultObject(
super.className, {

8
packages/dynamite/dynamite/lib/src/type_result/type_result.dart

@ -7,6 +7,7 @@ part 'list.dart';
part 'map.dart';
part 'object.dart';
@immutable
abstract class TypeResult {
TypeResult(
this.className, {
@ -91,4 +92,11 @@ abstract class TypeResult {
/// Native dart type equivalent
// ignore: avoid_returning_this
TypeResult get dartType => this;
@override
bool operator ==(final Object other) =>
other is TypeResult && other.className == className && other.generics == generics && other.nullable == nullable;
@override
int get hashCode => className.hashCode + generics.hashCode + nullable.hashCode;
}

1
packages/dynamite/dynamite/pubspec.yaml

@ -11,6 +11,7 @@ dependencies:
dart_style: ^2.3.1
intersperse: ^2.0.0
json_annotation: ^4.8.1
meta: ^1.9.1
path: ^1.8.3
dev_dependencies:

Loading…
Cancel
Save