Skip to content

Commit 709e9b4

Browse files
committed
use type in OrderKey
Signed-off-by: Stefan Bischof <[email protected]>
1 parent 5a6c46f commit 709e9b4

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed

common/src/main/java/org/eclipse/daanse/olap/fun/FunUtil.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
import java.util.Map;
4040
import java.util.Set;
4141

42+
import org.slf4j.Logger;
43+
import org.slf4j.LoggerFactory;
44+
4245
import org.eclipse.daanse.mdx.model.api.expression.operation.OperationAtom;
4346
import org.eclipse.daanse.olap.api.CatalogReader;
4447
import org.eclipse.daanse.olap.api.DataType;
@@ -100,6 +103,8 @@
100103
*/
101104
public class FunUtil extends Util {
102105

106+
private static final Logger LOGGER = LoggerFactory.getLogger(FunUtil.class);
107+
103108
public static final NullMember NullMember = new NullMember();
104109

105110

@@ -481,8 +486,8 @@ public static int compareValues( Object value0, Object value1 ) {
481486
( (Number) value1 ).doubleValue() );
482487
} else if ( value0 instanceof Date date) {
483488
return date.compareTo( (Date) value1 );
484-
} else if ( value0 instanceof OrderKey orderKey) {
485-
return orderKey.compareTo( value1 );
489+
} else if ( value0 instanceof OrderKey orderKey && value1 instanceof OrderKey orderKeyOther) {
490+
return orderKey.compareTo( orderKeyOther);
486491
} else {
487492
throw Util.newInternal( "cannot compare " + value0 );
488493
}
@@ -940,8 +945,8 @@ public static SetWrapper[] evaluateSet(
940945
DoubleCalc calc = calcs[ i ];
941946
SetWrapper retval = retvals[ i ];
942947
Double o = calc.evaluate( evaluator );
943-
if(o==null) {
944-
System.out.println(calc);
948+
if (o == null) {
949+
LOGGER.debug("Calc evaluated to null: {}", calc);
945950
}
946951
if ( o == FunUtil.DOUBLE_NULL) {
947952
retval.nullCount++;
@@ -1673,7 +1678,7 @@ private static Member getCorrespondingMember(
16731678

16741679

16751680
public static class SetWrapper {
1676-
public List v = new ArrayList();
1681+
public List<Object> v = new ArrayList<>();
16771682
public int errorCount = 0;
16781683
public int nullCount = 0;
16791684

@@ -1700,16 +1705,16 @@ public static class SetWrapper {
17001705
* Nulls compare last, exceptions (including the
17011706
* object which indicates the the cell is not in the cache yet) next, then numbers and strings are compared by value.
17021707
*/
1703-
public static class DescendingValueComparator implements Comparator {
1708+
public static class DescendingValueComparator implements Comparator<Object> {
17041709
/**
17051710
* The singleton.
17061711
*/
17071712
public static final DescendingValueComparator instance =
17081713
new DescendingValueComparator();
17091714

17101715
@Override
1711-
public int compare( Object o1, Object o2 ) {
1712-
return -FunUtil.compareValues( o1, o2 );
1716+
public int compare(Object o1, Object o2) {
1717+
return -FunUtil.compareValues(o1, o2);
17131718
}
17141719
}
17151720

common/src/main/java/org/eclipse/daanse/olap/fun/sort/OrderKey.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,35 @@
2929

3030
import org.eclipse.daanse.olap.api.element.Member;
3131

32+
public class OrderKey implements Comparable<OrderKey> {
3233

33-
public class OrderKey implements Comparable {
34-
final Member member;
34+
final Member member;
3535

36-
public OrderKey( Member member ) {
37-
super();
38-
this.member = member;
39-
}
40-
41-
@Override
42-
public int compareTo( Object o ) {
43-
assert o instanceof OrderKey;
44-
OrderKey other = (OrderKey) o;
45-
Member otherMember = other.member;
46-
final boolean thisCalculated = this.member.isCalculatedInQuery();
47-
final boolean otherCalculated = otherMember.isCalculatedInQuery();
48-
if ( thisCalculated ) {
49-
if ( !otherCalculated ) {
50-
return 1;
51-
}
52-
} else {
53-
if ( otherCalculated ) {
54-
return -1;
55-
}
36+
public OrderKey(Member member) {
37+
this.member = member;
5638
}
57-
final Comparable thisKey = this.member.getOrderKey();
58-
final Comparable otherKey = otherMember.getOrderKey();
59-
if ( ( thisKey != null ) && ( otherKey != null ) ) {
60-
return thisKey.compareTo( otherKey );
61-
} else {
62-
return this.member.compareTo( otherMember );
39+
40+
@Override
41+
@SuppressWarnings({"rawtypes", "unchecked"})
42+
public int compareTo(OrderKey other) {
43+
Member otherMember = other.member;
44+
final boolean thisCalculated = this.member.isCalculatedInQuery();
45+
final boolean otherCalculated = otherMember.isCalculatedInQuery();
46+
if (thisCalculated) {
47+
if (!otherCalculated) {
48+
return 1;
49+
}
50+
} else {
51+
if (otherCalculated) {
52+
return -1;
53+
}
54+
}
55+
final Comparable thisKey = this.member.getOrderKey();
56+
final Comparable otherKey = otherMember.getOrderKey();
57+
if ((thisKey != null) && (otherKey != null)) {
58+
return thisKey.compareTo(otherKey);
59+
} else {
60+
return this.member.compareTo(otherMember);
61+
}
6362
}
64-
}
6563
}

common/src/main/java/org/eclipse/daanse/olap/fun/sort/Sorter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,8 @@ public static TupleList sortTuples(
328328
tupleArrayList = tupleList;
329329
}
330330

331-
@SuppressWarnings( { "unchecked" } )
332-
List<Member>[] tuples =
333-
tupleArrayList.toArray( new List[ tupleArrayList.size() ] );
331+
@SuppressWarnings("unchecked")
332+
List<Member>[] tuples = tupleArrayList.toArray(List[]::new);
334333
final DelegatingTupleList result =
335334
new DelegatingTupleList(
336335
tupleIterable.getArity(),
@@ -645,8 +644,8 @@ public static int compareValues( Object value0, Object value1 ) {
645644
return ( (Date) value0 ).compareTo( (Date) value1 );
646645
} else if ( value0 instanceof LocalDateTime ) {
647646
return ( (LocalDateTime) value0 ).compareTo( (LocalDateTime) value1 );
648-
} else if ( value0 instanceof OrderKey ) {
649-
return ( (OrderKey) value0 ).compareTo( value1 );
647+
} else if ( value0 instanceof OrderKey orderKey0 && value0 instanceof OrderKey orderKey1 ) {
648+
return orderKey0.compareTo( orderKey1);
650649
} else {
651650
throw newInternal( "cannot compare " + value0 );
652651
}

0 commit comments

Comments
 (0)