Java Code Examples for org.yaml.snakeyaml.nodes.Tag#FLOAT

The following examples show how to use org.yaml.snakeyaml.nodes.Tag#FLOAT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SafeRepresenter.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: SafeRepresenter.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: ConfigurationAsCode.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
private Tag getTag(Scalar.Format format) {
    switch (format) {
        case NUMBER:
            return Tag.INT;
        case FLOATING:
            return Tag.FLOAT;
        case BOOLEAN:
            return Tag.BOOL;
        case STRING:
        case MULTILINESTRING:
        default:
            return Tag.STR;
    }
}
 
Example 4
Source File: AbstractRepresent.java    From Diorite with MIT License 5 votes vote down vote up
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);
}