Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove apache.commons.coll: CollectionUtils.filter, CompositeCollection #1288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions mondrian/src/it/java/mondrian/olap/fun/sort/SorterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import mondrian.olap.fun.MemberOrderKeyFunDef;
import mondrian.server.Execution;
import mondrian.server.Statement;
import java.util.Comparator;
import org.apache.commons.collections.comparators.ComparatorChain;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
Expand Down Expand Up @@ -57,8 +58,8 @@ public class SorterTest extends TestCase {
@Mock Hierarchy hierarchy2;
@Mock Calc calc1;
@Mock Calc calc2;
@Mock ComparatorChain comparatorChain;
@Captor ArgumentCaptor<TupleComparator> comparatorCaptor;
@Mock Comparator comparatorChain;
@Captor ArgumentCaptor<Comparator> comparatorCaptor;


public void setUp() throws Exception {
Expand All @@ -83,31 +84,34 @@ public void testComparatorSelectionBrkOrderByKey() {
setupSortKeyMocks( true, Sorter.Flag.BASC, Sorter.Flag.BDESC );
Sorter.applySortSpecToComparator( evaluator, 2, comparatorChain, sortKeySpec1 );
Sorter.applySortSpecToComparator( evaluator, 2, comparatorChain, sortKeySpec2 );
verify( comparatorChain ).addComparator( any( TupleExpMemoComparator.BreakTupleComparator.class ), eq( false ) );
verify( comparatorChain ).addComparator( any( TupleExpMemoComparator.BreakTupleComparator.class ), eq( true ) );
verify( comparatorChain, times( 2 ) ).thenComparing( comparatorCaptor.capture());
assertTrue( comparatorCaptor.getAllValues().get( 0 ) instanceof TupleExpMemoComparator.BreakTupleComparator );
assertTrue( comparatorCaptor.getAllValues().get( 1 ).reversed() instanceof TupleExpMemoComparator.BreakTupleComparator );
}

public void testComparatorSelectionBrkNotOrderByKey() {
setupSortKeyMocks( false, Sorter.Flag.BASC, Sorter.Flag.BDESC );
Sorter.applySortSpecToComparator( evaluator, 2, comparatorChain, sortKeySpec1 );
Sorter.applySortSpecToComparator( evaluator, 2, comparatorChain, sortKeySpec2 );
verify( comparatorChain ).addComparator( any( TupleExpMemoComparator.BreakTupleComparator.class ), eq( false ) );
verify( comparatorChain ).addComparator( any( TupleExpMemoComparator.BreakTupleComparator.class ), eq( true ) );
verify( comparatorChain, times( 2 )).thenComparing(comparatorCaptor.capture());
assertTrue( comparatorCaptor.getAllValues().get( 0 ) instanceof TupleExpMemoComparator.BreakTupleComparator );
assertTrue( comparatorCaptor.getAllValues().get( 1 ).reversed() instanceof TupleExpMemoComparator.BreakTupleComparator );
}

public void testComparatorSelectionNotBreakingOrderByKey() {
setupSortKeyMocks( true, Sorter.Flag.ASC, Sorter.Flag.DESC );
Sorter.applySortSpecToComparator( evaluator, 2, comparatorChain, sortKeySpec1 );
Sorter.applySortSpecToComparator( evaluator, 2, comparatorChain, sortKeySpec2 );
verify( comparatorChain ).addComparator( any( HierarchicalTupleKeyComparator.class ), eq( false ) );
verify( comparatorChain ).addComparator( any( HierarchicalTupleKeyComparator.class ), eq( true ) );
verify( comparatorChain, times( 2 )).thenComparing(comparatorCaptor.capture());
assertTrue( comparatorCaptor.getAllValues().get( 0 ) instanceof HierarchicalTupleKeyComparator );
assertTrue( comparatorCaptor.getAllValues().get( 1 ).reversed() instanceof HierarchicalTupleKeyComparator );
}

public void testComparatorSelectionNotBreaking() {
setupSortKeyMocks( false, Sorter.Flag.ASC, Sorter.Flag.DESC );
Sorter.applySortSpecToComparator( evaluator, 2, comparatorChain, sortKeySpec1 );
Sorter.applySortSpecToComparator( evaluator, 2, comparatorChain, sortKeySpec2 );
verify( comparatorChain, times( 2 ) ).addComparator( comparatorCaptor.capture(), eq( false ) );
verify( comparatorChain, times( 2 )).thenComparing( comparatorCaptor.capture() );
assertTrue( comparatorCaptor.getAllValues().get( 0 ) instanceof HierarchicalTupleComparator );
assertTrue( comparatorCaptor.getAllValues().get( 1 ) instanceof HierarchicalTupleComparator );
}
Expand Down
2 changes: 1 addition & 1 deletion mondrian/src/it/java/mondrian/test/PerformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ void foo( int runCount, List<Integer> list, int limit ) {
}
}
@SuppressWarnings( "unchecked" ) final Comparator<Integer> comp =
ComparatorUtils.naturalComparator();
Comparator.naturalOrder();
final long start = System.currentTimeMillis();
List<Integer> x = sort( list, comp, limit );
statistician.record( start );
Expand Down
15 changes: 6 additions & 9 deletions mondrian/src/main/java/mondrian/olap/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import mondrian.spi.ProfileHandler;
import mondrian.util.ArrayStack;

import org.apache.commons.collections.collection.CompositeCollection;

import org.olap4j.impl.*;
import org.olap4j.mdx.IdentifierSegment;

Expand Down Expand Up @@ -552,13 +550,12 @@ public void explain( PrintWriter pw ) {
* @return Collection of all axes including slicer
*/
private Collection<QueryAxis> allAxes() {
if ( slicerAxis == null ) {
return Arrays.asList( axes );
} else {
// noinspection unchecked
return new CompositeCollection( new Collection[] { Collections.singletonList( slicerAxis ), Arrays.asList(
axes ) } );
}
List<QueryAxis> list=new ArrayList<>();
list.addAll( Arrays.asList( axes ));
if ( slicerAxis != null ) {
list.add(slicerAxis);
}
return list;
}

public void unparse( PrintWriter pw ) {
Expand Down
22 changes: 10 additions & 12 deletions mondrian/src/main/java/mondrian/olap/fun/sort/Sorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import mondrian.server.Execution;

import mondrian.util.CancellationChecker;
import org.apache.commons.collections.ComparatorUtils;
import org.apache.commons.collections.comparators.ComparatorChain;
import org.apache.log4j.Logger;

import java.util.AbstractList;
Expand Down Expand Up @@ -244,7 +242,7 @@ public static List<Member> sortMembers(
}
}

ComparatorChain chain = new ComparatorChain();
Comparator<Member> baseComp = (o1, o2) -> 0;
for ( SortKeySpec key : keySpecList ) {
boolean brk = key.getDirection().brk;
MemberComparator comp;
Expand All @@ -256,10 +254,10 @@ public static List<Member> sortMembers(
evaluator, key.getKey(), key.getDirection().descending );
}
comp.preloadValues( memberList );
chain.addComparator( comp.wrap(), false );
baseComp=baseComp.thenComparing(comp.wrap());
}

memberList.sort( chain );
memberList.sort( baseComp );
return memberList;
}

