Package com.amihaiemil.eoyaml.extensions
Class MergedYamlSequence
- java.lang.Object
-
- com.amihaiemil.eoyaml.BaseYamlSequence
-
- com.amihaiemil.eoyaml.extensions.MergedYamlSequence
-
- All Implemented Interfaces:
YamlNode,YamlSequence,Comparable<YamlNode>,Iterable<YamlNode>
public final class MergedYamlSequence extends BaseYamlSequence
Merge two YAML Sequences into a single one. Very useful in implementing Updating of an existing YamlSequence. Use it like this:final YamlSequence original = ...; final YamlSequence changed = ...; final YamlSequence merged = new MergedYamlSequence( original, changed, true|false ); //or, via the Supplier constructor: final YamlSequence merged = new MergedYamlSequence( original, () -> { //create the changed version on-the-fly, right here. }, true|false );- Since:
- 4.1.0
- Version:
- $Id: bccefba7fdc4dce03915f593f66a535f304e8c22 $
- Author:
- Mihai Andronache (amihaiemil@gmail.com)
-
-
Constructor Summary
Constructors Constructor Description MergedYamlSequence(YamlSequence original, YamlSequence changed)Constructor.MergedYamlSequence(YamlSequence original, YamlSequence changed, boolean overrideIndices)Constructor.MergedYamlSequence(YamlSequence original, Supplier<YamlSequence> changed)Constructor.MergedYamlSequence(YamlSequence original, Supplier<YamlSequence> changed, boolean overrideIndices)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends YamlNode>
TasClass(Class<T> clazz, Node type)Gives theYamlNodeinstance from node class and node type.YamlMappingasMapping()Gives a Mapping value of the node.ScalarasScalar()Gives a String value of the node.YamlSequenceasSequence()Gives a Sequence value of the node.YamlStreamasStream()Gives a Stream value of the node.Commentcomment()Comment referring to this Node.StringtoString()Print this YamlNode using a StringWriter to create its String representation.Collection<YamlNode>values()Fetch the values of this sequence.-
Methods inherited from class com.amihaiemil.eoyaml.BaseYamlSequence
compareTo, equals, hashCode, isEmpty, type
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface com.amihaiemil.eoyaml.YamlNode
asClass, asMapping, asScalar, asSequence, asStream
-
Methods inherited from interface com.amihaiemil.eoyaml.YamlSequence
date, dateTime, doubleNumber, floatNumber, foldedBlockScalar, integer, iterator, literalBlockScalar, longNumber, size, string, yamlMapping, yamlSequence
-
-
-
-
Constructor Detail
-
MergedYamlSequence
public MergedYamlSequence(YamlSequence original, YamlSequence changed)
Constructor. By default, it's simply going to add the elements of changed to the ones of original.- Parameters:
original- YamlSequence in which the changes will be merged.changed- YamlSequence containing the differences.
-
MergedYamlSequence
public MergedYamlSequence(YamlSequence original, Supplier<YamlSequence> changed)
Constructor. By default, it's simply going to add the elements of changed to the ones of original.- Parameters:
original- YamlSequence in which the changes will be merged.changed- Supplier of YamlSequence containing the differences.
-
MergedYamlSequence
public MergedYamlSequence(YamlSequence original, Supplier<YamlSequence> changed, boolean overrideIndices)
Constructor. You can choose whether to override existing indices or not.- Parameters:
original- YamlSequence in which the changes will be merged.changed- YamlSequence containing the differences.overrideIndices- Override existing indices or not?
-
MergedYamlSequence
public MergedYamlSequence(YamlSequence original, YamlSequence changed, boolean overrideIndices)
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.overrideIndices- Override existing indices or not?
-
-
Method Detail
-
values
public Collection<YamlNode> values()
Description copied from interface:YamlSequenceFetch the values of this sequence.- Returns:
- Collection of
YamlNode
-
comment
public Comment comment()
Description copied from interface:YamlNodeComment 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:YamlNodeGives a String value of the node.- Specified by:
asScalarin 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:YamlNodeGives a Mapping value of the node.- Specified by:
asMappingin 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:YamlNodeGives a Sequence value of the node.- Specified by:
asSequencein 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:YamlNodeGives a Stream value of the node.- Specified by:
asStreamin 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:YamlNodeGives theYamlNodeinstance from node class and node type.- Specified by:
asClassin interfaceYamlNode- Type Parameters:
T- Requested aYamlNodeclass instance.- Parameters:
clazz- Requested aYamlNodeclass.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:
toStringin classObject- Returns:
- String print of this YamlNode.
- Throws:
YamlPrintException- If there is any I/O problem when printing the YAML.
-
-