當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。