Package com.amihaiemil.eoyaml
Class BaseYamlMapping
- java.lang.Object
-
- com.amihaiemil.eoyaml.BaseYamlMapping
-
- All Implemented Interfaces:
YamlMapping,YamlNode,Comparable<YamlNode>
- Direct Known Subclasses:
EmptyYamlMapping,MergedYamlMapping,StrictYamlMapping
public abstract class BaseYamlMapping extends Object implements YamlMapping
Base YamlMapping which all implementations of YamlMapping should extend. It implementing toString(), equals, hashcode and compareTo methods.
These methods should be default methods on the interface, but we are not allowed to have default implementations of java.lang.Object methods.- Since:
- 4.0.0
- Version:
- $Id: 2c8a407b9812bd53a41bc1098af15eccbfedba37 $
- Author:
- Mihai Andronache (amihaiemil@gmail.com)
-
-
Constructor Summary
Constructors Constructor Description BaseYamlMapping()
-
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.intcompareTo(YamlNode other)Compare this Mapping to another node.
A Mapping is always considered greater than a Scalar or a Sequence.
If other is a Mapping, their integer lengths are compared - the one with the greater length is considered greater.booleanequals(Object other)Equals method for YamlMapping.inthashCode()booleanisEmpty()Is this YamlNode empty?StringtoString()Print this YamlNode using a StringWriter to create its String representation.Nodetype()Type of the node.-
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, keys, literalBlockScalar, literalBlockScalar, longNumber, longNumber, string, string, value, value, values, yamlMapping, yamlMapping, yamlSequence, yamlSequence
-
-
-
-
Method Detail
-
equals
public final boolean equals(Object other)
Equals method for YamlMapping. It returns true if the compareTo(...) method returns 0.
-
compareTo
public final int compareTo(YamlNode other)
Compare this Mapping to another node.
A Mapping is always considered greater than a Scalar or a Sequence.
If other is a Mapping, their integer lengths are compared - the one with the greater length is considered greater. If the lengths are equal, then the 2 Mappings are equal if all elements are equal (K==K and V==V). If the elements are not identical, the comparison of the first unequal elements is returned.- Specified by:
compareToin interfaceComparable<YamlNode>- Parameters:
other- The other AbstractNode.- Returns:
- a value < 0 if this < other
0 if this == other or
a value > 0 if this > other
-
isEmpty
public final boolean isEmpty()
Description copied from interface:YamlNodeIs this YamlNode empty?
-
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.
-
-