Skip to content

Commit a10f08f

Browse files
committed
adds IterationType in index.ts so it is importable by users, fixes pagingpredicate test
1 parent 4a5d6db commit a10f08f

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as Predicates from './core/Predicate';
2222
import Address = require('./Address');
2323
import TopicOverloadPolicy = require('./proxy/topic/TopicOverloadPolicy');
2424
import * as HazelcastErrors from './HazelcastError';
25+
import {IterationType} from './core/Predicate';
2526

2627
export {
2728
HazelcastClient as Client,
@@ -31,5 +32,6 @@ export {
3132
Address,
3233
Predicates,
3334
TopicOverloadPolicy,
34-
HazelcastErrors
35+
HazelcastErrors,
36+
IterationType
3537
};

test/javaclasses/CustomComparator.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
var IterationType = require('../../lib/').IterationType;
18+
1719
/**
1820
*
1921
* @param type
@@ -45,12 +47,35 @@ CustomComparator.prototype.readData = function (inp) {
4547
this.iterationType = inp.readInt();
4648
};
4749

48-
CustomComparator.prototype.sort = function (o1, o2) {
49-
if (this.type === 0) {
50-
return o1[1] - o2[1];
51-
} else {
52-
return o2[1] - o1[1];
50+
CustomComparator.prototype.sort = function (e1, e2) {
51+
var str1;
52+
var str2;
53+
switch (this.iterationType) {
54+
case IterationType.KEY:
55+
str1 = e1[0].toString();
56+
str2 = e2[0].toString();
57+
break;
58+
case IterationType.VALUE:
59+
str1 = e1[1].toString();
60+
str2 = e2[1].toString();
61+
break;
62+
case IterationType.ENTRY:
63+
str1 = e1[0].toString() + e1[1].toString();
64+
str2 = e2[0].toString() + e2[1].toString();
65+
break;
66+
default:
67+
str1 = e1[0].toString();
68+
str2 = e2[0].toString();
69+
}
70+
switch (this.type) {
71+
case 0:
72+
return str1.localeCompare(str2);
73+
case 1:
74+
return str2.localeCompare(str1);
75+
case 2:
76+
return str1.length - str2.length;
5377
}
78+
return 0;
5479
};
5580

5681
module.exports = CustomComparator;

test/map/MapPredicateTest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ describe("Predicates", function() {
187187
});
188188

189189
it('Paging with reverse comparator should have elements in reverse order', function() {
190-
var paging = Predicates.paging(Predicates.lessThan('this', 40), 3, createReverseValueComparator());
191-
return testPredicate(paging, [39, 38, 37], true);
190+
var paging = Predicates.paging(Predicates.lessThan('this', 10), 3, createReverseValueComparator());
191+
return testPredicate(paging, [9, 8, 7], true);
192192
});
193193

194194
it('Paging first page should have first two items', function() {

0 commit comments

Comments
 (0)