Skip to content

Commit

Permalink
Add method to copy node
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubenicos committed Jan 29, 2024
1 parent 30fd6f1 commit 994acbf
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/com/saicone/settings/SettingsNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.saicone.settings.node.ListNode;
import com.saicone.settings.node.MapNode;
import com.saicone.settings.node.NodeKey;
import com.saicone.settings.node.ObjectNode;
import com.saicone.settings.type.ValueType;
import com.saicone.settings.util.Strings;
Expand Down Expand Up @@ -461,6 +462,39 @@ default SettingsNode move(@NotNull String... path) {
return this;
}

/**
* Copy this node into new one and return the clone itself.
*
* @return a clone of this node.
*/
@NotNull
default SettingsNode copy() {
return copy(false);
}

/**
* Copy this node into new one and return the clone itself.
*
* @param parent true to save parent information.
* @return a clone of this node.
*/
@NotNull
default SettingsNode copy(boolean parent) {
return copy(parent, true);
}

/**
* Copy this node into new one and return the clone itself.
*
* @param parent true to save parent information.
* @param key true to save key information.
* @return a clone of this node.
*/
@NotNull
default SettingsNode copy(boolean parent, boolean key) {
return NodeKey.of(parent ? getParent() : null, key ? getKey() : null, this);
}

/**
* Cast this node into an object node type.
*
Expand Down

0 comments on commit 994acbf

Please sign in to comment.