FIRAggregateQuerySnapshot.mm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2022 Google LLC
  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 "FIRAggregateQuerySnapshot+Internal.h"
  17. #import "FIRAggregateQuery.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. @implementation FIRAggregateQuerySnapshot {
  20. int64_t _result;
  21. FIRAggregateQuery* _query;
  22. }
  23. - (instancetype)initWithCount:(int64_t)count query:(FIRAggregateQuery*)query {
  24. if (self = [super init]) {
  25. _result = count;
  26. _query = query;
  27. }
  28. return self;
  29. }
  30. #pragma mark - NSObject Methods
  31. - (BOOL)isEqual:(nullable id)other {
  32. if (other == self) return YES;
  33. if (![[other class] isEqual:[self class]]) return NO;
  34. auto otherSnap = static_cast<FIRAggregateQuerySnapshot*>(other);
  35. return _result == otherSnap->_result && [_query isEqual:otherSnap->_query];
  36. }
  37. - (NSUInteger)hash {
  38. NSUInteger result = [_query hash];
  39. result = 31 * result + [[self count] hash];
  40. return result;
  41. }
  42. #pragma mark - Public Methods
  43. - (NSNumber*)count {
  44. return [NSNumber numberWithLongLong:_result];
  45. }
  46. - (FIRAggregateQuery*)query {
  47. return _query;
  48. }
  49. @end
  50. NS_ASSUME_NONNULL_END