本文整理匯總了Java中org.yaml.snakeyaml.nodes.Node.setType方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.setType方法的具體用法?Java Node.setType怎麽用?Java Node.setType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.yaml.snakeyaml.nodes.Node
的用法示例。
在下文中一共展示了Node.setType方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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));
}
}
示例2: getConstructor
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
private Construct getConstructor(Node node) {
Class<?> cl = getClassForNode(node);
node.setType(cl);
// call the constructor as if the runtime class is defined
Construct constructor = yamlClassConstructors.get(node.getNodeId());
return constructor;
}
示例3: toYamlNode
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
/**
* Serialize a Java object into a YAML Node.
*
* @param data
* Java object to be Serialized to YAML
*
* @return YAML Node
*/
public Node toYamlNode(@Nullable Object data)
{
Node represent = this.yaml().represent(data);
if (data != null)
{
if (! (data instanceof Map) && ! (data instanceof Collection))
{
represent.setType(data.getClass());
represent.setTag(new Tag(data.getClass()));
}
}
return represent;
}
示例4: constructArrayStep2
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
protected Object constructArrayStep2(SequenceNode node, Object array) {
final Class<?> componentType = node.getType().getComponentType();
int index = 0;
for (Node child : node.getValue()) {
// Handle multi-dimensional arrays...
if (child.getType() == Object.class) {
child.setType(componentType);
}
final Object value = constructObject(child);
if (componentType.isPrimitive()) {
// Null values are disallowed for primitives
if (value == null) {
throw new NullPointerException("Unable to construct element value for " + child);
}
// Primitive arrays require quite a lot of work.
if (byte.class.equals(componentType)) {
Array.setByte(array, index, ((Number) value).byteValue());
} else if (short.class.equals(componentType)) {
Array.setShort(array, index, ((Number) value).shortValue());
} else if (int.class.equals(componentType)) {
Array.setInt(array, index, ((Number) value).intValue());
} else if (long.class.equals(componentType)) {
Array.setLong(array, index, ((Number) value).longValue());
} else if (float.class.equals(componentType)) {
Array.setFloat(array, index, ((Number) value).floatValue());
} else if (double.class.equals(componentType)) {
Array.setDouble(array, index, ((Number) value).doubleValue());
} else if (char.class.equals(componentType)) {
Array.setChar(array, index, ((Character) value).charValue());
} else if (boolean.class.equals(componentType)) {
Array.setBoolean(array, index, ((Boolean) value).booleanValue());
} else {
throw new YAMLException("unexpected primitive type");
}
} else {
// Non-primitive arrays can simply be assigned:
Array.set(array, index, value);
}
++index;
}
return array;
}
示例5: constructArrayStep2
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
protected Object constructArrayStep2(SequenceNode node, Object array) {
final Class<?> componentType = node.getType().getComponentType();
int index = 0;
for (Node child : node.getValue()) {
// Handle multi-dimensional arrays...
if (child.getType() == Object.class) {
child.setType(componentType);
}
final Object value = constructObject(child);
if (componentType.isPrimitive()) {
// Null values are disallowed for primitives
if (value == null) {
throw new NullPointerException(
"Unable to construct element value for " + child);
}
// Primitive arrays require quite a lot of work.
if (byte.class.equals(componentType)) {
Array.setByte(array, index, ((Number) value).byteValue());
} else if (short.class.equals(componentType)) {
Array.setShort(array, index, ((Number) value).shortValue());
} else if (int.class.equals(componentType)) {
Array.setInt(array, index, ((Number) value).intValue());
} else if (long.class.equals(componentType)) {
Array.setLong(array, index, ((Number) value).longValue());
} else if (float.class.equals(componentType)) {
Array.setFloat(array, index, ((Number) value).floatValue());
} else if (double.class.equals(componentType)) {
Array.setDouble(array, index, ((Number) value).doubleValue());
} else if (char.class.equals(componentType)) {
Array.setChar(array, index, ((Character) value).charValue());
} else if (boolean.class.equals(componentType)) {
Array.setBoolean(array, index, ((Boolean) value).booleanValue());
} else {
throw new YAMLException("unexpected primitive type");
}
} else {
// Non-primitive arrays can simply be assigned:
Array.set(array, index, value);
}
++index;
}
return array;
}
示例6: fromYamlNode
import org.yaml.snakeyaml.nodes.Node; //導入方法依賴的package包/類
/**
* Construct object from given node.
*
* @param node
* node to load.
* @param type
* type of node.
* @param <T>
* type of node.
*
* @return loaded object.
*/
@SuppressWarnings("unchecked")
@Nullable
public <T> T fromYamlNode(Node node, Class<T> type)
{
node.setTag(new Tag(type));
node.setType(type);
return (T) this.constructor.constructFromNode(node);
}