Class NodeStateCopier.Builder

  • Enclosing class:
    NodeStateCopier

    public static class NodeStateCopier.Builder
    extends java.lang.Object
    The NodeStateCopier.Builder allows configuring a NodeState copy operation with includePaths, excludePaths and mergePaths.
    Include paths can define which paths should be copied from the source to the target.
    Exclude paths allow restricting which paths should be copied. This is especially useful when there are individual nodes in an included path that should not be copied.
    By default copying will remove items that already exist in the target but do not exist in the source. If this behaviour is undesired that is where merge paths come in.
    Merge paths dictate in which parts of the tree the copy operation should be additive, i.e. the content from source is merged with the content in the target. Nodes that are present in the target but not in the source are then not deleted. However, in the case where nodes are present in both the source and the target, the node from the source is copied with its properties and any properties previously present on the target's node are lost.
    Finally, using one of the copy methods, NodeStores or NodeStates can be copied.
    • Method Detail

      • include

        @NotNull
        public @NotNull NodeStateCopier.Builder include​(@NotNull
                                                        @NotNull java.util.Set<java.lang.String> paths)
        Set include paths.
        Parameters:
        paths - include paths
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • include

        @NotNull
        public @NotNull NodeStateCopier.Builder include​(@NotNull
                                                        @NotNull java.lang.String... paths)
        Convenience wrapper for include(Set).
        Parameters:
        paths - include paths
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • preserve

        @NotNull
        public @NotNull NodeStateCopier.Builder preserve​(@NotNull
                                                         @org.jetbrains.annotations.NotNull boolean preserveOnTarget)
        Set if preserve paths on target
        Parameters:
        preserveOnTarget - if paths on target are preserved if not present on source
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • exclude

        @NotNull
        public @NotNull NodeStateCopier.Builder exclude​(@NotNull
                                                        @NotNull java.util.Set<java.lang.String> paths)
        Set exclude paths.
        Parameters:
        paths - exclude paths
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • exclude

        @NotNull
        public @NotNull NodeStateCopier.Builder exclude​(@NotNull
                                                        @NotNull java.lang.String... paths)
        Convenience wrapper for exclude(Set).
        Parameters:
        paths - exclude paths
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • supportFragment

        @NotNull
        public @NotNull NodeStateCopier.Builder supportFragment​(@NotNull
                                                                @NotNull java.util.Set<java.lang.String> paths)
        Set fragment paths.
        Parameters:
        paths - fragment paths
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • supportFragment

        @NotNull
        public @NotNull NodeStateCopier.Builder supportFragment​(@NotNull
                                                                @NotNull java.lang.String... paths)
        Convenience wrapper for supportFragment(Set).
        Parameters:
        paths - fragment paths
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • excludeFragments

        @NotNull
        public @NotNull NodeStateCopier.Builder excludeFragments​(@NotNull
                                                                 @NotNull java.util.Set<java.lang.String> fragments)
        Set exclude fragments.
        Parameters:
        fragments - exclude fragments
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • excludeFragments

        @NotNull
        public @NotNull NodeStateCopier.Builder excludeFragments​(@NotNull
                                                                 @NotNull java.lang.String... fragments)
        Convenience wrapper for exclude(Set).
        Parameters:
        fragments - exclude fragments
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • merge

        @NotNull
        public @NotNull NodeStateCopier.Builder merge​(@NotNull
                                                      @NotNull java.util.Set<java.lang.String> paths)
        Set merge paths.
        Parameters:
        paths - merge paths
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • merge

        @NotNull
        public @NotNull NodeStateCopier.Builder merge​(@NotNull
                                                      @NotNull java.lang.String... paths)
        Convenience wrapper for merge(Set).
        Parameters:
        paths - merge paths
        Returns:
        this Builder instance
        See Also:
        NodeStateCopier(Set, Set, Set, Set, Set, boolean, boolean, Consumer)
      • withReferenceableFrozenNodes

        @NotNull
        public @NotNull NodeStateCopier.Builder withReferenceableFrozenNodes​(boolean isReferenceable)
      • withNodeConsumer

        public NodeStateCopier.Builder withNodeConsumer​(@NotNull
                                                        @NotNull java.util.function.Consumer consumer)
        Set consumer for node additions.
        Parameters:
        consumer - consumer to listen to path additions
        Returns:
        this Builder instance
      • copy

        public boolean copy​(@NotNull
                            @NotNull NodeState sourceRoot,
                            @NotNull
                            @NotNull NodeBuilder targetRoot)
        Creates a NodeStateCopier to copy the sourceRoot NodeState to the targetRoot NodeBuilder, using any include, exclude, merge paths and consumer set on this NodeStateCopier.Builder.
        It is the responsibility of the caller to persist any changes using e.g. NodeStore.merge(NodeBuilder, CommitHook, CommitInfo).
        Parameters:
        sourceRoot - NodeState to copy from
        targetRoot - NodeBuilder to copy to
        Returns:
        true if there were any changes, false if sourceRoot and targetRoot represent the same content
      • copy

        public boolean copy​(@NotNull
                            @NotNull NodeStore source,
                            @NotNull
                            @NotNull NodeStore target)
                     throws CommitFailedException
        Creates a NodeStateCopier to copy the source NodeStore to the target NodeStore, using any include, exclude, merge paths and consumer set on this NodeStateCopier.Builder.
        Changes are automatically persisted with empty CommitHooks and CommitInfo via NodeStore.merge(NodeBuilder, CommitHook, CommitInfo).
        Parameters:
        source - NodeStore to copy from
        target - NodeStore to copy to
        Returns:
        true if there were any changes, false if source and target represent the same content
        Throws:
        CommitFailedException - if the copy operation fails