@Override
    public int compare(ComplexEvent complexEvent1, ComplexEvent complexEvent2) {
        if (groupByExecutors != null) {
            for (int i = 0, groupByExecutorsLength = groupByExecutors.length; i < groupByExecutorsLength; i++) {
                ExpressionExecutor executor = groupByExecutors[i];
                boolean isAscending = isAscendingArray[i];
                Object value1 = executor.execute(complexEvent1);
                Object value2 = executor.execute(complexEvent2);
                if (value1 != null && value2 != null) {
                    int results = 0;
                    Attribute.Type type = executor.getReturnType();
                    switch (type) {
                        case STRING:
                            results = ((String) value1).compareTo(((String) value2));
                            break;
                        case INT:
                            results = ((Integer) value1).compareTo(((Integer) value2));
                            break;
                        case LONG:
                            results = ((Long) value1).compareTo(((Long) value2));
                            break;
                        case FLOAT:
                            results = ((Float) value1).compareTo(((Float) value2));
                            break;
                        case DOUBLE:
                            results = ((Double) value1).compareTo(((Double) value2));
                            break;
                        case BOOL:
                            results = ((Boolean) value1).compareTo(((Boolean) value2));
                            break;
                        case OBJECT:
                            int hashDiff = value1.hashCode() - value2.hashCode();
                            if (hashDiff < 0) {
                                results = -1;
                            } else if (hashDiff > 0) {
                                results = 1;
                            }
                    }
                    if (!isAscending) {
                        results = results * -1;
                    }
                    if (results != 0) {
                        return results;
                    }
                } else if (value1 != null) {
                    return -1;
                } else if (value2 != null) {
                    return 1;
                }
            }
            return 0;
        } else {
            return 0;
        }
    }
Comparator class to arrange complex events based on hashcode.
modules/siddhi-core/src/main/java/io/siddhi/core/query/selector/OrderByEventComparator.java