FQuerySpec.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "FirebaseDatabase/Sources/Core/FQuerySpec.h"
  17. @interface FQuerySpec ()
  18. @property(nonatomic, strong, readwrite) FPath *path;
  19. @property(nonatomic, strong, readwrite) FQueryParams *params;
  20. @end
  21. @implementation FQuerySpec
  22. - (id)initWithPath:(FPath *)path params:(FQueryParams *)params {
  23. self = [super init];
  24. if (self != nil) {
  25. self->_path = path;
  26. self->_params = params;
  27. }
  28. return self;
  29. }
  30. + (FQuerySpec *)defaultQueryAtPath:(FPath *)path {
  31. return [[FQuerySpec alloc] initWithPath:path
  32. params:[FQueryParams defaultInstance]];
  33. }
  34. - (id)copyWithZone:(NSZone *)zone {
  35. // Immutable
  36. return self;
  37. }
  38. - (id<FIndex>)index {
  39. return self.params.index;
  40. }
  41. - (BOOL)isDefault {
  42. return self.params.isDefault;
  43. }
  44. - (BOOL)loadsAllData {
  45. return self.params.loadsAllData;
  46. }
  47. - (BOOL)isEqual:(id)object {
  48. if (self == object) {
  49. return YES;
  50. }
  51. if (![object isKindOfClass:[FQuerySpec class]]) {
  52. return NO;
  53. }
  54. FQuerySpec *other = (FQuerySpec *)object;
  55. if (![self.path isEqual:other.path]) {
  56. return NO;
  57. }
  58. return [self.params isEqual:other.params];
  59. }
  60. - (NSUInteger)hash {
  61. return self.path.hash * 31 + self.params.hash;
  62. }
  63. - (NSString *)description {
  64. return [NSString stringWithFormat:@"FQuerySpec (path: %@, params: %@)",
  65. self.path, self.params];
  66. }
  67. @end