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);
}
}
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());
}
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());
}
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());
}
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));
}
Aggregations