FIRSnapshotMetadata.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. if (self.pendingWrites != metadata.pendingWrites) return NO;
  45. if (self.fromCache != metadata.fromCache) return NO;
  46. return YES;
  47. }
  48. - (NSUInteger)hash {
  49. NSUInteger hash = self.pendingWrites ? 1 : 0;
  50. hash = hash * 31u + (self.fromCache ? 1 : 0);
  51. return hash;
  52. }
  53. @end
  54. NS_ASSUME_NONNULL_END