Skip to content

Commit

Permalink
MONDRIAN: Fix MONDRIAN-686, "Regression: JPivot output invalid - New …
Browse files Browse the repository at this point in the history
…Variance Percent column".

[git-p4: depot-paths = "//open/mondrian-release/3.1/": change = 13352]
  • Loading branch information
julianhyde committed Jan 25, 2010
1 parent 62a11dc commit da75342
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/main/mondrian/util/Format.java
Expand Up @@ -2371,22 +2371,6 @@ private String parseFormatString(
haveSeenNumber = true;
}

// Merge adjacent literal formats.
for (int i = 0; i < formatList.size(); ++i) {
if (i > 0
&& formatList.get(i) instanceof LiteralFormat
&& formatList.get(i - 1) instanceof LiteralFormat)
{
formatList.set(
i - 1,
new LiteralFormat(
((LiteralFormat) formatList.get(i - 1)).s
+ ((LiteralFormat) formatList.get(i)).s));
formatList.remove(i);
--i;
}
}

// If they used some symbol like 'AM/PM' in the format string, tell all
// date formats to use twelve hour clock. Likewise, figure out the
// multiplier implied by their use of "%" or ",".
Expand Down Expand Up @@ -2452,6 +2436,26 @@ private String parseFormatString(
}
}

// Merge adjacent literal formats.
//
// Must do this AFTER adjusting for percent. Otherwise '%' and following
// '|' might be merged into a plain literal, and '%' would lose its
// special powers.
for (int i = 0; i < formatList.size(); ++i) {
if (i > 0
&& formatList.get(i) instanceof LiteralFormat
&& formatList.get(i - 1) instanceof LiteralFormat)
{
formatList.set(
i - 1,
new LiteralFormat(
((LiteralFormat) formatList.get(i - 1)).s
+ ((LiteralFormat) formatList.get(i)).s));
formatList.remove(i);
--i;
}
}

// Create a CompoundFormat containing all of the format elements.
// This is the end of an alternate - or of the whole format string.
// Push the current list of formats onto the list of alternates.
Expand Down
23 changes: 23 additions & 0 deletions testsrc/main/mondrian/util/FormatTest.java
Expand Up @@ -330,6 +330,29 @@ public void testNegativeZero() {
checkFormat(null, new BigDecimal("-0.0"), "#0.0", "0.0");
}

/**
* Test case for bug <a href="http://jira.pentaho.com/browse/MONDRIAN-686">
* MONDRIAN-686</a>, "Regression: JPivot output invalid - New Variance
* Percent column".
*/
public void testNegativePercentWithStyle() {
checkFormat(
null,
new BigDecimal("0.0364"),
"|#.00%|style='green'",
"|3.64%|style='green'");
checkFormat(
null,
new BigDecimal("-0.0364"),
"|#.00%|style='red'",
"-|3.64%|style='red'"); // confirmed on SSAS 2005
}

public void testNegativePercent() {
checkFormat(null, new BigDecimal("-0.0364"), "#.00%", "-3.64%");
checkFormat(null, new BigDecimal("0.0364"), "#.00%", "3.64%");
}

public void testNumberRoundingBug() {
checkFormat(null, new BigDecimal("0.50"), "0", "1");
checkFormat(null, new BigDecimal("-1.5"), "0", "-2");
Expand Down

0 comments on commit da75342

Please sign in to comment.