当前位置: 首页>>代码示例>>Java>>正文


Java Tag类代码示例

本文整理汇总了Java中org.yaml.snakeyaml.nodes.Tag的典型用法代码示例。如果您正苦于以下问题:Java Tag类的具体用法?Java Tag怎么用?Java Tag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Tag类属于org.yaml.snakeyaml.nodes包,在下文中一共展示了Tag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addSerializer

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的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);
		}

	});
}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:17,代码来源:YamlSnakeYaml.java

示例2: representData

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
public Node representData(Object data) {
    Tag tag;
    String value;
    if (data instanceof Byte || data instanceof Short || data instanceof Integer
            || data instanceof Long || data instanceof BigInteger) {
        tag = Tag.INT;
        value = data.toString();
    } else {
        Number number = (Number) data;
        tag = Tag.FLOAT;
        if (number.equals(Double.NaN)) {
            value = ".NaN";
        } else if (number.equals(Double.POSITIVE_INFINITY)) {
            value = ".inf";
        } else if (number.equals(Double.NEGATIVE_INFINITY)) {
            value = "-.inf";
        } else {
            value = number.toString();
        }
    }
    return representScalar(getTag(data.getClass(), tag), value);
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:23,代码来源:SafeRepresenter.java

示例3: representSequence

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的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;
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:26,代码来源:BaseRepresenter.java

示例4: representMapping

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的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;
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:26,代码来源:BaseRepresenter.java

示例5: addImplicitResolvers

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
protected void addImplicitResolvers() {
    addImplicitResolver(Tag.BOOL, BOOL, "yYnNtTfFoO");
    /*
     * INT must be before FLOAT because the regular expression for FLOAT
     * matches INT (see issue 130)
     * http://code.google.com/p/snakeyaml/issues/detail?id=130
     */
    addImplicitResolver(Tag.INT, INT, "-+0123456789");
    addImplicitResolver(Tag.FLOAT, FLOAT, "-+0123456789.");
    addImplicitResolver(Tag.MERGE, MERGE, "<");
    addImplicitResolver(Tag.NULL, NULL, "~nN\0");
    addImplicitResolver(Tag.NULL, EMPTY, null);
    addImplicitResolver(Tag.TIMESTAMP, TIMESTAMP, "0123456789");
    // The following implicit resolver is only for documentation
    // purposes.
    // It cannot work
    // because plain scalars cannot start with '!', '&', or '*'.
    addImplicitResolver(Tag.YAML, YAML, "!&*");
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:20,代码来源:Resolver.java

示例6: SafeConstructor

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
public SafeConstructor() {
    this.yamlConstructors.put(Tag.NULL, new ConstructYamlNull());
    this.yamlConstructors.put(Tag.BOOL, new ConstructYamlBool());
    this.yamlConstructors.put(Tag.INT, new ConstructYamlInt());
    this.yamlConstructors.put(Tag.FLOAT, new ConstructYamlFloat());
    this.yamlConstructors.put(Tag.BINARY, new ConstructYamlBinary());
    this.yamlConstructors.put(Tag.TIMESTAMP, new ConstructYamlTimestamp());
    this.yamlConstructors.put(Tag.OMAP, new ConstructYamlOmap());
    this.yamlConstructors.put(Tag.PAIRS, new ConstructYamlPairs());
    this.yamlConstructors.put(Tag.SET, new ConstructYamlSet());
    this.yamlConstructors.put(Tag.STR, new ConstructYamlStr());
    this.yamlConstructors.put(Tag.SEQ, new ConstructYamlSeq());
    this.yamlConstructors.put(Tag.MAP, new ConstructYamlMap());
    this.yamlConstructors.put(null, undefinedConstructor);
    this.yamlClassConstructors.put(NodeId.scalar, undefinedConstructor);
    this.yamlClassConstructors.put(NodeId.sequence, undefinedConstructor);
    this.yamlClassConstructors.put(NodeId.mapping, undefinedConstructor);
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:19,代码来源:SafeConstructor.java

示例7: newYaml

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
public static Yaml newYaml() {
  PropertyUtils propertyUtils = new AdvancedPropertyUtils();
  propertyUtils.setSkipMissingProperties(true);

  Constructor constructor = new Constructor(Federations.class);
  TypeDescription federationDescription = new TypeDescription(Federations.class);
  federationDescription.putListPropertyType("federatedMetaStores", FederatedMetaStore.class);
  constructor.addTypeDescription(federationDescription);
  constructor.setPropertyUtils(propertyUtils);

  Representer representer = new AdvancedRepresenter();
  representer.setPropertyUtils(new FieldOrderPropertyUtils());
  representer.addClassTag(Federations.class, Tag.MAP);
  representer.addClassTag(AbstractMetaStore.class, Tag.MAP);
  representer.addClassTag(WaggleDanceConfiguration.class, Tag.MAP);
  representer.addClassTag(YamlStorageConfiguration.class, Tag.MAP);
  representer.addClassTag(GraphiteConfiguration.class, Tag.MAP);

  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setIndent(2);
  dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);

  return new Yaml(constructor, representer, dumperOptions);
}
 
开发者ID:HotelsDotCom,项目名称:waggle-dance,代码行数:25,代码来源:YamlFactory.java

示例8: representJavaBeanProperty

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
/**
 * Overrides the {@link
 * Representer#representJavaBeanProperty(Object, Property, Object,
 * Tag)} method to return {@code null} when the given property
 * value can be omitted from its YAML representation without loss
 * of information.
 *
 * @param bean the Java bean whose property value is being
 * represented; may be {@code null}
 *
 * @param property the {@link Property} whose value is being
 * represented; may be {@code null}
 *
 * @param value the value being represented; may be {@code null}
 *
 * @param tag the {@link Tag} in effect; may be {@code null}
 *
 * @return {@code null} or the result of invoking the {@link
 * Representer#representJavaBeanProperty(Object, Property, Object,
 * Tag)} method with the supplied values
 */
@Override
protected final NodeTuple representJavaBeanProperty(final Object bean, final Property property, final Object value, final Tag tag) {
  final NodeTuple returnValue;
  if (value == null || value.equals(Boolean.FALSE)) {
    returnValue = null;
  } else if (value instanceof CharSequence) {
    if (((CharSequence)value).length() <= 0) {
      returnValue = null;
    } else {
      returnValue = super.representJavaBeanProperty(bean, property, value, tag);
    }
  } else if (value instanceof Collection) {
    if (((Collection<?>)value).isEmpty()) {
      returnValue = null;
    } else {
      returnValue = super.representJavaBeanProperty(bean, property, value, tag);
    }
  } else if (value instanceof Map) {
    if (((Map<?, ?>)value).isEmpty()) {
      returnValue = null;
    } else {
      returnValue = super.representJavaBeanProperty(bean, property, value, tag);
    }
  } else if (value.getClass().isArray()) {
    if (Array.getLength(value) <= 0) {
      returnValue = null;
    } else {
      returnValue = super.representJavaBeanProperty(bean, property, value, tag);
    }
  } else {
    returnValue = super.representJavaBeanProperty(bean, property, value, tag);
  }
  return returnValue;
}
 
开发者ID:microbean,项目名称:microbean-helm,代码行数:56,代码来源:AbstractChartWriter.java

示例9: dumpAll

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
private void dumpAll(Iterator<?> data, Writer output, @Nullable Tag rootTag)
{
    Serializer serializer =
            new Serializer(this.serialization, new Emitter(this.serialization, output, this.dumperOptions), this.resolver, this.dumperOptions, rootTag);
    try
    {
        serializer.open();
        while (data.hasNext())
        {
            Object next = data.next();
            ClassLoader old = Thread.currentThread().getContextClassLoader();
            if ((old == null) && (next != null))
            {
                Thread.currentThread().setContextClassLoader(next.getClass().getClassLoader());
            }
            try
            {
                Node node = this.representer.represent(next);
                serializer.serialize(node);
            }
            finally
            {
                if (old == null)
                {
                    Thread.currentThread().setContextClassLoader(null);
                }
            }
        }
        serializer.close();
    }
    catch (IOException e)
    {
        throw new YAMLException(e);
    }
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:36,代码来源:Yaml.java

示例10: representNumber

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
public final Node representNumber(Number data)
{
    Tag tag;
    String value;
    if ((data instanceof Byte) || (data instanceof Short) || (data instanceof Integer) || (data instanceof Long) || (data instanceof BigInteger))
    {
        tag = Tag.INT;
        value = data.toString();
    }
    else
    {
        tag = Tag.FLOAT;
        if (data.equals(Double.NaN))
        {
            value = ".NaN";
        }
        else if (data.equals(Double.POSITIVE_INFINITY))
        {
            value = ".inf";
        }
        else if (data.equals(Double.NEGATIVE_INFINITY))
        {
            value = "-.inf";
        }
        else
        {
            value = data.toString();
        }
    }
    return this.representer.representScalar(this.representer.getTag(data.getClass(), tag), value);
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:32,代码来源:AbstractRepresent.java

示例11: representJavaBean

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
/**
 * Tag logic:<br/>
 * - explicit root tag is set in serializer <br/>
 * - if there is a predefined class tag it is used<br/>
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,2002:map)
 * when the property class is the same as runtime class
 * 
 * @param properties
 *            JavaBean getters
 * @param javaBean
 *            instance for Node
 * @return Node to get serialized
 */
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(properties.size());
    Tag tag;
    Tag customTag = classTags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag(javaBean.getClass());
    // flow style will be chosen by BaseRepresenter
    MappingNode node = new MappingNode(tag, value, null);
    representedObjects.put(javaBean, node);
    boolean bestStyle = true;
    for (Property property : properties) {
        Object memberValue = property.get(javaBean);
        Tag customPropertyTag = memberValue == null ? null : classTags.get(memberValue
                .getClass());
        NodeTuple tuple = representJavaBeanProperty(javaBean, property, memberValue,
                customPropertyTag);
        if (tuple == null) {
            continue;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:49,代码来源:Representer.java

示例12: representJavaBeanProperty

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
/**
 * Represent one JavaBean property.
 * 
 * @param javaBean
 *            - the instance to be represented
 * @param property
 *            - the property of the instance
 * @param propertyValue
 *            - value to be represented
 * @param customTag
 *            - user defined Tag
 * @return NodeTuple to be used in a MappingNode. Return null to skip the
 *         property
 */
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
        Object propertyValue, Tag customTag) {
    ScalarNode nodeKey = (ScalarNode) representData(property.getName());
    // the first occurrence of the node must keep the tag
    boolean hasAlias = this.representedObjects.containsKey(propertyValue);

    Node nodeValue = representData(propertyValue);

    if (propertyValue != null && !hasAlias) {
        NodeId nodeId = nodeValue.getNodeId();
        if (customTag == null) {
            if (nodeId == NodeId.scalar) {
                if (propertyValue instanceof Enum<?>) {
                    nodeValue.setTag(Tag.STR);
                }
            } else {
                if (nodeId == NodeId.mapping) {
                    if (property.getType() == propertyValue.getClass()) {
                        if (!(propertyValue instanceof Map<?, ?>)) {
                            if (!nodeValue.getTag().equals(Tag.SET)) {
                                nodeValue.setTag(Tag.MAP);
                            }
                        }
                    }
                }
                checkGlobalTag(property, nodeValue, propertyValue);
            }
        }
    }

    return new NodeTuple(nodeKey, nodeValue);
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:47,代码来源:Representer.java

示例13: resetTag

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
private void resetTag(Class<? extends Object> type, Node node) {
    Tag tag = node.getTag();
    if (tag.matches(type)) {
        if (Enum.class.isAssignableFrom(type)) {
            node.setTag(Tag.STR);
        } else {
            node.setTag(Tag.MAP);
        }
    }
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:11,代码来源:Representer.java

示例14: representScalar

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
protected Node representScalar(Tag tag, String value, Character style) {
    if (style == null) {
        style = this.defaultScalarStyle;
    }
    Node node = new ScalarNode(tag, value, null, null, style);
    return node;
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:8,代码来源:BaseRepresenter.java

示例15: composeMappingChildren

import org.yaml.snakeyaml.nodes.Tag; //导入依赖的package包/类
protected void composeMappingChildren(List<NodeTuple> children, MappingNode node) {
    Node itemKey = composeKeyNode(node);
    if (itemKey.getTag().equals(Tag.MERGE)) {
        node.setMerged(true);
    }
    Node itemValue = composeValueNode(node);
    children.add(new NodeTuple(itemKey, itemValue));
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:9,代码来源:Composer.java


注:本文中的org.yaml.snakeyaml.nodes.Tag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。