Search in sources :

Example 1 with FormattedNumber

use of org.freeplane.features.format.FormattedNumber in project freeplane by freeplane.

the class CompareConditionAdapter method compareToData.

private int compareToData(final Object transformedContent) {
    if (conditionValue instanceof FormattedNumber && transformedContent instanceof Number) {
        return -((FormattedNumber) conditionValue).compareTo((Number) transformedContent);
    }
    if (conditionValue instanceof Number && transformedContent instanceof String) {
        try {
            Number number = TextUtils.toNumber((String) transformedContent);
            if (conditionValue instanceof FormattedNumber) {
                return -((FormattedNumber) conditionValue).compareTo(number);
            }
            if (number instanceof Long)
                return compareTo((Long) number);
            if (number instanceof Double)
                return compareTo((Double) number);
        } catch (final NumberFormatException fne) {
        }
        ;
        error = true;
        return 0;
    }
    if (conditionValue instanceof FormattedDate) {
        if (transformedContent instanceof FormattedDate) {
            return compareTo((FormattedDate) transformedContent);
        }
        error = true;
        return 0;
    }
    final String valueAsString = conditionValue.toString();
    final String text = transformedContent.toString();
    if (isEqualityCondition()) {
        return stringMatchingStrategy.matches(valueAsString, text, false, matchCase) ? 0 : -1;
    } else {
        return matchCase ? text.compareTo(valueAsString) : text.compareToIgnoreCase(valueAsString);
    }
}
Also used : FormattedDate(org.freeplane.features.format.FormattedDate) FormattedNumber(org.freeplane.features.format.FormattedNumber) FormattedNumber(org.freeplane.features.format.FormattedNumber)

Example 2 with FormattedNumber

use of org.freeplane.features.format.FormattedNumber in project freeplane by freeplane.

the class FormattedNumberTest method testWithPattern.

@Test
public void testWithPattern() {
    double number = 1.123456;
    final FormattedNumber formattedNumber = new FormattedNumber(number, "#.##");
    assertEquals("wrong pattern", "#.##", formattedNumber.getPattern());
    assertEquals("wrong formatting", "1.12", formattedNumber.toString());
}
Also used : FormattedNumber(org.freeplane.features.format.FormattedNumber) Test(org.junit.Test)

Example 3 with FormattedNumber

use of org.freeplane.features.format.FormattedNumber in project freeplane by freeplane.

the class FormattedNumberTest method testDefaultPattern.

@Test
public void testDefaultPattern() {
    double number = 1.123456;
    final FormattedNumber formattedNumber = new FormattedNumber(number);
    assertEquals("wrong default pattern", "#0.####", formattedNumber.getPattern());
    // expect a rounded number
    assertEquals("wrong default formatting", "1.1235", formattedNumber.toString());
}
Also used : FormattedNumber(org.freeplane.features.format.FormattedNumber) Test(org.junit.Test)

Example 4 with FormattedNumber

use of org.freeplane.features.format.FormattedNumber in project freeplane by freeplane.

the class FormattedObjectTest method testNestedIFormattedObject.

@Test
public void testNestedIFormattedObject() {
    double number = 1.123456;
    final FormattedNumber formattedNumber = new FormattedNumber(number, "#.##");
    final FormattedObject formattedObject = new FormattedObject(formattedNumber, "x: %s");
    assertEquals("wrong pattern", "x: %s", formattedObject.getPattern());
    assertEquals("wrong formatting", "x: 1.12", formattedObject.toString());
}
Also used : FormattedObject(org.freeplane.features.format.FormattedObject) FormattedNumber(org.freeplane.features.format.FormattedNumber) Test(org.junit.Test)

Example 5 with FormattedNumber

use of org.freeplane.features.format.FormattedNumber in project freeplane by freeplane.

the class FormattedNumberTest method testSerialization.

@Test
public void testSerialization() {
    double number = 1.123456;
    final FormattedNumber formattedNumber = new FormattedNumber(number, "#.##");
    final String serialized = "1.123456|#.##";
    assertEquals(serialized, FormattedNumber.serialize(formattedNumber));
    assertEquals(formattedNumber, FormattedNumber.deserialize(serialized));
}
Also used : FormattedNumber(org.freeplane.features.format.FormattedNumber) Test(org.junit.Test)

Aggregations

FormattedNumber (org.freeplane.features.format.FormattedNumber)7 Test (org.junit.Test)6 Locale (java.util.Locale)1 FormattedDate (org.freeplane.features.format.FormattedDate)1 FormattedObject (org.freeplane.features.format.FormattedObject)1