Package com.amihaiemil.eoyaml
Class StrictYamlMapping
- java.lang.Object
-
- com.amihaiemil.eoyaml.BaseYamlMapping
-
- com.amihaiemil.eoyaml.StrictYamlMapping
-
- All Implemented Interfaces:
YamlMapping,YamlNode,Comparable<YamlNode>
@Deprecated public final class StrictYamlMapping extends BaseYamlMapping
Deprecated.This class will be moved to the extensions package in one of the future releases. There will be no changes to it other than a more suitable package.Decorator for aYamlMappingwhich throws YamlNodenotFoundException, instead of returning null, if a given key doesn't exist in the mapping, or if it points to a different type of node than the demanded one.
It is based on the fail-fast and null-is-bad idea
see here: http://www.yegor256.com/2014/05/13/why-null-is-bad.html- Since:
- 1.0.0
- Version:
- $Id: 31dd44906ab8f91053b0c35c9ffa0f2f40a101a5 $
- Author:
- Mihai Andronache (amihaiemil@gmail.com)
-
-
Constructor Summary
Constructors Constructor Description StrictYamlMapping(YamlMapping decorated)Deprecated.Ctor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated 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()Deprecated.Comment referring to this Node.Set<YamlNode>keys()Deprecated.Return the keys' set of this mapping.StringtoString()Print this YamlNode using a StringWriter to create its String representation.YamlNodevalue(YamlNode key)Deprecated.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
-
StrictYamlMapping
public StrictYamlMapping(YamlMapping decorated)
Deprecated.Ctor.- Parameters:
decorated- Original YamlMapping
-
-
Method Detail
-
keys
public Set<YamlNode> keys()
Deprecated.Description copied from interface:YamlMappingReturn the keys' set of this mapping.- Returns:
- Set of YamlNode keys.
-
value
public YamlNode value(YamlNode key)
Deprecated.Description copied from interface:YamlMappingGet 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()
Deprecated.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.
-
-