FIRSnapshotMetadata.mm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FIRSnapshotMetadata.h"
  17. #import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. @interface FIRSnapshotMetadata ()
  20. - (instancetype)initWithPendingWrites:(BOOL)pendingWrites fromCache:(BOOL)fromCache;
  21. @end
  22. @implementation FIRSnapshotMetadata (Internal)
  23. + (instancetype)snapshotMetadataWithPendingWrites:(BOOL)pendingWrites fromCache:(BOOL)fromCache {
  24. return [[FIRSnapshotMetadata alloc] initWithPendingWrites:pendingWrites fromCache:fromCache];
  25. }
  26. @end
  27. @implementation FIRSnapshotMetadata
  28. - (instancetype)initWithPendingWrites:(BOOL)pendingWrites fromCache:(BOOL)fromCache {
  29. if (self = [super init]) {
  30. _pendingWrites = pendingWrites;
  31. _fromCache = fromCache;
  32. }
  33. return self;
  34. }
  35. // NSObject Methods
  36. - (BOOL)isEqual:(nullable id)other {
  37. if (other == self) return YES;
  38. if (![[other class] isEqual:[self class]]) return NO;
  39. return [self isEqualToMetadata:other];
  40. }
  41. - (BOOL)isEqualToMetadata:(nullable FIRSnapshotMetadata *)metadata {
  42. if (self == metadata) return YES;
  43. if (metadata == nil) return NO;
  44. return self.pendingWrites == metadata.pendingWrites && self.fromCache == metadata.fromCache;
  45. }
  46. - (NSUInteger)hash {
  47. NSUInteger hash = self.pendingWrites ? 1 : 0;
  48. hash = hash * 31u + (self.fromCache ? 1 : 0);
  49. return hash;
  50. }
  51. @end
  52. NS_ASSUME_NONNULL_END