FImmutableTree.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/Utilities/FPath.h"
  17. #import "FirebaseDatabase/Sources/Utilities/Tuples/FTuplePathValue.h"
  18. #import "FirebaseDatabase/Sources/third_party/FImmutableSortedDictionary/FImmutableSortedDictionary/FImmutableSortedDictionary.h"
  19. @interface FImmutableTree : NSObject
  20. - (id)initWithValue:(id)aValue;
  21. - (id)initWithValue:(id)aValue
  22. children:(FImmutableSortedDictionary *)childrenMap;
  23. + (FImmutableTree *)empty;
  24. - (BOOL)isEmpty;
  25. - (FTuplePathValue *)findRootMostMatchingPath:(FPath *)relativePath
  26. predicate:(BOOL (^)(id))predicate;
  27. - (FTuplePathValue *)findRootMostValueAndPath:(FPath *)relativePath;
  28. - (FImmutableTree *)subtreeAtPath:(FPath *)relativePath;
  29. - (FImmutableTree *)setValue:(id)newValue atPath:(FPath *)relativePath;
  30. - (FImmutableTree *)removeValueAtPath:(FPath *)relativePath;
  31. - (id)valueAtPath:(FPath *)relativePath;
  32. - (id)rootMostValueOnPath:(FPath *)path;
  33. - (id)rootMostValueOnPath:(FPath *)path matching:(BOOL (^)(id))predicate;
  34. - (id)leafMostValueOnPath:(FPath *)path;
  35. - (id)leafMostValueOnPath:(FPath *)relativePath
  36. matching:(BOOL (^)(id))predicate;
  37. - (BOOL)containsValueMatching:(BOOL (^)(id))predicate;
  38. - (FImmutableTree *)setTree:(FImmutableTree *)newTree
  39. atPath:(FPath *)relativePath;
  40. - (id)foldWithBlock:(id (^)(FPath *path, id value,
  41. NSDictionary *foldedChildren))block;
  42. - (id)findOnPath:(FPath *)path
  43. andApplyBlock:(id (^)(FPath *path, id value))block;
  44. - (FPath *)forEachOnPath:(FPath *)path
  45. whileBlock:(BOOL (^)(FPath *path, id value))block;
  46. - (FImmutableTree *)forEachOnPath:(FPath *)path
  47. performBlock:(void (^)(FPath *path, id value))block;
  48. - (void)forEach:(void (^)(FPath *path, id value))block;
  49. - (void)forEachChild:(void (^)(NSString *childKey, id childValue))block;
  50. @property(nonatomic, strong, readonly) id value;
  51. @property(nonatomic, strong, readonly) FImmutableSortedDictionary *children;
  52. @end