Libraryless. Click here for Pure Java version (66L/1K).
1 | static int compareCharIterators(Iterator<Char> it1, Iterator<Char> it2) {
|
2 | while true {
|
3 | if (!it1.hasNext()) |
4 | ret it2.hasNext() ? -1 : 0; |
5 | if (!it2.hasNext()) ret 1; |
6 | char a = it1.next(), b = it2.next(); |
7 | if (a < b) ret -1; |
8 | if (a > b) ret 1; |
9 | } |
10 | } |
11 | |
12 | static int compareCharIterators(CharacterIterator it1, CharacterIterator it2) {
|
13 | while true {
|
14 | if (!it1.hasNext()) |
15 | ret it2.hasNext() ? -1 : 0; |
16 | if (!it2.hasNext()) ret 1; |
17 | char a = it1.next(), b = it2.next(); |
18 | if (a < b) ret -1; |
19 | if (a > b) ret 1; |
20 | } |
21 | } |
22 | |
23 | static int compareCharIterators(CharacterIterator it1, CharacterIterator it2, CharComparator comparator) {
|
24 | if (comparator == null) ret compareCharIterators(it1, it2); |
25 | |
26 | while true {
|
27 | if (!it1.hasNext()) |
28 | ret it2.hasNext() ? -1 : 0; |
29 | if (!it2.hasNext()) ret 1; |
30 | char a = it1.next(), b = it2.next(); |
31 | int cmp = comparator.compare(a, b); |
32 | if (cmp != 0) ret cmp; |
33 | } |
34 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1029161 |
| Snippet name: | compareCharIterators - compare strings represented by char iterators lexicographically |
| Eternal ID of this version: | #1029161/8 |
| Text MD5: | 9d6a86f157f8671166ffae9196fd54af |
| Transpilation MD5: | a1e2fed74cfba29640411e23e3b627c6 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-08-23 09:27:22 |
| Source code size: | 970 bytes / 34 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 458 / 599 |
| Version history: | 7 change(s) |
| Referenced in: | [show references] |