This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
forked from arouel/uadetector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arouel#133 : replaced alphanum by other implementation
Thomas Draier
committed
Sep 29, 2016
1 parent
43f6147
commit 3df9453
Showing
5 changed files
with
84 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 0 additions & 150 deletions
150
...les/uadetector-core/src/main/java/net/sf/uadetector/internal/util/AlphanumComparator.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
...uadetector-core/src/main/java/net/sf/uadetector/internal/util/NaturalOrderComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2014 Olivier Oudot | ||
* | ||
* THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR | ||
* "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS | ||
* AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. | ||
* | ||
* BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. | ||
* TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN | ||
* CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS. | ||
* | ||
* https://creativecommons.org/licenses/by-sa/3.0/ | ||
*/ | ||
package net.sf.uadetector.internal.util; | ||
|
||
import java.util.*; | ||
|
||
public class NaturalOrderComparator implements Comparator { | ||
|
||
@Override | ||
public int compare(Object o1, Object o2) { | ||
return compareNatural(o1 != null ? o1.toString() : "", o2 != null ? o2.toString() : ""); | ||
} | ||
|
||
public static final int compareNatural(String s1, String s2) { | ||
// Skip all identical characters | ||
int len1 = s1.length(); | ||
int len2 = s2.length(); | ||
int i; | ||
char c1, c2; | ||
for (i = 0, c1 = 0, c2 = 0; (i < len1) && (i < len2) && (c1 = s1.charAt(i)) == (c2 = s2.charAt(i)); i++) ; | ||
|
||
// Check end of string | ||
if (c1 == c2) | ||
return (len1 - len2); | ||
|
||
// Check digit in first string | ||
if (Character.isDigit(c1)) { | ||
// Check digit only in first string | ||
if (!Character.isDigit(c2)) | ||
return ((i > 0) && Character.isDigit(s1.charAt(i - 1)) ? 1 : c1 - c2); | ||
|
||
// Scan all integer digits | ||
int x1, x2; | ||
for (x1 = i + 1; (x1 < len1) && Character.isDigit(s1.charAt(x1)); x1++) ; | ||
for (x2 = i + 1; (x2 < len2) && Character.isDigit(s2.charAt(x2)); x2++) ; | ||
|
||
// Longer integer wins, first digit otherwise | ||
return (x2 == x1 ? c1 - c2 : x1 - x2); | ||
} | ||
|
||
// Check digit only in second string | ||
if (Character.isDigit(c2)) | ||
return ((i > 0) && Character.isDigit(s2.charAt(i - 1)) ? -1 : c1 - c2); | ||
|
||
// No digits | ||
return (c1 - c2); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters