Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement the == and hashCode methods for AtKey, AtValue and Metadata classes #241

Merged
merged 4 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions at_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.0.27
* feat: Implement the `==` and `hashCode` methods for AtKey, AtValue and Metadata classes
## 3.0.26
* feat: Introduce notifyFetch verb
* fix: bug in at_exception_stack.dart
Expand Down
79 changes: 79 additions & 0 deletions at_commons/lib/src/keystore/at_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ class AtKey {
Metadata? metadata;
bool isRef = false;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is AtKey &&
runtimeType == other.runtimeType &&
key == other.key &&
_sharedWith == other._sharedWith &&
_sharedBy == other._sharedBy &&
namespace == other.namespace &&
metadata == other.metadata &&
isRef == other.isRef &&
_isLocal == other._isLocal;

@override
int get hashCode =>
key.hashCode ^
_sharedWith.hashCode ^
_sharedBy.hashCode ^
namespace.hashCode ^
metadata.hashCode ^
isRef.hashCode ^
_isLocal.hashCode;

/// When set to true, represents the [LocalKey]
/// These keys will never be synced between the client and secondary server.
bool _isLocal = false;
Expand Down Expand Up @@ -494,6 +517,55 @@ class Metadata {
}
return metaData;
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Metadata &&
runtimeType == other.runtimeType &&
ttl == other.ttl &&
ttb == other.ttb &&
ttr == other.ttr &&
ccd == other.ccd &&
availableAt == other.availableAt &&
expiresAt == other.expiresAt &&
refreshAt == other.refreshAt &&
createdAt == other.createdAt &&
updatedAt == other.updatedAt &&
dataSignature == other.dataSignature &&
sharedKeyStatus == other.sharedKeyStatus &&
isPublic == other.isPublic &&
isHidden == other.isHidden &&
namespaceAware == other.namespaceAware &&
isBinary == other.isBinary &&
isEncrypted == other.isEncrypted &&
isCached == other.isCached &&
sharedKeyEnc == other.sharedKeyEnc &&
pubKeyCS == other.pubKeyCS &&
encoding == other.encoding;

@override
int get hashCode =>
ttl.hashCode ^
ttb.hashCode ^
ttr.hashCode ^
ccd.hashCode ^
availableAt.hashCode ^
expiresAt.hashCode ^
refreshAt.hashCode ^
createdAt.hashCode ^
updatedAt.hashCode ^
dataSignature.hashCode ^
sharedKeyStatus.hashCode ^
isPublic.hashCode ^
isHidden.hashCode ^
namespaceAware.hashCode ^
isBinary.hashCode ^
isEncrypted.hashCode ^
isCached.hashCode ^
sharedKeyEnc.hashCode ^
pubKeyCS.hashCode ^
encoding.hashCode;
}

class AtValue {
Expand All @@ -504,4 +576,11 @@ class AtValue {
String toString() {
return 'AtValue{value: $value, metadata: $metadata}';
}

@override
bool operator ==(Object other) =>
identical(this, other) || other is AtValue && runtimeType == other.runtimeType && value == other.value && metadata == other.metadata;

@override
int get hashCode => value.hashCode ^ metadata.hashCode;
}
2 changes: 1 addition & 1 deletion at_commons/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_commons
description: A library of Dart and Flutter utility classes that are used across other components of the atPlatform.
version: 3.0.26
version: 3.0.27
repository: https://github.com/atsign-foundation/at_tools
homepage: https://atsign.dev

Expand Down