From 3954093b03a8739f93e447782f86275dcf228aed Mon Sep 17 00:00:00 2001 From: Claes Rosell Date: Tue, 7 Nov 2023 21:17:24 +0100 Subject: [PATCH] Add DENSE_RANK aggregate function (#1484) * Add DENSE_RANK aggregate function Initial implementation and unit tests. --- .../aggregation/api/IBuildInAggregation.java | 2 + .../data/aggregation/i18n/messages.properties | 4 +- .../impl/BuildInAggregationFactory.java | 5 + .../aggregation/impl/rank/BaseTotalRank.java | 235 ++++++++++ .../aggregation/impl/rank/TotalDenseRank.java | 54 +++ .../data/aggregation/impl/rank/TotalRank.java | 199 +-------- .../data/engine/aggregation/TotalTest.java | 402 ++++++++++-------- 7 files changed, 535 insertions(+), 366 deletions(-) create mode 100644 data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/BaseTotalRank.java create mode 100644 data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/TotalDenseRank.java diff --git a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/api/IBuildInAggregation.java b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/api/IBuildInAggregation.java index 7e2e521ca74..001b49692db 100644 --- a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/api/IBuildInAggregation.java +++ b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/api/IBuildInAggregation.java @@ -52,4 +52,6 @@ public interface IBuildInAggregation { String TOTAL_CONCATENATE_FUNC = "CONCATENATE";//$NON-NLS-1$ String TOTAL_RANGE_FUNC = "RANGE";//$NON-NLS-1$ + String TOTAL_DENSERANK_FUNC = "DENSERANK";//$NON-NLS-1$ + } diff --git a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/i18n/messages.properties b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/i18n/messages.properties index 90e12d1c0f5..580308c03bb 100644 --- a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/i18n/messages.properties +++ b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/i18n/messages.properties @@ -26,6 +26,8 @@ TotalCount.description=function Total.COUNT() TotalCount.displayName=COUNT TotalCountDistinct.description=function Total.COUNTDISTINCT() TotalCountDistinct.displayName=COUNTDISTINCT +TotalDenseRank.description=function Total.DENSERANK() +TotalDenseRank.displayName=DENSERANK TotalFirst.description=function Total.FIRST() TotalFirst.displayName=FIRST TotalIrr.description=function Total.IRR() @@ -91,7 +93,7 @@ TotalQuartile.param.quart=&Quart TotalRank.description=function Total.RANK() TotalRank.displayName=RANK TotalRank.param.ascending=&Ascending -TotalConcatenate.description=funtion Total.CONCATENATE() +TotalConcatenate.description=function Total.CONCATENATE() TotalConcatenate.displayName=CONCATENATE TotalConcatenate.param.separator=Separat&or TotalConcatenate.param.maxLength=Ma&x length diff --git a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/BuildInAggregationFactory.java b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/BuildInAggregationFactory.java index 9110d9d3f36..dd71b53c319 100644 --- a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/BuildInAggregationFactory.java +++ b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/BuildInAggregationFactory.java @@ -20,6 +20,7 @@ import java.util.Map; import org.eclipse.birt.data.aggregation.api.IBuildInAggregation; +import org.eclipse.birt.data.aggregation.impl.rank.TotalDenseRank; import org.eclipse.birt.data.aggregation.impl.rank.TotalIsBottomN; import org.eclipse.birt.data.aggregation.impl.rank.TotalIsBottomNPercent; import org.eclipse.birt.data.aggregation.impl.rank.TotalIsTopN; @@ -139,6 +140,10 @@ private void populateAggregations() { final TotalRange totalRange = new TotalRange(); aggrMap.put(IBuildInAggregation.TOTAL_RANGE_FUNC, totalRange); aggregations.add(totalRange); + + final TotalDenseRank totalDenseRank = new TotalDenseRank(); + aggrMap.put(IBuildInAggregation.TOTAL_DENSERANK_FUNC, totalDenseRank); + aggregations.add(totalDenseRank); } /** diff --git a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/BaseTotalRank.java b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/BaseTotalRank.java new file mode 100644 index 00000000000..55004de0e0a --- /dev/null +++ b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/BaseTotalRank.java @@ -0,0 +1,235 @@ +package org.eclipse.birt.data.aggregation.impl.rank; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import org.eclipse.birt.core.data.DataType; +import org.eclipse.birt.data.aggregation.i18n.Messages; +import org.eclipse.birt.data.aggregation.impl.AggrFunction; +import org.eclipse.birt.data.aggregation.impl.Constants; +import org.eclipse.birt.data.aggregation.impl.ParameterDefn; +import org.eclipse.birt.data.aggregation.impl.RunningAccumulator; +import org.eclipse.birt.data.aggregation.impl.SupportedDataTypes; +import org.eclipse.birt.data.engine.api.aggregation.IParameterDefn; +import org.eclipse.birt.data.engine.core.DataException; + +/** + * @since 3.3 + * + */ +abstract class BaseTotalRank extends AggrFunction { + + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.data.engine.aggregation.Aggregation#getType() + */ + @Override + public int getType() { + return RUNNING_AGGR; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.data.engine.api.aggregation.IAggregation#getDateType() + */ + @Override + public int getDataType() { + return DataType.INTEGER_TYPE; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.data.engine.aggregation.Aggregation#getParameterDefn() + */ + @Override + public IParameterDefn[] getParameterDefn() { + return new IParameterDefn[] { + new ParameterDefn(Constants.EXPRESSION_NAME, Constants.EXPRESSION_DISPLAY_NAME, false, true, + SupportedDataTypes.CALCULATABLE, ""), //$NON-NLS-1$ + new ParameterDefn("ascending", Messages.getString("TotalRank.param.ascending"), true, false, //$NON-NLS-1$ //$NON-NLS-2$ + SupportedDataTypes.ANY, "") //$NON-NLS-1$ + }; + } + + /* + * + */ + @Override + public int getNumberOfPasses() { + return 2; + } + + static class TotalRankAccumulator extends RunningAccumulator { + + private Integer sum; + private List cachedValues; + private Map rankMap; + private boolean asc; + private boolean denseRank; + private boolean hasInitialized; + private int passCount = 0; + private Comparator comparator; + + /** + * @param denseRank If the dense rank algorithm should be used or not + * + */ + public TotalRankAccumulator(boolean denseRank) { + this.denseRank = denseRank; + } + + @Override + public void start() { + if (passCount == 0) { + cachedValues = new ArrayList<>(); + rankMap = new HashMap<>(); + sum = 0; + asc = true; + comparator = RankObjComparator.INSTANCE; // Sorting for ascending. Can change later + hasInitialized = false; + } + passCount++; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.birt.data.engine.aggregation.Accumulator#onRow(java.lang.Object[] + * ) + */ + @Override + public void onRow(Object[] args) throws DataException { + assert (args.length > 0); + if (passCount == 1) { + if (args[0] != null) { + cachedValues.add(args[0]); + } else { + cachedValues.add(RankAggregationUtil.getNullObject()); + } + if ((!hasInitialized) && args[1] != null) { + // Here, the ascending/descending sort order can change from defaults depending + // on the second argument + hasInitialized = true; + if (args[1].toString().equals("false")) { //$NON-NLS-1$ + asc = false; + } else if (args[1] instanceof Double && ((Double) args[1]).equals(Double.valueOf(0))) { + asc = false; + } else { + asc = true; + } + + // Reverse the sorting if the sorting is not ascending + if (!this.asc) { + comparator = RankObjComparator.INSTANCE.reversed(); + } + } + } else { + Object compareValue; + if (args[0] != null) { + compareValue = args[0]; + } else { + compareValue = RankAggregationUtil.getNullObject(); + } + + Integer calculatedRank = this.rankMap.get(compareValue); + sum = calculatedRank != null ? calculatedRank.intValue() : -1; + } + } + + @Override + public void finish() throws DataException { + if (this.passCount == 1) { + Collections.sort(cachedValues, comparator); + calculateRank(cachedValues, this.denseRank); + } + } + + /** + * Precondition: The parameter objs should be sorted acsending + * previously. Note: rank is 1-based. ex. + * The following table give details: + * Value | Rank + * 20 | 4 + * 10 | 5 + * 30 | 2 + * 30 | 2 + * 40 | 1 + * + * + * @param key + * @return rank + */ + private void calculateRank(List sortedList, boolean useDenseRank) { + + int currentRank = 1; + int currentDenseRank = 1; + Object currentValue = sortedList.get(0); + + for (int i = 0; i < sortedList.size(); i++) { + Object integer = sortedList.get(i); + if (!Objects.equals(integer, currentValue)) { + + rankMap.put(currentValue, useDenseRank ? currentDenseRank : currentRank); + currentValue = integer; + currentDenseRank++; + currentRank = i + 1; + } + + } + + // Handle the last integer in the list + rankMap.put(currentValue, useDenseRank ? currentDenseRank : currentRank); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.data.engine.api.aggregation.Accumulator#getValue() + */ + @Override + public Object getValue() throws DataException { + return sum; + } + } + + /* + * + */ + static class RankObjComparator implements Comparator { + + public static RankObjComparator INSTANCE = new RankObjComparator(); + + private RankObjComparator() { + // No need + } + + @Override + public int compare(Object o1, Object o2) {// for efficiency, we assure o1 and o2 can be just Comparable or + // NullObject + if (o1 instanceof Comparable) { + if (o2 instanceof Comparable) {// Comparable ? Comparable + @SuppressWarnings("unchecked") + Comparable obj1 = (Comparable) o1; + @SuppressWarnings("unchecked") + Comparable obj2 = (Comparable) o2; + return obj1.compareTo(obj2); + } + return 1;// Comparable > NullObject + } else if (o2 instanceof Comparable) {// NullObject < Comparable + return -1; + } else {// NullObject == NullObject + return 0; + } + } + } +} diff --git a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/TotalDenseRank.java b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/TotalDenseRank.java new file mode 100644 index 00000000000..c16585b9a79 --- /dev/null +++ b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/TotalDenseRank.java @@ -0,0 +1,54 @@ +package org.eclipse.birt.data.aggregation.impl.rank; + +import org.eclipse.birt.data.aggregation.api.IBuildInAggregation; +import org.eclipse.birt.data.aggregation.i18n.Messages; +import org.eclipse.birt.data.engine.api.aggregation.Accumulator; + +/** + * @since 3.3 + * + */ +public class TotalDenseRank extends BaseTotalRank { + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.data.engine.aggregation.Aggregation#getName() + */ + @Override + public String getName() { + return IBuildInAggregation.TOTAL_DENSERANK_FUNC; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.data.engine.aggregation.Aggregation#newAccumulator() + */ + @Override + public Accumulator newAccumulator() { + return new TotalRankAccumulator(true); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.birt.data.engine.api.aggregation.IAggrFunction#getDescription() + */ + @Override + public String getDescription() { + return Messages.getString("TotalDenseRank.description"); //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.birt.data.engine.api.aggregation.IAggrFunction#getDisplayName() + */ + @Override + public String getDisplayName() { + return Messages.getString("TotalDenseRank.displayName"); //$NON-NLS-1$ + } +} diff --git a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/TotalRank.java b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/TotalRank.java index 047f2faf2c9..7b495919740 100644 --- a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/TotalRank.java +++ b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/rank/TotalRank.java @@ -17,27 +17,14 @@ package org.eclipse.birt.data.aggregation.impl.rank; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import org.eclipse.birt.core.data.DataType; import org.eclipse.birt.data.aggregation.api.IBuildInAggregation; import org.eclipse.birt.data.aggregation.i18n.Messages; -import org.eclipse.birt.data.aggregation.impl.AggrFunction; -import org.eclipse.birt.data.aggregation.impl.Constants; -import org.eclipse.birt.data.aggregation.impl.ParameterDefn; -import org.eclipse.birt.data.aggregation.impl.RunningAccumulator; -import org.eclipse.birt.data.aggregation.impl.SupportedDataTypes; import org.eclipse.birt.data.engine.api.aggregation.Accumulator; -import org.eclipse.birt.data.engine.api.aggregation.IParameterDefn; -import org.eclipse.birt.data.engine.core.DataException; /** * Implements the built-in Total.Rank aggregation. */ -public class TotalRank extends AggrFunction { +public class TotalRank extends BaseTotalRank { /* * (non-Javadoc) @@ -49,49 +36,6 @@ public String getName() { return IBuildInAggregation.TOTAL_RANK_FUNC; } - /* - * (non-Javadoc) - * - * @see org.eclipse.birt.data.engine.aggregation.Aggregation#getType() - */ - @Override - public int getType() { - return RUNNING_AGGR; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.birt.data.engine.api.aggregation.IAggregation#getDateType() - */ - @Override - public int getDataType() { - return DataType.INTEGER_TYPE; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.birt.data.engine.aggregation.Aggregation#getParameterDefn() - */ - @Override - public IParameterDefn[] getParameterDefn() { - return new IParameterDefn[] { - new ParameterDefn(Constants.EXPRESSION_NAME, Constants.EXPRESSION_DISPLAY_NAME, false, true, - SupportedDataTypes.CALCULATABLE, ""), //$NON-NLS-1$ - new ParameterDefn("ascending", Messages.getString("TotalRank.param.ascending"), true, false, //$NON-NLS-1$ //$NON-NLS-2$ - SupportedDataTypes.ANY, "") //$NON-NLS-1$ - }; - } - - /* - * - */ - @Override - public int getNumberOfPasses() { - return 2; - } - /* * (non-Javadoc) * @@ -99,146 +43,7 @@ public int getNumberOfPasses() { */ @Override public Accumulator newAccumulator() { - return new MyAccumulator(); - } - - private class MyAccumulator extends RunningAccumulator { - - private Integer sum; - private List cachedValues; - private boolean asc; - private boolean hasInitialized; - private int passCount = 0; - private RankObjComparator comparator; - - @Override - public void start() { - if (passCount == 0) { - cachedValues = new ArrayList(); - sum = 0; - asc = true; - hasInitialized = false; - comparator = new RankObjComparator(); - } - passCount++; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.birt.data.engine.aggregation.Accumulator#onRow(java.lang.Object[] - * ) - */ - @Override - public void onRow(Object[] args) throws DataException { - assert (args.length > 0); - if (passCount == 1) { - if (args[0] != null) { - cachedValues.add(args[0]); - } else { - cachedValues.add(RankAggregationUtil.getNullObject()); - } - if ((!hasInitialized) && args[1] != null) { - hasInitialized = true; - if (args[1].toString().equals("false")) { //$NON-NLS-1$ - asc = false; - } else if (args[1] instanceof Double && ((Double) args[1]).equals(new Double(0))) { - asc = false; - } else { - asc = true; - } - } - } else { - Object compareValue; - if (args[0] != null) { - compareValue = args[0]; - } else { - compareValue = RankAggregationUtil.getNullObject(); - } - sum = getRank(compareValue); - } - } - - @Override - public void finish() throws DataException { - if (this.passCount == 1) { - Collections.sort(cachedValues, comparator); - } - } - - /** - * Precondition: The parameter objs should be sorted acsending - * previously. Note: rank is 1-based. ex. - * The following table give details: - * Value | Rank - * 20 | 4 - * 10 | 5 - * 30 | 2 - * 30 | 2 - * 40 | 1 - * - * - * @param key - * @return rank - */ - private int getRank(Object key) { - // search the index of key in the cachedValues list using - // binary search algorithm - int index = Collections.binarySearch(cachedValues, key, comparator); - if (index < 0) {// not found, return default rank: -1 - return -1; - } - // Note:index is 0-based, but rank is 1-based - if (asc) {// caculate the rank in ascending order - for (int i = index - 1; i >= 0; i--) { - if (!cachedValues.get(i).equals(key)) { - return i + 2; - } - } - } else {// caculate the rank in descending order - for (int i = index + 1; i < cachedValues.size(); i++) { - if (!cachedValues.get(i).equals(key)) { - return cachedValues.size() - i + 1; - } - } - } - return 1; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.birt.data.engine.api.aggregation.Accumulator#getValue() - */ - @Override - public Object getValue() throws DataException { - return sum; - } - } - - /* - * - */ - static class RankObjComparator implements Comparator { - - @Override - public int compare(Object o1, Object o2) {// for efficiency, we assure o1 and o2 can be just Comparable or - // NullObject - if (o1 instanceof Comparable) { - if (o2 instanceof Comparable) {// Comparable ? Comparable - Comparable obj1 = (Comparable) o1; - Comparable obj2 = (Comparable) o2; - return obj1.compareTo(obj2); - } else {// Comparable > NullObject - return 1; - } - } else if (o2 instanceof Comparable) {// NullObject < Comparable - return -1; - } else {// NullObject == NullObject - return 0; - } - } + return new TotalRankAccumulator(false); } /* diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/aggregation/TotalTest.java b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/aggregation/TotalTest.java index 7dc83d81c4a..94909763899 100644 --- a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/aggregation/TotalTest.java +++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/aggregation/TotalTest.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.birt.data.engine.aggregation; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -45,15 +46,21 @@ public class TotalTest { private boolean[] doubleArray3TopBottom = { true, false, false, true, false, false, false, false }; private int[] doubleArray3RankDec = { 2, 4, 7, 1, 7, 3, 5, 5 }; private int[] doubleArray3RankAsc = { 7, 5, 1, 8, 1, 6, 3, 3 }; + + private int[] doubleArray3DenseRankDec = { 2, 4, 6, 1, 6, 3, 5, 5 }; + private int[] doubleArray3DenseRankAsc = { 5, 3, 1, 6, 1, 4, 2, 2 }; + private int[] doubleArray3PercentRank = { 857, 571, 0, 1000, 0, 714, 285, 285 }; - private Object[] doubleArray3PercentSum = { new Integer(208), new Integer(41), null, new Integer(625), null, - new Integer(83), new Integer(20), new Integer(20) }; + private Object[] doubleArray3PercentSum = { Integer.valueOf(208), Integer.valueOf(41), null, Integer.valueOf(625), + null, Integer.valueOf(83), Integer.valueOf(20), Integer.valueOf(20) }; private String[] str1 = { "4", "-43", "4", "23", "-15", "-6", "4", "-6", "3", "63", "33", "-6", "-23", "34" }; private double[] doubleArray4 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; private double[] doubleArray5 = { 1, 2, 2, 3, 1, 3, 4, 1, 2 }; private double[] doubleArray6 = { 1, 2, 2, 3, 1, 3, 4, 2, 1 }; - private Object[] anyObjectArray = { "aa", "bb", null, new Integer(0), null, new Double(1), new Float(0), null }; - private Object[] anyObjectArray2 = { "aa", "bb", null, new Integer(0), null, new Double(1), new Float(0), null, + private Object[] anyObjectArray = { "aa", "bb", null, Integer.valueOf(0), null, Double.valueOf(1), new Float(0), + null }; + private Object[] anyObjectArray2 = { "aa", "bb", null, Integer.valueOf(0), null, Double.valueOf(1), new Float(0), + null, false, new Date(1000000L) }; private Date[] dates = { new Date(1000000L), new Date(2000000L), new Date(3000000L), new Date(4000000L) }; @@ -72,7 +79,7 @@ public class TotalTest { new BigDecimal("6"), new BigDecimal("7") }; private int[] bigDecimalRankAsc = { 1, 2, 7, 4, 9, 13, 2, 4, 7, 11, 14, 15, 4, 9, 11 }; - + private int[] bigDecimalDenseRankAsc = { 1, 2, 4, 3, 5, 7, 2, 3, 4, 6, 8, 9, 3, 5, 6 }; private int[] bigDecimalPercentRank = { 0, 71, 428, 214, 571, 857, 71, 214, 428, 714, 928, 1000, 214, 571, 714 }; @@ -292,28 +299,28 @@ public void testTotalCount() throws Exception { ac.onRow(new Object[] { anyObjectArray[i] }); } ac.finish(); - assertEquals(new Integer(5), ac.getValue()); + assertEquals(Integer.valueOf(5), ac.getValue()); ac.start(); for (int i = 0; i < anyObjectArray.length; i++) { ac.onRow(null); } ac.finish(); - assertEquals(new Integer(8), ac.getValue()); + assertEquals(Integer.valueOf(8), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray1.length; i++) { ac.onRow(new Object[] {}); } ac.finish(); - assertEquals(new Integer(15), ac.getValue()); + assertEquals(Integer.valueOf(15), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { ac.onRow(new Object[] {}); } ac.finish(); - assertEquals(new Integer(14), ac.getValue()); + assertEquals(Integer.valueOf(14), ac.getValue()); ac.start(); @@ -321,11 +328,11 @@ public void testTotalCount() throws Exception { ac.onRow(new Object[] {}); } ac.finish(); - assertEquals(new Integer(14), ac.getValue()); + assertEquals(Integer.valueOf(14), ac.getValue()); ac.start(); ac.finish(); - assertEquals(new Integer(0), ac.getValue()); + assertEquals(Integer.valueOf(0), ac.getValue()); ac.start(); try { @@ -358,17 +365,17 @@ public void testTotalSum() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); - assertEquals(new Double(82.0), ac.getValue()); + assertEquals(Double.valueOf(82.0), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(69.0), ac.getValue()); + assertEquals(Double.valueOf(69.0), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { @@ -418,7 +425,7 @@ public void testTotalSum() throws Exception { // test Total.sum() for heterogeneous Number array data { Number numberArray[] = { BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN, Double.valueOf("0.1"), - new BigDecimal("0.1"), new BigDecimal(0.1D), new BigDecimal("0.1"), new Double(0.1D), }; + new BigDecimal("0.1"), new BigDecimal(0.1D), new BigDecimal("0.1"), Double.valueOf(0.1D), }; ac.start(); for (int i = 0; i < numberArray.length; i++) { ac.onRow(new Object[] { numberArray[i] }); @@ -493,9 +500,9 @@ public void testTotalRunningSum() throws Exception { double sum = 0D; ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); sum += doubleArray1[i]; - assertEquals(new Double(sum), ac.getValue()); + assertEquals(Double.valueOf(sum), ac.getValue()); } ac.finish(); } @@ -504,9 +511,9 @@ public void testTotalRunningSum() throws Exception { double sum = 0D; ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); sum += doubleArray2[i]; - assertEquals(new Double(sum), ac.getValue()); + assertEquals(Double.valueOf(sum), ac.getValue()); } ac.finish(); } @@ -560,24 +567,24 @@ public void testTotalAve() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); - assertEquals(new Double(5.466666666666667), ac.getValue()); + assertEquals(Double.valueOf(5.466666666666667), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(4.928571428571429), ac.getValue()); + assertEquals(Double.valueOf(4.928571428571429), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { ac.onRow(new Object[] { str1[i] }); } ac.finish(); - assertEquals(new Double(4.928571428571429), ac.getValue()); + assertEquals(Double.valueOf(4.928571428571429), ac.getValue()); ac.start(); ac.finish(); @@ -613,17 +620,17 @@ public void testTotalFirst() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); - assertEquals(new Double(1.0), ac.getValue()); + assertEquals(Double.valueOf(1.0), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(4), ac.getValue()); + assertEquals(Double.valueOf(4), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { @@ -666,17 +673,17 @@ public void testTotalLast() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); - assertEquals(new Double(7.0), ac.getValue()); + assertEquals(Double.valueOf(7.0), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(34.0), ac.getValue()); + assertEquals(Double.valueOf(34.0), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { @@ -718,17 +725,17 @@ public void testTotalMax() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); - assertEquals(new Double(10.0), ac.getValue()); + assertEquals(Double.valueOf(10.0), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(63.0), ac.getValue()); + assertEquals(Double.valueOf(63.0), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { @@ -770,17 +777,17 @@ public void testTotalMin() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); - assertEquals(new Double(1.0), ac.getValue()); + assertEquals(Double.valueOf(1.0), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(-43), ac.getValue()); + assertEquals(Double.valueOf(-43), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { @@ -823,17 +830,17 @@ public void testTotalRange() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); - assertEquals(new Double(9.0), ac.getValue()); + assertEquals(Double.valueOf(9.0), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(106), ac.getValue()); + assertEquals(Double.valueOf(106), ac.getValue()); // String data type returns 0 ac.start(); @@ -886,24 +893,24 @@ public void testTotalMedian() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); - assertEquals(new Double(5.0), ac.getValue()); + assertEquals(Double.valueOf(5.0), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(3.5), ac.getValue()); + assertEquals(Double.valueOf(3.5), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { ac.onRow(new Object[] { str1[i] }); } ac.finish(); - assertEquals(new Double(3.5D), ac.getValue()); + assertEquals(Double.valueOf(3.5D), ac.getValue()); ac.start(); ac.finish(); @@ -956,39 +963,39 @@ public void testTotalMode() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); - assertEquals(new Double(4.0), ac.getValue()); + assertEquals(Double.valueOf(4.0), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(4.0), ac.getValue()); + assertEquals(Double.valueOf(4.0), ac.getValue()); // double4: unique numbers ac.start(); for (int i = 0; i < doubleArray4.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray4[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray4[i]) }); } ac.finish(); assertEquals(null, ac.getValue()); // double 5: mutiple mode, return the first appeared mode ac.start(); for (int i = 0; i < doubleArray5.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray5[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray5[i]) }); } ac.finish(); - assertEquals(new Double(1.0), ac.getValue()); + assertEquals(Double.valueOf(1.0), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray6.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray6[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray6[i]) }); } ac.finish(); - assertEquals(new Double(1.0), ac.getValue()); + assertEquals(Double.valueOf(1.0), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { @@ -1010,11 +1017,11 @@ public void testTotalMode() throws Exception { } ac.start(); - ac.onRow(new Double[] { new Double(4) }); - ac.onRow(new Double[] { new Double(4) }); - ac.onRow(new Double[] { new Double(3) }); + ac.onRow(new Double[] { Double.valueOf(4) }); + ac.onRow(new Double[] { Double.valueOf(4) }); + ac.onRow(new Double[] { Double.valueOf(3) }); ac.finish(); - assertEquals(ac.getValue(), new Double(4)); + assertEquals(ac.getValue(), Double.valueOf(4)); // mode test for Date // 1: no mode date ac.start(); @@ -1053,17 +1060,17 @@ public void testTotalStdDev() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); assertEquals(2.445598573141631D, ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(26.560422510872147), ac.getValue()); + assertEquals(Double.valueOf(26.560422510872147), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { @@ -1107,17 +1114,17 @@ public void testTotalVariance() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]) }); } ac.finish(); assertEquals(5.980952380952381D, ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]) }); } ac.finish(); - assertEquals(new Double(705.4560439560439), ac.getValue()); + assertEquals(Double.valueOf(705.4560439560439), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { @@ -1161,52 +1168,52 @@ public void testTotalWeightedAva() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(weight[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(weight[i]) }); } ac.finish(); - assertEquals(new Double(5.343042071197409), ac.getValue()); + assertEquals(Double.valueOf(5.343042071197409), ac.getValue()); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray2[i]), new Double(weight[i]) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray2[i]), Double.valueOf(weight[i]) }); } ac.finish(); - assertEquals(new Double(3.236104279390063), ac.getValue()); + assertEquals(Double.valueOf(3.236104279390063), ac.getValue()); ac.start(); for (int i = 0; i < str1.length; i++) { - ac.onRow(new Object[] { str1[i], new Double(weight[i]) }); + ac.onRow(new Object[] { str1[i], Double.valueOf(weight[i]) }); } ac.finish(); assertEquals(3.236104279390063D, ac.getValue()); ac.start(); - ac.onRow(new Object[] { new Double(1), new Double(1) }); - ac.onRow(new Object[] { new Double(2), new Double(2) }); + ac.onRow(new Object[] { Double.valueOf(1), Double.valueOf(1) }); + ac.onRow(new Object[] { Double.valueOf(2), Double.valueOf(2) }); ac.finish(); - assertEquals(new Double(1.6666666666666667), ac.getValue()); + assertEquals(Double.valueOf(1.6666666666666667), ac.getValue()); ac.start(); - ac.onRow(new Object[] { null, new Double(3) }); - ac.onRow(new Object[] { new Double(2), new Double(2) }); - ac.onRow(new Object[] { new Double(2), null }); + ac.onRow(new Object[] { null, Double.valueOf(3) }); + ac.onRow(new Object[] { Double.valueOf(2), Double.valueOf(2) }); + ac.onRow(new Object[] { Double.valueOf(2), null }); ac.finish(); - assertEquals(new Double(2), ac.getValue()); + assertEquals(Double.valueOf(2), ac.getValue()); ac.start(); - ac.onRow(new Object[] { new Double(1), new Double(3) }); - ac.onRow(new Object[] { new Double(1), new Double(-3) }); + ac.onRow(new Object[] { Double.valueOf(1), Double.valueOf(3) }); + ac.onRow(new Object[] { Double.valueOf(1), Double.valueOf(-3) }); ac.finish(); assertEquals(Double.NaN, ac.getValue()); ac.start(); - ac.onRow(new Object[] { new Double(1), new Double(2) }); - ac.onRow(new Object[] { new Double(2), new Double(-4) }); + ac.onRow(new Object[] { Double.valueOf(1), Double.valueOf(2) }); + ac.onRow(new Object[] { Double.valueOf(2), Double.valueOf(-4) }); ac.finish(); - assertEquals(new Double(3.0), ac.getValue()); + assertEquals(Double.valueOf(3.0), ac.getValue()); ac.start(); ac.finish(); @@ -1223,7 +1230,7 @@ public void testTotalWeightedAva() throws Exception { // test Total.WeightedAve() for BigDecimal data ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(weight[i]) }); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(weight[i]) }); } ac.finish(); Object ret = ac.getValue(); @@ -1250,21 +1257,21 @@ public void testTotalMovingAve() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Object[] { new Double(doubleArray1[i]), new Integer(8) }); - assertEquals(new Double(values1[i]), ac.getValue()); + ac.onRow(new Object[] { Double.valueOf(doubleArray1[i]), Integer.valueOf(8) }); + assertEquals(Double.valueOf(values1[i]), ac.getValue()); } ac.finish(); ac.start(); for (int i = 0; i < doubleArray2.length; i++) { - ac.onRow(new Object[] { new Double(doubleArray2[i]), new Integer(6) }); + ac.onRow(new Object[] { Double.valueOf(doubleArray2[i]), Integer.valueOf(6) }); assertEquals(Double.valueOf(values2[i]), ac.getValue()); } ac.finish(); ac.start(); for (int i = 0; i < str1.length; i++) { - ac.onRow(new Object[] { str1[i], new Integer(6) }); + ac.onRow(new Object[] { str1[i], Integer.valueOf(6) }); assertEquals(Double.valueOf(values2[i]), ac.getValue()); } ac.finish(); @@ -1367,14 +1374,14 @@ public void testTotalTop() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(5) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(5) }); } ac.finish(); ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(5) }); - assertEquals(new Boolean(doubleArray1TopBottom[i]), ac.getValue()); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(5) }); + assertEquals(Boolean.valueOf(doubleArray1TopBottom[i]), ac.getValue()); } ac.finish(); @@ -1387,25 +1394,25 @@ public void testTotalTop() throws Exception { assertTrue(!ag.getParameterDefn()[1].isOptional()); ac.start(); - ac.onRow(new Double[] { new Double(6), new Double(5) }); + ac.onRow(new Double[] { Double.valueOf(6), Double.valueOf(5) }); ac.finish(); ac.start(); - ac.onRow(new Double[] { new Double(6), new Double(5) }); + ac.onRow(new Double[] { Double.valueOf(6), Double.valueOf(5) }); ac.finish(); - assertEquals(new Boolean(true), ac.getValue()); + assertEquals(Boolean.valueOf(true), ac.getValue()); // test Total.ISTOPN() for BigDecimal data ac = ag.newAccumulator(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(5) }); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(5) }); } ac.finish(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(5) }); - assertEquals(new Boolean(doubleArray1TopBottom[i]), ac.getValue()); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(5) }); + assertEquals(Boolean.valueOf(doubleArray1TopBottom[i]), ac.getValue()); } ac.finish(); @@ -1419,13 +1426,13 @@ public void testTotalTop() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(33) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(33) }); } ac.finish(); ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(33) }); - assertEquals(new Boolean(doubleArray1TopBottom[i]), ac.getValue()); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(33) }); + assertEquals(Boolean.valueOf(doubleArray1TopBottom[i]), ac.getValue()); } ac.finish(); @@ -1433,13 +1440,13 @@ public void testTotalTop() throws Exception { ac = ag.newAccumulator(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(33) }); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(33) }); } ac.finish(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(33) }); - assertEquals(new Boolean(doubleArray1TopBottom[i]), ac.getValue()); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(33) }); + assertEquals(Boolean.valueOf(doubleArray1TopBottom[i]), ac.getValue()); } ac.finish(); @@ -1452,13 +1459,13 @@ public void testTotalTop() throws Exception { assertTrue(!ag.getParameterDefn()[1].isOptional()); ac.start(); - ac.onRow(new Double[] { new Double(6), new Double(100) }); + ac.onRow(new Double[] { Double.valueOf(6), Double.valueOf(100) }); ac.finish(); ac.start(); - ac.onRow(new Double[] { new Double(6), new Double(100) }); + ac.onRow(new Double[] { Double.valueOf(6), Double.valueOf(100) }); ac.finish(); - assertEquals(new Boolean(true), ac.getValue()); + assertEquals(Boolean.valueOf(true), ac.getValue()); } /** @@ -1477,14 +1484,14 @@ public void testTotalTop2() throws Exception { ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Double[] { doubleArray3[i], new Double(2) }); + ac.onRow(new Double[] { doubleArray3[i], Double.valueOf(2) }); } ac.finish(); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Double[] { doubleArray3[i], new Double(2) }); - assertEquals(new Boolean(doubleArray3TopBottom[i]), ac.getValue()); + ac.onRow(new Double[] { doubleArray3[i], Double.valueOf(2) }); + assertEquals(Boolean.valueOf(doubleArray3TopBottom[i]), ac.getValue()); } ac.finish(); } @@ -1501,13 +1508,13 @@ public void testTotalBottom() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(10) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(10) }); } ac.finish(); ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(10) }); - assertEquals(new Boolean(!doubleArray1TopBottom[i]), ac.getValue()); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(10) }); + assertEquals(Boolean.valueOf(!doubleArray1TopBottom[i]), ac.getValue()); } ac.finish(); @@ -1515,13 +1522,13 @@ public void testTotalBottom() throws Exception { ac = ag.newAccumulator(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(10) }); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(10) }); } ac.finish(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(10) }); - assertEquals(new Boolean(!doubleArray1TopBottom[i]), ac.getValue()); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(10) }); + assertEquals(Boolean.valueOf(!doubleArray1TopBottom[i]), ac.getValue()); } ac.finish(); @@ -1535,14 +1542,14 @@ public void testTotalBottom() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(66) }); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(66) }); } ac.finish(); ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(66) }); - assertEquals(new Boolean(!doubleArray1TopBottom[i]), ac.getValue()); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(66) }); + assertEquals(Boolean.valueOf(!doubleArray1TopBottom[i]), ac.getValue()); } ac.finish(); @@ -1550,13 +1557,13 @@ public void testTotalBottom() throws Exception { ac = ag.newAccumulator(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(66) }); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(66) }); } ac.finish(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(66) }); - assertEquals(new Boolean(!doubleArray1TopBottom[i]), ac.getValue()); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(66) }); + assertEquals(Boolean.valueOf(!doubleArray1TopBottom[i]), ac.getValue()); } ac.finish(); } @@ -1573,14 +1580,14 @@ public void testTotalRank() throws Exception { ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Boolean(false) }); + ac.onRow(new Object[] { doubleArray3[i], Boolean.valueOf(false) }); } ac.finish(); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Integer(0) }); - assertEquals(new Integer(doubleArray3RankDec[i]), ac.getValue()); + ac.onRow(new Object[] { doubleArray3[i], Integer.valueOf(0) }); + assertEquals(Integer.valueOf(doubleArray3RankDec[i]), ac.getValue()); } ac.finish(); @@ -1589,13 +1596,13 @@ public void testTotalRank() throws Exception { ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Boolean(true) }); + ac.onRow(new Object[] { doubleArray3[i], Boolean.valueOf(true) }); } ac.finish(); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Integer(1) }); - assertEquals(new Integer(doubleArray3RankAsc[i]), ac.getValue()); + ac.onRow(new Object[] { doubleArray3[i], Integer.valueOf(1) }); + assertEquals(Integer.valueOf(doubleArray3RankAsc[i]), ac.getValue()); } ac.finish(); @@ -1603,14 +1610,73 @@ public void testTotalRank() throws Exception { ac = ag.newAccumulator(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Boolean(true) }); + ac.onRow(new Object[] { bigDecimalArray[i], Boolean.valueOf(true) }); + } + ac.finish(); + ac.start(); + for (int i = 0; i < bigDecimalArray.length; i++) { + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(0) }); + assertEquals(Integer.valueOf(bigDecimalRankAsc[i]), ac.getValue()); + } + ac.finish(); + } + + @Test + public void testTotalDenseRank() throws Exception { + IAggrFunction ag = buildInAggrFactory.getAggregation("denserank"); + Accumulator ac = ag.newAccumulator(); + assertEquals(IBuildInAggregation.TOTAL_DENSERANK_FUNC, ag.getName()); + assertEquals(IAggrFunction.RUNNING_AGGR, ag.getType()); + assertEquals(2, ag.getParameterDefn().length); + assertTrue(!ag.getParameterDefn()[0].isOptional()); + assertFalse(!ag.getParameterDefn()[1].isOptional()); + + ac.start(); + for (int i = 0; i < doubleArray3.length; i++) { + ac.onRow(new Object[] { doubleArray3[i], Boolean.valueOf(false) }); + } + ac.finish(); + + ac.start(); + int[] doubleResultArray3DenseRankDec = new int[doubleArray3.length]; + for (int i = 0; i < doubleArray3.length; i++) { + ac.onRow(new Object[] { doubleArray3[i], Integer.valueOf(0) }); + doubleResultArray3DenseRankDec[i] = ((Integer) ac.getValue()).intValue(); + } + assertArrayEquals(doubleArray3DenseRankDec, doubleResultArray3DenseRankDec); + ac.finish(); + + ag = buildInAggrFactory.getAggregation("denserank"); + ac = ag.newAccumulator(); + + ac.start(); + for (int i = 0; i < doubleArray3.length; i++) { + ac.onRow(new Object[] { doubleArray3[i], Boolean.valueOf(true) }); + } + ac.finish(); + ac.start(); + int[] doubleResultArray3DenseRankAsc = new int[doubleArray3.length]; + for (int i = 0; i < doubleArray3.length; i++) { + ac.onRow(new Object[] { doubleArray3[i], Integer.valueOf(1) }); + doubleResultArray3DenseRankAsc[i] = ((Integer) ac.getValue()).intValue(); + } + assertArrayEquals(doubleArray3DenseRankAsc, doubleResultArray3DenseRankAsc); + ac.finish(); + + // test Total.denserank() for BigDecimal data + ac = ag.newAccumulator(); + ac.start(); + for (int i = 0; i < bigDecimalArray.length; i++) { + ac.onRow(new Object[] { bigDecimalArray[i], Boolean.valueOf(true) }); } ac.finish(); ac.start(); + int[] bigDecimalResultArray3DenseRankAsc = new int[bigDecimalArray.length]; for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(0) }); - assertEquals(new Integer(bigDecimalRankAsc[i]), ac.getValue()); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(0) }); + bigDecimalResultArray3DenseRankAsc[i] = ((Integer) ac.getValue()).intValue(); } + assertArrayEquals(bigDecimalDenseRankAsc, bigDecimalResultArray3DenseRankAsc); ac.finish(); } @@ -1632,7 +1698,7 @@ public void testTotalPercentRank() throws Exception { for (int i = 0; i < doubleArray3.length; i++) { ac.onRow(new Object[] { doubleArray3[i] }); assertEquals(doubleArray3PercentRank[i], - new Double((((Double) ac.getValue()).doubleValue() * 1000)).intValue()); + Double.valueOf((((Double) ac.getValue()).doubleValue() * 1000)).intValue()); } ac.finish(); @@ -1647,7 +1713,7 @@ public void testTotalPercentRank() throws Exception { for (int i = 0; i < bigDecimalArray.length; i++) { ac.onRow(new Object[] { bigDecimalArray[i] }); assertEquals(bigDecimalPercentRank[i], - new Double((((Double) ac.getValue()).doubleValue() * 1000)).intValue()); + Double.valueOf((((Double) ac.getValue()).doubleValue() * 1000)).intValue()); } ac.finish(); } @@ -1670,8 +1736,8 @@ public void testTotalPercentSum() throws Exception { ac.start(); for (int i = 0; i < doubleArray3.length; i++) { ac.onRow(new Object[] { doubleArray3[i] }); - assertEquals(doubleArray3PercentSum[i] == null ? new Integer(0) : doubleArray3PercentSum[i], - new Integer((int) (Double.parseDouble(ac.getValue().toString()) * 1000))); + assertEquals(doubleArray3PercentSum[i] == null ? Integer.valueOf(0) : doubleArray3PercentSum[i], + Integer.valueOf((int) (Double.parseDouble(ac.getValue().toString()) * 1000))); } ac.finish(); // DataException should be throwed if the parameter is non-numeric @@ -1697,7 +1763,7 @@ public void testTotalPercentSum() throws Exception { ac.onRow(new Object[] { bigDecimalArray[i] }); Object ret = ac.getValue(); assertTrue(ret instanceof Double); - assertEquals(bigDecimalPercentSum[i], new Double((((Number) ret).doubleValue() * 1000)).intValue()); + assertEquals(bigDecimalPercentSum[i], Double.valueOf((((Number) ret).doubleValue() * 1000)).intValue()); } ac.finish(); } @@ -1714,48 +1780,48 @@ public void testTotalPercentile() throws Exception { ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(0.1) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(0.1) }); } ac.finish(); Object value = ac.getValue(); - assertEquals(value, new Double(10.0)); + assertEquals(value, Double.valueOf(10.0)); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(0) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(0) }); } ac.finish(); value = ac.getValue(); - assertEquals(value, new Double(10)); + assertEquals(value, Double.valueOf(10)); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(1) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(1) }); } ac.finish(); value = ac.getValue(); - assertEquals(value, new Double(300)); + assertEquals(value, Double.valueOf(300)); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(0.7) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(0.7) }); } ac.finish(); value = ac.getValue(); - assertEquals(value, new Double(70)); + assertEquals(value, Double.valueOf(70)); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(0.35) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(0.35) }); } ac.finish(); value = ac.getValue(); - assertEquals(value, new Double(17.5)); + assertEquals(value, Double.valueOf(17.5)); try { ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(-1) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(-1) }); } ac.finish(); fail("should not arrive here"); @@ -1767,13 +1833,13 @@ public void testTotalPercentile() throws Exception { ac.start(); for (int i = 0; i < doubleArray3.length; i++) { try { - ac.onRow(new Object[] { doubleArray3[i], new Double(-0.9) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(-0.9) }); fail(); } catch (DataException e) { } try { - ac.onRow(new Object[] { doubleArray3[i], new Double(4.1) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(4.1) }); fail(); } catch (DataException e) { } @@ -1784,7 +1850,7 @@ public void testTotalPercentile() throws Exception { ac = ag.newAccumulator(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(0.1) }); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(0.1) }); } ac.finish(); Object ret = ac.getValue(); @@ -1804,48 +1870,48 @@ public void testTotalQuartile() throws Exception { ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(0) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(0) }); } ac.finish(); Object value = ac.getValue(); - assertEquals(value, new Double(10)); + assertEquals(value, Double.valueOf(10)); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(1) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(1) }); } ac.finish(); value = ac.getValue(); - assertEquals(value, new Double(12.5)); + assertEquals(value, Double.valueOf(12.5)); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(2) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(2) }); } ac.finish(); value = ac.getValue(); - assertEquals(value, new Double(30)); + assertEquals(value, Double.valueOf(30)); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(3) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(3) }); } ac.finish(); value = ac.getValue(); - assertEquals(value, new Double(85)); + assertEquals(value, Double.valueOf(85)); ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(4) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(4) }); } ac.finish(); value = ac.getValue(); - assertEquals(value, new Double(300)); + assertEquals(value, Double.valueOf(300)); try { ac.start(); for (int i = 0; i < doubleArray3.length; i++) { - ac.onRow(new Object[] { doubleArray3[i], new Double(5) }); + ac.onRow(new Object[] { doubleArray3[i], Double.valueOf(5) }); } ac.finish(); fail("should not arrive here"); @@ -1855,7 +1921,7 @@ public void testTotalQuartile() throws Exception { ac = ag.newAccumulator(); ac.start(); for (int i = 0; i < bigDecimalArray.length; i++) { - ac.onRow(new Object[] { bigDecimalArray[i], new Double(1) }); + ac.onRow(new Object[] { bigDecimalArray[i], Double.valueOf(1) }); } ac.finish(); Object ret = ac.getValue(); @@ -1873,8 +1939,8 @@ public void testTotalRunningCount() throws Exception { ac.start(); for (int i = 0; i < doubleArray1.length; i++) { - ac.onRow(new Double[] { new Double(doubleArray1[i]), new Double(5) }); - assertEquals(new Integer(i + 1), ac.getValue()); + ac.onRow(new Double[] { Double.valueOf(doubleArray1[i]), Double.valueOf(5) }); + assertEquals(Integer.valueOf(i + 1), ac.getValue()); } ac.finish(); @@ -1883,14 +1949,14 @@ public void testTotalRunningCount() throws Exception { ac.onRow(new Object[] { anyObjectArray[i] }); } ac.finish(); - assertEquals(new Integer(5), ac.getValue()); + assertEquals(Integer.valueOf(5), ac.getValue()); ac.start(); for (int i = 0; i < anyObjectArray.length; i++) { ac.onRow(null); } ac.finish(); - assertEquals(new Integer(8), ac.getValue()); + assertEquals(Integer.valueOf(8), ac.getValue()); } }