FCacheNode.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/View/FCacheNode.h"
  17. #import "FirebaseDatabase/Sources/Core/Utilities/FPath.h"
  18. #import "FirebaseDatabase/Sources/Snapshot/FEmptyNode.h"
  19. #import "FirebaseDatabase/Sources/Snapshot/FIndexedNode.h"
  20. #import "FirebaseDatabase/Sources/Snapshot/FNode.h"
  21. @interface FCacheNode ()
  22. @property(nonatomic, readwrite) BOOL isFullyInitialized;
  23. @property(nonatomic, readwrite) BOOL isFiltered;
  24. @property(nonatomic, strong, readwrite) FIndexedNode *indexedNode;
  25. @end
  26. @implementation FCacheNode
  27. - (id)initWithIndexedNode:(FIndexedNode *)indexedNode
  28. isFullyInitialized:(BOOL)fullyInitialized
  29. isFiltered:(BOOL)filtered {
  30. self = [super init];
  31. if (self) {
  32. self.indexedNode = indexedNode;
  33. self.isFullyInitialized = fullyInitialized;
  34. self.isFiltered = filtered;
  35. }
  36. return self;
  37. }
  38. - (BOOL)isCompleteForPath:(FPath *)path {
  39. if (path.isEmpty) {
  40. return self.isFullyInitialized && !self.isFiltered;
  41. } else {
  42. NSString *childKey = [path getFront];
  43. return [self isCompleteForChild:childKey];
  44. }
  45. }
  46. - (BOOL)isCompleteForChild:(NSString *)childKey {
  47. return (self.isFullyInitialized && !self.isFiltered) ||
  48. [self.node hasChild:childKey];
  49. }
  50. - (id<FNode>)node {
  51. return self.indexedNode.node;
  52. }
  53. @end