Expand Down Expand Up @@ -411,17 +409,17 @@ public static TupleList sortTuples(
return tupleList;
}

ComparatorChain chain = new ComparatorChain();
Comparator<List<Member>> chain = (o1, o2) -> 0;
for ( SortKeySpec key : keySpecList ) {
applySortSpecToComparator( evaluator, arity, chain, key );
chain= applySortSpecToComparator( evaluator, arity, chain, key );
}
tupleList.sort( chain );
logTuples( tupleList, "Sorter.sortTuples" );
return tupleList;
}

@VisibleForTesting
static void applySortSpecToComparator( Evaluator evaluator, int arity, ComparatorChain chain,
static Comparator<List<Member>> applySortSpecToComparator( Evaluator evaluator, int arity, Comparator<List<Member>> comparator,
SortKeySpec key ) {
boolean brk = key.getDirection().brk;
boolean orderByKey =
Expand All @@ -430,15 +428,15 @@ static void applySortSpecToComparator( Evaluator evaluator, int arity, Comparato
if ( brk ) {
TupleExpMemoComparator comp =
new TupleExpMemoComparator.BreakTupleComparator( evaluator, key.getKey(), arity );
chain.addComparator( comp, direction );
return comparator.thenComparing(direction? comp.reversed():comp);
} else if ( orderByKey ) {
TupleExpMemoComparator comp =
new HierarchicalTupleKeyComparator( evaluator, key.getKey(), arity );
chain.addComparator( comp, direction );
return comparator.thenComparing(direction? comp.reversed():comp);
} else {
TupleComparator.TupleExpComparator comp =
new HierarchicalTupleComparator( evaluator, key.getKey(), arity, direction );
chain.addComparator( comp, false ); // ordering handled in the comparator.
return comparator.thenComparing(comp); // ordering handled in the comparator.
}
}

Expand Down Expand Up @@ -764,7 +762,7 @@ public static int compareSiblingMembers( Member m1, Member m2 ) {
static <T> void partialSort( T[] items, Comparator<T> comp, int limit ) {
if ( comp == null ) {
//noinspection unchecked
comp = (Comparator<T>) ComparatorUtils.naturalComparator();
comp = (Comparator<T>) Comparator.naturalOrder();
}
new Quicksorter<>( items, comp ).partialSort( limit );
}
Expand Down