Package com.amihaiemil.eoyaml.extensions
Class MergedYamlMapping
- java.lang.Object
-
- com.amihaiemil.eoyaml.BaseYamlMapping
-
- com.amihaiemil.eoyaml.extensions.MergedYamlMapping
-
- All Implemented Interfaces:
YamlMapping
,YamlNode
,Comparable<YamlNode>
public final class MergedYamlMapping extends BaseYamlMapping
Merge two YAML Mappings into a single one. Very useful in implementing Updating of an existing YamlMapping. Use it like this:final YamlMapping original = ...; final YamlMapping changed = ...; final YamlMapping merged = new MergedYamlMapping( original, changed, true|false ); //or, via the Supplier constructor: final YamlMapping merged = new MergedYamlMapping( original, () -> { //create the changed version on-the-fly, right here. }, true|false );
- Since:
- 4.1.0
- Version:
- $Id: c07b9f7b3e47ab637021dbfcd2e3d14ad9162937 $
- Author:
- Mihai Andronache ([email protected])
-
-
Constructor Summary
Constructors Constructor Description MergedYamlMapping(YamlMapping original, YamlMapping changed)
Constructor.MergedYamlMapping(YamlMapping original, YamlMapping changed, boolean overrideConflicts)
Constructor.MergedYamlMapping(YamlMapping original, Supplier<YamlMapping> changed)
Constructor.MergedYamlMapping(YamlMapping original, Supplier<YamlMapping> changed, boolean overrideConflicts)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends YamlNode>
TasClass(Class<T> clazz, Node type)
Gives theYamlNode
instance from node class and node type.YamlMapping
asMapping()
Gives a Mapping value of the node.Scalar
asScalar()
Gives a String value of the node.YamlSequence
asSequence()
Gives a Sequence value of the node.YamlStream
asStream()
Gives a Stream value of the node.Comment
comment()
Comment referring to this Node.Set<YamlNode>
keys()
Return the keys' set of this mapping.String
toString()
Print this YamlNode using a StringWriter to create its String representation.YamlNode
value(YamlNode key)
Get the YamlNode mapped to the specified key.-
Methods inherited from class com.amihaiemil.eoyaml.BaseYamlMapping
compareTo, equals, hashCode, isEmpty, type
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.amihaiemil.eoyaml.YamlMapping
date, date, dateTime, dateTime, doubleNumber, doubleNumber, floatNumber, floatNumber, foldedBlockScalar, foldedBlockScalar, integer, integer, literalBlockScalar, literalBlockScalar, longNumber, longNumber, string, string, value, values, yamlMapping, yamlMapping, yamlSequence, yamlSequence
-
-
-
-
Constructor Detail
-
MergedYamlMapping
public MergedYamlMapping(YamlMapping original, YamlMapping changed)
Constructor. By default, conflicting keys will not be overriden.- Parameters:
original
- YamlMapping in which the changes will be merged.changed
- YamlMapping containing the differences.
-
MergedYamlMapping
public MergedYamlMapping(YamlMapping original, Supplier<YamlMapping> changed)
Constructor. By default, conflicting keys will not be overriden.- Parameters:
original
- YamlMapping in which the changes will be merged.changed
- Supplier of YamlMapping containing the differences.
-
MergedYamlMapping
public MergedYamlMapping(YamlMapping original, Supplier<YamlMapping> changed, boolean overrideConflicts)
Constructor. You can choose whether conflicting keys will be overriden or not.- Parameters:
original
- YamlMapping in which the changes will be merged.changed
- YamlMapping containing the differences.overrideConflicts
- Override key conflicts or not?
-
MergedYamlMapping
public MergedYamlMapping(YamlMapping original, YamlMapping changed, boolean overrideConflicts)
Constructor. You can choose whether conflicting keys will be overriden or not.- Parameters:
original
- YamlMapping in which the changes will be merged.changed
- YamlMapping containing the differences.overrideConflicts
- Override key conflicts or not?
-
-
Method Detail
-
keys
public Set<YamlNode> keys()
Description copied from interface:YamlMapping
Return the keys' set of this mapping.- Returns:
- Set of YamlNode keys.
-
value
public YamlNode value(YamlNode key)
Description copied from interface:YamlMapping
Get the YamlNode mapped to the specified key.- Parameters:
key
- YamlNode key. Could be a simple scalar, a YamlMapping or a YamlSequence.- Returns:
- The found YamlNode or null if nothing is found.
-
comment
public Comment comment()
Description copied from interface:YamlNode
Comment referring to this Node.- Returns:
- Comment. If there is no comment, it will return an "empty" comment (an instance of Comment with empty-string value()).
-
asScalar
public final Scalar asScalar() throws YamlReadingException, ClassCastException
Description copied from interface:YamlNode
Gives a String value of the node.- Specified by:
asScalar
in interfaceYamlNode
- Returns:
- String value of the node.
- Throws:
YamlReadingException
- If the node type is not Scalar.ClassCastException
- If the node type couldn't defined correctly.
-
asMapping
public final YamlMapping asMapping() throws YamlReadingException, ClassCastException
Description copied from interface:YamlNode
Gives a Mapping value of the node.- Specified by:
asMapping
in interfaceYamlNode
- Returns:
- Mapping value of the node.
- Throws:
YamlReadingException
- If the node type is not Mapping.ClassCastException
- If the node type couldn't defined correctly.
-
asSequence
public final YamlSequence asSequence() throws YamlReadingException, ClassCastException
Description copied from interface:YamlNode
Gives a Sequence value of the node.- Specified by:
asSequence
in interfaceYamlNode
- Returns:
- Sequence value of the node.
- Throws:
YamlReadingException
- If the node type is not Sequence.ClassCastException
- If the node type couldn't defined correctly.
-
asStream
public final YamlStream asStream() throws YamlReadingException, ClassCastException
Description copied from interface:YamlNode
Gives a Stream value of the node.- Specified by:
asStream
in interfaceYamlNode
- Returns:
- Stream value of the node.
- Throws:
YamlReadingException
- If the node type is not Stream.ClassCastException
- If the node type couldn't defined correctly.
-
asClass
public final <T extends YamlNode> T asClass(Class<T> clazz, Node type) throws YamlReadingException, ClassCastException
Description copied from interface:YamlNode
Gives theYamlNode
instance from node class and node type.- Specified by:
asClass
in interfaceYamlNode
- Type Parameters:
T
- Requested aYamlNode
class instance.- Parameters:
clazz
- Requested aYamlNode
class.type
- Requested aNode
.- Returns:
- Requested a
YamlNode
. - Throws:
YamlReadingException
- If the type is not aYamlNode
.ClassCastException
- If the node type couldn't defined correctly.
-
toString
public final String toString()
Print this YamlNode using a StringWriter to create its String representation.- Overrides:
toString
in classObject
- Returns:
- String print of this YamlNode.
- Throws:
YamlPrintException
- If there is any I/O problem when printing the YAML.
-
-