本文整理匯總了Java中org.yaml.snakeyaml.nodes.Node.getStartMark方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getStartMark方法的具體用法?Java Node.getStartMark怎麽用?Java Node.getStartMark使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.yaml.snakeyaml.nodes.Node
的用法示例。
在下文中一共展示了Node.getStartMark方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSingleNode
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
/**
* Reads a document from a source that contains only one document.
* <p>
* If the stream contains more than one document an exception is thrown.
* </p>
*
* @return The root node of the document or <code>null</code> if no document
* is available.
*/
public Node getSingleNode() {
// Drop the STREAM-START event.
parser.getEvent();
// Compose a document if the stream is not empty.
Node document = null;
if (!parser.checkEvent(Event.ID.StreamEnd)) {
document = composeDocument();
}
// Ensure that the stream contains no more documents.
if (!parser.checkEvent(Event.ID.StreamEnd)) {
Event event = parser.getEvent();
throw new ComposerException("expected a single document in the stream",
document.getStartMark(), "but found another document", event.getStartMark());
}
// Drop the STREAM-END event.
parser.getEvent();
return document;
}
示例2: constructObject
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
/**
* Construct object from the specified Node. Return existing instance if the
* node is already constructed.
*
* @param node
* Node to be constructed
* @return Java instance
*/
protected Object constructObject(Node node) {
if (constructedObjects.containsKey(node)) {
return constructedObjects.get(node);
}
if (recursiveObjects.contains(node)) {
throw new ConstructorException(null, null, "found unconstructable recursive node",
node.getStartMark());
}
recursiveObjects.add(node);
Construct constructor = getConstructor(node);
Object data = constructor.construct(node);
constructedObjects.put(node, data);
recursiveObjects.remove(node);
if (node.isTwoStepsConstruction()) {
constructor.construct2ndStep(node, data);
}
return data;
}
示例3: getSingleNode
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
/**
* Reads a document from a source that contains only one document.
* <p>
* If the stream contains more than one document an exception is thrown.
* </p>
*
* @return The root node of the document or <code>null</code> if no document
* is available.
*/
public Node getSingleNode() {
// Drop the STREAM-START event.
parser.getEvent();
// Compose a document if the stream is not empty.
Node document = null;
if (!parser.checkEvent(Event.ID.StreamEnd)) {
document = composeDocument();
}
// Ensure that the stream contains no more documents.
if (!parser.checkEvent(Event.ID.StreamEnd)) {
Event event = parser.getEvent();
throw new ComposerException("expected a single document in the stream",
document.getStartMark(), "but found another document", event.getStartMark());
}
// Drop the STREAM-END event.
parser.getEvent();
return document;
}
示例4: constructObject
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
/**
* Construct object from the specified Node. Return existing instance if the
* node is already constructed.
*
* @param node
* Node to be constructed
* @return Java instance
*/
protected Object constructObject(Node node) {
if (constructedObjects.containsKey(node)) {
return constructedObjects.get(node);
}
if (recursiveObjects.contains(node)) {
throw new ConstructorException(null, null, "found unconstructable recursive node",
node.getStartMark());
}
recursiveObjects.add(node);
Construct constructor = getConstructor(node);
Object data = constructor.construct(node);
constructedObjects.put(node, data);
recursiveObjects.remove(node);
if (node.isTwoStepsConstruction()) {
constructor.construct2ndStep(node, data);
}
return data;
}
示例5: construct2ndStep
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
public void construct2ndStep(Node node, Object object) {
try {
getConstructor(node).construct2ndStep(node, object);
} catch (Exception e) {
throw new ConstructorException(null, null,
"Can't construct a second step for a java object for " + node.getTag()
+ "; exception=" + e.getMessage(), node.getStartMark(), e);
}
}
示例6: construct
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
public Object construct(Node node) {
// Note: we do not check for duplicate keys, because it's too
// CPU-expensive.
Map<Object, Object> omap = new LinkedHashMap<Object, Object>();
if (!(node instanceof SequenceNode)) {
throw new ConstructorException("while constructing an ordered map",
node.getStartMark(), "expected a sequence, but found " + node.getNodeId(),
node.getStartMark());
}
SequenceNode snode = (SequenceNode) node;
for (Node subnode : snode.getValue()) {
if (!(subnode instanceof MappingNode)) {
throw new ConstructorException("while constructing an ordered map",
node.getStartMark(), "expected a mapping of length 1, but found "
+ subnode.getNodeId(), subnode.getStartMark());
}
MappingNode mnode = (MappingNode) subnode;
if (mnode.getValue().size() != 1) {
throw new ConstructorException("while constructing an ordered map",
node.getStartMark(), "expected a single mapping item, but found "
+ mnode.getValue().size() + " items", mnode.getStartMark());
}
Node keyNode = mnode.getValue().get(0).getKeyNode();
Node valueNode = mnode.getValue().get(0).getValueNode();
Object key = constructObject(keyNode);
Object value = constructObject(valueNode);
omap.put(key, value);
}
return omap;
}
示例7: construct
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
public Object construct(Node node) {
// Note: we do not check for duplicate keys, because it's too
// CPU-expensive.
Map<Object, Object> omap = new LinkedHashMap<Object, Object>();
if (!(node instanceof SequenceNode)) {
throw new ConstructorException("while constructing an ordered map",
node.getStartMark(), "expected a sequence, but found " + node.getNodeId(),
node.getStartMark());
}
SequenceNode snode = (SequenceNode) node;
for (Node subnode : snode.getValue()) {
if (!(subnode instanceof MappingNode)) {
throw new ConstructorException("while constructing an ordered map",
node.getStartMark(),
"expected a mapping of length 1, but found " + subnode.getNodeId(),
subnode.getStartMark());
}
MappingNode mnode = (MappingNode) subnode;
if (mnode.getValue().size() != 1) {
throw new ConstructorException("while constructing an ordered map",
node.getStartMark(), "expected a single mapping item, but found "
+ mnode.getValue().size() + " items",
mnode.getStartMark());
}
Node keyNode = mnode.getValue().get(0).getKeyNode();
Node valueNode = mnode.getValue().get(0).getValueNode();
Object key = constructObject(keyNode);
Object value = constructObject(valueNode);
omap.put(key, value);
}
return omap;
}
示例8: mergeNode
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
/**
* Does merge for supplied mapping node.
*
* @param node
* where to merge
* @param isPreffered
* true if keys of node should take precedence over others...
* @param key2index
* maps already merged keys to index from values
* @param values
* collects merged NodeTuple
* @return list of the merged NodeTuple (to be set as value for the
* MappingNode)
*/
private List<NodeTuple> mergeNode(MappingNode node, boolean isPreffered,
Map<Object, Integer> key2index, List<NodeTuple> values) {
List<NodeTuple> nodeValue = node.getValue();
// reversed for http://code.google.com/p/snakeyaml/issues/detail?id=139
Collections.reverse(nodeValue);
for (Iterator<NodeTuple> iter = nodeValue.iterator(); iter.hasNext();) {
final NodeTuple nodeTuple = iter.next();
final Node keyNode = nodeTuple.getKeyNode();
final Node valueNode = nodeTuple.getValueNode();
if (keyNode.getTag().equals(Tag.MERGE)) {
iter.remove();
switch (valueNode.getNodeId()) {
case mapping:
MappingNode mn = (MappingNode) valueNode;
mergeNode(mn, false, key2index, values);
break;
case sequence:
SequenceNode sn = (SequenceNode) valueNode;
List<Node> vals = sn.getValue();
for (Node subnode : vals) {
if (!(subnode instanceof MappingNode)) {
throw new ConstructorException("while constructing a mapping",
node.getStartMark(),
"expected a mapping for merging, but found "
+ subnode.getNodeId(), subnode.getStartMark());
}
MappingNode mnode = (MappingNode) subnode;
mergeNode(mnode, false, key2index, values);
}
break;
default:
throw new ConstructorException("while constructing a mapping",
node.getStartMark(),
"expected a mapping or list of mappings for merging, but found "
+ valueNode.getNodeId(), valueNode.getStartMark());
}
} else {
// we need to construct keys to avoid duplications
Object key = constructObject(keyNode);
if (!key2index.containsKey(key)) { // 1st time merging key
values.add(nodeTuple);
// keep track where tuple for the key is
key2index.put(key, values.size() - 1);
} else if (isPreffered) { // there is value for the key, but we
// need to override it
// change value for the key using saved position
values.set(key2index.get(key), nodeTuple);
}
}
}
return values;
}
示例9: mergeNode
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
/**
* Does merge for supplied mapping node.
*
* @param node
* where to merge
* @param isPreffered
* true if keys of node should take precedence over others...
* @param key2index
* maps already merged keys to index from values
* @param values
* collects merged NodeTuple
* @return list of the merged NodeTuple (to be set as value for the
* MappingNode)
*/
private List<NodeTuple> mergeNode(MappingNode node, boolean isPreffered,
Map<Object, Integer> key2index, List<NodeTuple> values) {
Iterator<NodeTuple> iter = node.getValue().iterator();
while (iter.hasNext()) {
final NodeTuple nodeTuple = iter.next();
final Node keyNode = nodeTuple.getKeyNode();
final Node valueNode = nodeTuple.getValueNode();
if (keyNode.getTag().equals(Tag.MERGE)) {
iter.remove();
switch (valueNode.getNodeId()) {
case mapping:
MappingNode mn = (MappingNode) valueNode;
mergeNode(mn, false, key2index, values);
break;
case sequence:
SequenceNode sn = (SequenceNode) valueNode;
List<Node> vals = sn.getValue();
for (Node subnode : vals) {
if (!(subnode instanceof MappingNode)) {
throw new ConstructorException("while constructing a mapping",
node.getStartMark(),
"expected a mapping for merging, but found "
+ subnode.getNodeId(),
subnode.getStartMark());
}
MappingNode mnode = (MappingNode) subnode;
mergeNode(mnode, false, key2index, values);
}
break;
default:
throw new ConstructorException("while constructing a mapping",
node.getStartMark(),
"expected a mapping or list of mappings for merging, but found "
+ valueNode.getNodeId(),
valueNode.getStartMark());
}
} else {
// we need to construct keys to avoid duplications
Object key = constructObject(keyNode);
if (!key2index.containsKey(key)) { // 1st time merging key
values.add(nodeTuple);
// keep track where tuple for the key is
key2index.put(key, values.size() - 1);
} else if (isPreffered) { // there is value for the key, but we
// need to override it
// change value for the key using saved position
values.set(key2index.get(key), nodeTuple);
}
}
}
return values;
}