本文整理汇总了Java中org.yaml.snakeyaml.nodes.MappingNode.getStartMark方法的典型用法代码示例。如果您正苦于以下问题:Java MappingNode.getStartMark方法的具体用法?Java MappingNode.getStartMark怎么用?Java MappingNode.getStartMark使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.yaml.snakeyaml.nodes.MappingNode
的用法示例。
在下文中一共展示了MappingNode.getStartMark方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructSet2ndStep
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的package包/类
protected void constructSet2ndStep(MappingNode node, Set<Object> set) {
List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
for (NodeTuple tuple : nodeValue) {
Node keyNode = tuple.getKeyNode();
Object key = constructObject(keyNode);
if (key != null) {
try {
key.hashCode();// check circular dependencies
} catch (Exception e) {
throw new ConstructorException("while constructing a Set", node.getStartMark(),
"found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e);
}
}
if (keyNode.isTwoStepsConstruction()) {
/*
* if keyObject is created it 2 steps we should postpone putting
* it into the set because it may have different hash after
* initialization compared to clean just created one. And set of
* course does not observe value hashCode changes.
*/
sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
} else {
set.add(key);
}
}
}
示例2: constructSet2ndStep
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的package包/类
protected void constructSet2ndStep(MappingNode node, Set<Object> set) {
List<NodeTuple> nodeValue = node.getValue();
for (NodeTuple tuple : nodeValue) {
Node keyNode = tuple.getKeyNode();
Object key = constructObject(keyNode);
if (key != null) {
try {
key.hashCode();// check circular dependencies
} catch (Exception e) {
throw new ConstructorException("while constructing a Set", node.getStartMark(),
"found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e);
}
}
if (keyNode.isTwoStepsConstruction()) {
/*
* if keyObject is created it 2 steps we should postpone putting
* it into the set because it may have different hash after
* initialization compared to clean just created one. And set of
* course does not observe value hashCode changes.
*/
sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
} else {
set.add(key);
}
}
}
示例3: constructSet2ndStep
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的package包/类
protected void constructSet2ndStep(final MappingNode node, final Set<Object> set) {
List<NodeTuple> nodeValue = node.getValue();
for (NodeTuple tuple : nodeValue) {
Node keyNode = tuple.getKeyNode();
Object key = constructObject(keyNode);
if (key != null) {
try {
key.hashCode();// check circular dependencies
} catch (Exception e) {
throw new ConstructorException("while constructing a Set", node.getStartMark(), "found unacceptable key " + key, tuple
.getKeyNode().getStartMark(), e);
}
}
if (keyNode.isTwoStepsConstruction()) {
/*
* if keyObject is created it 2 steps we should postpone putting
* it into the set because it may have different hash after
* initialization compared to clean just created one. And set of
* course does not observe value hashCode changes.
*/
sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
} else {
set.add(key);
}
}
}
示例4: constructMapping2ndStep
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的package包/类
protected void constructMapping2ndStep(MappingNode node, Map<Object, Object> mapping) {
List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
for (NodeTuple tuple : nodeValue) {
Node keyNode = tuple.getKeyNode();
Node valueNode = tuple.getValueNode();
Object key = constructObject(keyNode);
if (key != null) {
try {
key.hashCode();// check circular dependencies
} catch (Exception e) {
throw new ConstructorException("while constructing a mapping",
node.getStartMark(), "found unacceptable key " + key, tuple
.getKeyNode().getStartMark(), e);
}
}
Object value = constructObject(valueNode);
if (keyNode.isTwoStepsConstruction()) {
/*
* if keyObject is created it 2 steps we should postpone putting
* it in map because it may have different hash after
* initialization compared to clean just created one. And map of
* course does not observe key hashCode changes.
*/
maps2fill.add(0,
new RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>>(
mapping, new RecursiveTuple<Object, Object>(key, value)));
} else {
mapping.put(key, value);
}
}
}
示例5: construct
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的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;
}
示例6: constructMapping2ndStep
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的package包/类
protected void constructMapping2ndStep(MappingNode node, Map<Object, Object> mapping) {
List<NodeTuple> nodeValue = node.getValue();
for (NodeTuple tuple : nodeValue) {
Node keyNode = tuple.getKeyNode();
Node valueNode = tuple.getValueNode();
Object key = constructObject(keyNode);
if (key != null) {
try {
key.hashCode();// check circular dependencies
} catch (Exception e) {
throw new ConstructorException("while constructing a mapping",
node.getStartMark(), "found unacceptable key " + key,
tuple.getKeyNode().getStartMark(), e);
}
}
Object value = constructObject(valueNode);
if (keyNode.isTwoStepsConstruction()) {
/*
* if keyObject is created it 2 steps we should postpone putting
* it in map because it may have different hash after
* initialization compared to clean just created one. And map of
* course does not observe key hashCode changes.
*/
maps2fill.add(0,
new RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>>(
mapping, new RecursiveTuple<Object, Object>(key, value)));
} else {
mapping.put(key, value);
}
}
}
示例7: processDuplicateKeys
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的package包/类
protected void processDuplicateKeys(MappingNode node) {
List<NodeTuple> nodeValue = node.getValue();
Map<Object, Integer> keys = new HashMap<Object, Integer>(nodeValue.size());
Deque<Integer> toRemove = new ArrayDeque<Integer>();
int i = 0;
for (NodeTuple tuple : nodeValue) {
Node keyNode = tuple.getKeyNode();
if (!keyNode.getTag().equals(Tag.MERGE)) {
Object key = constructObject(keyNode);
if (key != null) {
try {
key.hashCode();// check circular dependencies
} catch (Exception e) {
throw new ConstructorException("while constructing a mapping",
node.getStartMark(), "found unacceptable key " + key,
tuple.getKeyNode().getStartMark(), e);
}
}
Integer prevIndex = keys.put(key, i);
if (prevIndex != null) {
if (!isAllowDuplicateKeys()) {
throw new IllegalStateException("duplicate key: " + key);
}
toRemove.add(prevIndex);
}
}
i = i + 1;
}
Iterator<Integer> indicies2remove = toRemove.descendingIterator();
while (indicies2remove.hasNext()) {
nodeValue.remove(indicies2remove.next().intValue());
}
}
示例8: construct
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的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;
}
示例9: constructMapping
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的package包/类
@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
try {
return super.constructMapping(node);
}
catch (IllegalStateException ex) {
throw new ParserException("while parsing MappingNode",
node.getStartMark(), ex.getMessage(), node.getEndMark());
}
}
示例10: constructMapping2ndStep
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的package包/类
protected void constructMapping2ndStep(final MappingNode node, final Map<Object, Object> mapping) {
List<NodeTuple> nodeValue = node.getValue();
for (NodeTuple tuple : nodeValue) {
Node keyNode = tuple.getKeyNode();
Node valueNode = tuple.getValueNode();
Object key = constructObject(keyNode);
if (key != null) {
try {
key.hashCode();// check circular dependencies
} catch (Exception e) {
throw new ConstructorException("while constructing a mapping", node.getStartMark(), "found unacceptable key " + key,
tuple.getKeyNode().getStartMark(), e);
}
}
Object value = constructObject(valueNode);
if (keyNode.isTwoStepsConstruction()) {
/*
* if keyObject is created it 2 steps we should postpone putting
* it in map because it may have different hash after
* initialization compared to clean just created one. And map of
* course does not observe key hashCode changes.
*/
maps2fill.add(0, new RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>>(mapping,
new RecursiveTuple<Object, Object>(key, value)));
} else {
mapping.put(key, value);
}
}
}
示例11: construct
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的package包/类
@Override
public Object construct(final 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;
}
示例12: mergeNode
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的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;
}
示例13: mergeNode
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的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;
}
示例14: mergeNode
import org.yaml.snakeyaml.nodes.MappingNode; //导入方法依赖的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(final MappingNode node, final boolean isPreffered, final Map<Object, Integer> key2index,
final 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;
}