FQuerySpec.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "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 params:[FQueryParams defaultInstance]];
  32. }
  33. - (id)copyWithZone:(NSZone *)zone {
  34. // Immutable
  35. return self;
  36. }
  37. - (id<FIndex>)index {
  38. return self.params.index;
  39. }
  40. - (BOOL)isDefault {
  41. return self.params.isDefault;
  42. }
  43. - (BOOL)loadsAllData {
  44. return self.params.loadsAllData;
  45. }
  46. - (BOOL)isEqual:(id)object {
  47. if (self == object) {
  48. return YES;
  49. }
  50. if (![object isKindOfClass:[FQuerySpec class]]) {
  51. return NO;
  52. }
  53. FQuerySpec *other = (FQuerySpec *)object;
  54. if (![self.path isEqual:other.path]) {
  55. return NO;
  56. }
  57. return [self.params isEqual:other.params];
  58. }
  59. - (NSUInteger)hash {
  60. return self.path.hash * 31 + self.params.hash;
  61. }
  62. - (NSString *)description {
  63. return [NSString stringWithFormat:@"FQuerySpec (path: %@, params: %@)", self.path, self.params];
  64. }
  65. @end