public class Sorter extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Sorter.Flag
Enumeration of the flags allowed to the
ORDER MDX function. |
static class |
Sorter.ObjIntPair<T>
Tuple consisting of an object and an integer.
|
Constructor and Description |
---|
Sorter() |
Modifier and Type | Method and Description |
---|---|
static Double |
box(double d)
Converts a double (primitive) value to a Double.
|
static Integer |
box(int n)
Converts an int (primitive) value to an Integer.
|
static int |
compareHierarchically(Member m1,
Member m2,
boolean post)
Compares a pair of members according to their positions in a prefix-order (or postfix-order, if
post is
true) walk over a hierarchy. |
static int |
compareSiblingMembers(Member m1,
Member m2)
Compares two members which are known to have the same parent.
|
static int |
compareValues(double d1,
double d2)
Compares double-precision values according to MDX semantics.
|
static int |
compareValues(Object value0,
Object value1)
Compares two cell values.
|
static Map<List<Member>,Object> |
evaluateTuples(Evaluator evaluator,
Calc exp,
TupleList tuples)
For each tuple in a list, evaluates an expression and creates a map from tuples to values.
|
static void |
hierarchizeMemberList(List<Member> memberList,
boolean post)
Sorts a list of members into hierarchical order.
|
static TupleList |
hierarchizeTupleList(TupleList tupleList,
boolean post)
Sorts a list of tuples into hierarchical order.
|
static boolean |
listEquals(List<Member> a1,
List<Member> a2) |
static List<Member> |
partiallySortMembers(Evaluator evaluator,
List<Member> list,
Calc exp,
int limit,
boolean desc)
Partially sorts a list of Members by the value of an applied expression.
|
static List<List<Member>> |
partiallySortTuples(Evaluator evaluator,
TupleList list,
Calc exp,
int limit,
boolean desc)
Partially sorts a list of Tuples by the value of an applied expression.
|
static List<Member> |
sortMembers(Evaluator evaluator,
Iterable<Member> memberIter,
List<Member> memberList,
Calc exp,
boolean desc,
boolean brk)
Helper function to sort a list of members according to an expression.
|
static List<Member> |
sortMembers(Evaluator evaluator,
Iterable<Member> memberIter,
List<Member> memberList,
List<SortKeySpec> keySpecList)
Sorts a list of members according to a list of SortKeySpecs.
|
static TupleList |
sortTuples(Evaluator evaluator,
TupleIterable tupleIterable,
TupleList tupleList,
Calc exp,
boolean desc,
boolean brk,
int arity)
Sorts a list of Tuples by the value of an applied expression.
|
static TupleList |
sortTuples(Evaluator evaluator,
TupleIterable tupleIter,
TupleList tupleList,
List<SortKeySpec> keySpecList,
int arity)
Helper function to sort a list of tuples according to a list of expressions and a list of sorting flags.
|
static <T> List<T> |
stablePartialSort(List<T> list,
Comparator<T> comp,
int limit)
Stable partial sort of a list.
|
static <T> List<T> |
stablePartialSort(List<T> list,
Comparator<T> comp,
int limit,
int algorithm)
Stable partial sort of a list, using a specified algorithm.
|
static <T> List<T> |
stablePartialSortArray(List<T> list,
Comparator<T> comp,
int limit)
Partial sort an array by sorting it and returning the first
limit elements. |
static <T> List<T> |
stablePartialSortJulian(List<T> list,
Comparator<T> comp,
int limit)
Julian's algorithm for stable partial sort.
|
static <T> List<T> |
stablePartialSortMarc(List<T> list,
Comparator<T> comp,
int limit)
Marc's original algorithm for stable partial sort of a list.
|
public static Map<List<Member>,Object> evaluateTuples(Evaluator evaluator, Calc exp, TupleList tuples)
evaluator
- Evaluation contextexp
- Expression to evaluatetuples
- List of tuples exp != null exp.getType() instanceof ScalarTypepublic static List<Member> sortMembers(Evaluator evaluator, Iterable<Member> memberIter, List<Member> memberList, Calc exp, boolean desc, boolean brk)
NOTE: This function does not preserve the contents of the validator.
If you do not specify memberList
, the method
will build its own member list as it iterates over memberIter
. It is acceptable if memberList
and
memberIter
are the same list object.
If you specify memberList
, the list is sorted in place, and
memberList is returned.
evaluator
- EvaluatormemberIter
- Iterable over membersmemberList
- List of membersexp
- Expression to sort ondesc
- Whether to sort descendingbrk
- Whether to breakpublic static List<Member> sortMembers(Evaluator evaluator, Iterable<Member> memberIter, List<Member> memberList, List<SortKeySpec> keySpecList)
NOTE: Does not preserve the contents of the validator.
public static TupleList sortTuples(Evaluator evaluator, TupleIterable tupleIterable, TupleList tupleList, Calc exp, boolean desc, boolean brk, int arity)
Helper function for MDX functions TopCount, TopSum, TopPercent, BottomCount, BottomSum, BottomPercent, but not the MDX function Order.
NOTE: This function does not preserve the contents of the validator.
If you specify tupleList
, the list is sorted in place, and
tupleList is returned.
evaluator
- EvaluatortupleIterable
- Iterator over tuplestupleList
- List of tuples, if known, otherwise nullexp
- Expression to sort ondesc
- Whether to sort descendingbrk
- Whether to breakarity
- Number of members in each tuplepublic static List<Member> partiallySortMembers(Evaluator evaluator, List<Member> list, Calc exp, int limit, boolean desc)
Avoids sorting the whole list, finds only the ntop (or bottom) valued Members, and returns them as a new List. Helper function for MDX functions TopCount and BottomCount.
NOTE: Does not preserve the contents of the validator.
list
- a list of membersexp
- a Calc applied to each member to find its sort-keyevaluator
- Evaluatorlimit
- maximum count of members to return.desc
- true to sort descending (and find TopCount), false to sort ascending (and find BottomCount).public static TupleList sortTuples(Evaluator evaluator, TupleIterable tupleIter, TupleList tupleList, List<SortKeySpec> keySpecList, int arity)
NOTE: This function does not preserve the contents of the validator.
public static List<List<Member>> partiallySortTuples(Evaluator evaluator, TupleList list, Calc exp, int limit, boolean desc)
Avoids sorting the whole list, finds only the n top (or bottom) valued Tuples, and returns them as a new List. Helper function for MDX functions TopCount and BottomCount.
NOTE: Does not preserve the contents of the validator. The returned list is immutable.
evaluator
- Evaluatorlist
- a list of tuplesexp
- a Calc applied to each tuple to find its sort-keylimit
- maximum count of tuples to return.desc
- true to sort descending (and find TopCount), false to sort ascending (and find BottomCount).public static void hierarchizeMemberList(List<Member> memberList, boolean post)
memberList
- List of memberspost
- Whether to sort in post order; if false, sorts in pre orderhierarchizeTupleList(mondrian.calc.TupleList, boolean)
public static TupleList hierarchizeTupleList(TupleList tupleList, boolean post)
tupleList
- List of tuplespost
- Whether to sort in post order; if false, sorts in pre orderhierarchizeMemberList(java.util.List, boolean)
public static int compareValues(double d1, double d2)
MDX requires a total order:
-inf < NULL < ... < -1 < ... < 0 < ... < NaN < +infbut this is different than Java semantics, specifically with regard to
Double.NaN
.public static int compareValues(Object value0, Object value1)
Nulls compare last, exceptions (including the object which indicates the the cell is not in the cache yet) next, then numbers and strings are compared by value.
value0
- First cell valuevalue1
- Second cell valuepublic static Double box(double d)
public static Integer box(int n)
public static int compareHierarchically(Member m1, Member m2, boolean post)
post
is
true) walk over a hierarchy.m1
- First memberm2
- Second memberpost
- Whether to sortMembers in postfix order. If true, a parent will sortMembers immediately after its last
child. If false, a parent will sortMembers immediately before its first child.public static int compareSiblingMembers(Member m1, Member m2)
First, compare by ordinal. This is only valid now we know they're siblings, because ordinals are only unique within a parent. If the dimension does not use ordinals, both ordinals will be -1.
If the ordinals do not differ, compare using regular member comparison.
m1
- First memberm2
- Second memberpublic static <T> List<T> stablePartialSort(List<T> list, Comparator<T> comp, int limit)
public static <T> List<T> stablePartialSort(List<T> list, Comparator<T> comp, int limit, int algorithm)
public static <T> List<T> stablePartialSortArray(List<T> list, Comparator<T> comp, int limit)
limit
elements. Fastest approach if limit is a
significant fraction of the list.public static <T> List<T> stablePartialSortMarc(List<T> list, Comparator<T> comp, int limit)
stablePartialSortJulian(java.util.List<T>, java.util.Comparator<T>, int)
.public static <T> List<T> stablePartialSortJulian(List<T> list, Comparator<T> comp, int limit)
limit
items seen. The items on the priority queue have an ordinal field, so the queue can be used to
generate a list of stably sorted items. (Heap sort is not normally stable.)T
- Element typelist
- List to sortcomp
- Comparatorlimit
- Maximum number of items to returnCopyright © 2020 Hitachi Vantara. All rights reserved.