本文整理匯總了Java中org.yaml.snakeyaml.nodes.Node類的典型用法代碼示例。如果您正苦於以下問題:Java Node類的具體用法?Java Node怎麽用?Java Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Node類屬於org.yaml.snakeyaml.nodes包,在下文中一共展示了Node類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addSerializer
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
public static final <T> void addSerializer(ExtensibleRepresenter representer, Class<T> type,
Function<T, String> function) {
representer.addRepresenter(type, new Represent() {
@SuppressWarnings("unchecked")
@Override
public Node representData(Object data) {
String txt = function.apply((T) data);
if (txt == null) {
return new ScalarNode(Tag.NULL, "null", null, null, null);
}
return new ScalarNode(Tag.STR, txt, null, null, null);
}
});
}
示例2: representSequence
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
protected Node representSequence(Tag tag, Iterable<?> sequence, Boolean flowStyle) {
int size = 10;// default for ArrayList
if (sequence instanceof List<?>) {
size = ((List<?>) sequence).size();
}
List<Node> value = new ArrayList<Node>(size);
SequenceNode node = new SequenceNode(tag, value, flowStyle);
representedObjects.put(objectToRepresent, node);
boolean bestStyle = true;
for (Object item : sequence) {
Node nodeItem = representData(item);
if (!(nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null)) {
bestStyle = false;
}
value.add(nodeItem);
}
if (flowStyle == null) {
if (defaultFlowStyle != FlowStyle.AUTO) {
node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
} else {
node.setFlowStyle(bestStyle);
}
}
return node;
}
示例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: construct
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@Override
public Object construct( Node node )
{
if ( node.isTwoStepsConstruction() ) {
throw new YAMLException( "Unexpected referential mapping structure. Node: " + node );
}
Map<?, ?> raw = (Map<?, ?>) super.construct( node );
if ( raw.containsKey( ConfigurationSerialization.SERIALIZED_TYPE_KEY ) ) {
Map<String, Object> typed = new LinkedHashMap<String, Object>( raw.size() );
for ( Map.Entry<?, ?> entry : raw.entrySet() ) {
typed.put( entry.getKey().toString(), entry.getValue() );
}
try {
return ConfigurationSerialization.deserializeObject( typed );
} catch ( IllegalArgumentException ex ) {
throw new YAMLException( "Could not deserialize object", ex );
}
}
return raw;
}
示例5: construct2ndStep
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void construct2ndStep(Node node, Object object)
{
if (Map.class.isAssignableFrom(node.getType()))
{
this.yamlConstructor.constructMapping2ndStep((MappingNode) node, (Map<Object, Object>) object);
}
else if (Set.class.isAssignableFrom(node.getType()))
{
this.yamlConstructor.constructSet2ndStep((MappingNode) node, (Set<Object>) object);
}
else
{
this.constructJavaBean2ndStep((MappingNode) node, object);
}
}
示例6: representMapping
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
protected Node representMapping(Tag tag, Map<?, ?> mapping, Boolean flowStyle) {
List<NodeTuple> value = new ArrayList<NodeTuple>(mapping.size());
MappingNode node = new MappingNode(tag, value, flowStyle);
representedObjects.put(objectToRepresent, node);
boolean bestStyle = true;
for (Map.Entry<?, ?> entry : mapping.entrySet()) {
Node nodeKey = representData(entry.getKey());
Node nodeValue = representData(entry.getValue());
if (!(nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null)) {
bestStyle = false;
}
if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
bestStyle = false;
}
value.add(new NodeTuple(nodeKey, nodeValue));
}
if (flowStyle == null) {
if (defaultFlowStyle != FlowStyle.AUTO) {
node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
} else {
node.setFlowStyle(bestStyle);
}
}
return node;
}
示例7: getNode
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@Nullable
private Node getNode(MappingNode node, String key, boolean remove)
{
for (Iterator<NodeTuple> iterator = node.getValue().iterator(); iterator.hasNext(); )
{
NodeTuple tuple = iterator.next();
Node keyNode = tuple.getKeyNode();
if (! (keyNode instanceof ScalarNode))
{
return null;
}
if (key.equals(((ScalarNode) keyNode).getValue()))
{
if (remove)
{
iterator.remove();
}
return tuple.getValueNode();
}
}
return null;
}
示例8: 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;
}
示例9: getClassForNode
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
protected Class<?> getClassForNode(Node node) {
Class<? extends Object> classForTag = typeTags.get(node.getTag());
if (classForTag == null) {
String name = node.getTag().getClassName();
Class<?> cl;
try {
cl = getClassForName(name);
} catch (ClassNotFoundException e) {
throw new YAMLException("Class not found: " + name);
}
typeTags.put(node.getTag(), cl);
return cl;
} else {
return classForTag;
}
}
示例10: construct
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
public Object construct(Node node) {
ScalarNode scalar = (ScalarNode) node;
try {
return nf.parse(scalar.getValue());
} catch (ParseException e) {
String lowerCaseValue = scalar.getValue().toLowerCase();
if (lowerCaseValue.contains("inf") || lowerCaseValue.contains("nan")) {
/*
* Non-finites such as (+/-)infinity and NaN are not
* parseable by NumberFormat when these `Double` values are
* dumped by snakeyaml. Delegate to the `Tag.FLOAT`
* constructor when for this expected failure cause.
*/
return (Number) yamlConstructors.get(Tag.FLOAT).construct(node);
} else {
throw new IllegalArgumentException("Unable to parse as Number: "
+ scalar.getValue());
}
}
}
示例11: serialize
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
public void serialize(Node node) throws IOException {
if (closed == null) {
throw new SerializerException("serializer is not opened");
} else if (closed) {
throw new SerializerException("serializer is closed");
}
this.emitter.emit(new DocumentStartEvent(null, null, this.explicitStart, this.useVersion,
useTags));
anchorNode(node);
if (explicitRoot != null) {
node.setTag(explicitRoot);
}
serializeNode(node, null);
this.emitter.emit(new DocumentEndEvent(null, null, this.explicitEnd));
this.serializedNodes.clear();
this.anchors.clear();
}
示例12: construct2ndStep
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@Override
public void construct2ndStep(Node node, Object object) {
// Compact Object Notation may contain only one entry
MappingNode mnode = (MappingNode) node;
NodeTuple nodeTuple = mnode.getValue().iterator().next();
Node valueNode = nodeTuple.getValueNode();
if (valueNode instanceof MappingNode) {
valueNode.setType(object.getClass());
constructJavaBean2ndStep((MappingNode) valueNode, object);
} else {
// value is a list
applySequence(object, constructSequence((SequenceNode) valueNode));
}
}
示例13: nextAnchor
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
public String nextAnchor(Node node) {
this.lastAnchorId++;
NumberFormat format = NumberFormat.getNumberInstance();
format.setMinimumIntegerDigits(3);
format.setMaximumFractionDigits(0);// issue 172
format.setGroupingUsed(false);
String anchorId = format.format(this.lastAnchorId);
return "id" + anchorId;
}
示例14: construct
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@Override
public List<OpenShiftCluster> construct(Node node) {
List<OpenShiftCluster> clusters = new ArrayList<>();
SequenceNode sequenceNode = (SequenceNode) node;
for (Node n : sequenceNode.getValue()) {
MappingNode mapNode = (MappingNode) n;
Map<Object, Object> valueMap = constructMapping(mapNode);
String id = (String) valueMap.get("id");
String apiUrl = (String) valueMap.get("apiUrl");
String consoleUrl = (String) valueMap.get("consoleUrl");
clusters.add(new OpenShiftCluster(id, apiUrl, consoleUrl));
}
return clusters;
}
示例15: getNode
import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
/**
* Reads and composes the next document.
*
* @return The root node of the document or <code>null</code> if no more
* documents are available.
*/
public Node getNode() {
// Get the root node of the next document.
if (!parser.checkEvent(Event.ID.StreamEnd)) {
return composeDocument();
} else {
return null;
}
}