mirror of
https://github.com/tonikelope/megabasterd.git
synced 2025-04-29 22:24:32 +02:00
7.15
-Natural sort
This commit is contained in:
parent
c418d95bb1
commit
a6caabe3a8
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.tonikelope</groupId>
|
||||
<artifactId>MegaBasterd</artifactId>
|
||||
<version>7.14</version>
|
||||
<version>7.15</version>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -55,7 +55,7 @@ import javax.swing.UIManager;
|
||||
*/
|
||||
public final class MainPanel {
|
||||
|
||||
public static final String VERSION = "7.14";
|
||||
public static final String VERSION = "7.15";
|
||||
public static final boolean FORCE_SMART_PROXY = false; //TRUE FOR DEBUGING SMART PROXY
|
||||
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
|
||||
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
|
||||
|
@ -18,7 +18,8 @@ public class MegaMutableTreeNode extends DefaultMutableTreeNode {
|
||||
protected Comparator nodeComparator = new Comparator() {
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
return o1.toString().compareToIgnoreCase(o2.toString());
|
||||
|
||||
return MiscTools.naturalCompare(o1.toString(), o2.toString(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,7 +95,8 @@ public class MiscTools {
|
||||
} else {
|
||||
String sa = a.getUserObject().toString();
|
||||
String sb = b.getUserObject().toString();
|
||||
return sa.compareToIgnoreCase(sb);
|
||||
|
||||
return MiscTools.naturalCompare(sa, sb, true);
|
||||
}
|
||||
};
|
||||
private static final Logger LOG = Logger.getLogger(MiscTools.class.getName());
|
||||
@ -1134,6 +1135,69 @@ public class MiscTools {
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
/*
|
||||
Thanks -> https://stackoverflow.com/a/26884326
|
||||
*/
|
||||
public static int naturalCompare(String a, String b, boolean ignoreCase) {
|
||||
if (ignoreCase) {
|
||||
a = a.toLowerCase();
|
||||
b = b.toLowerCase();
|
||||
}
|
||||
int aLength = a.length();
|
||||
int bLength = b.length();
|
||||
int minSize = Math.min(aLength, bLength);
|
||||
char aChar, bChar;
|
||||
boolean aNumber, bNumber;
|
||||
boolean asNumeric = false;
|
||||
int lastNumericCompare = 0;
|
||||
for (int i = 0; i < minSize; i++) {
|
||||
aChar = a.charAt(i);
|
||||
bChar = b.charAt(i);
|
||||
aNumber = aChar >= '0' && aChar <= '9';
|
||||
bNumber = bChar >= '0' && bChar <= '9';
|
||||
if (asNumeric) {
|
||||
if (aNumber && bNumber) {
|
||||
if (lastNumericCompare == 0) {
|
||||
lastNumericCompare = aChar - bChar;
|
||||
}
|
||||
} else if (aNumber) {
|
||||
return 1;
|
||||
} else if (bNumber) {
|
||||
return -1;
|
||||
} else if (lastNumericCompare == 0) {
|
||||
if (aChar != bChar) {
|
||||
return aChar - bChar;
|
||||
}
|
||||
asNumeric = false;
|
||||
} else {
|
||||
return lastNumericCompare;
|
||||
}
|
||||
} else if (aNumber && bNumber) {
|
||||
asNumeric = true;
|
||||
if (lastNumericCompare == 0) {
|
||||
lastNumericCompare = aChar - bChar;
|
||||
}
|
||||
} else if (aChar != bChar) {
|
||||
return aChar - bChar;
|
||||
}
|
||||
}
|
||||
if (asNumeric) {
|
||||
if (aLength > bLength && a.charAt(bLength) >= '0' && a.charAt(bLength) <= '9') // as number
|
||||
{
|
||||
return 1; // a has bigger size, thus b is smaller
|
||||
} else if (bLength > aLength && b.charAt(aLength) >= '0' && b.charAt(aLength) <= '9') // as number
|
||||
{
|
||||
return -1; // b has bigger size, thus a is smaller
|
||||
} else if (lastNumericCompare == 0) {
|
||||
return aLength - bLength;
|
||||
} else {
|
||||
return lastNumericCompare;
|
||||
}
|
||||
} else {
|
||||
return aLength - bLength;
|
||||
}
|
||||
}
|
||||
|
||||
public static MegaAPI checkMegaAccountLoginAndShowMasterPassDialog(MainPanel main_panel, Container container, String email) throws Exception {
|
||||
|
||||
boolean remember_master_pass = true;
|
||||
|
@ -570,7 +570,7 @@ abstract public class TransferenceManager implements Runnable, SecureSingleThrea
|
||||
|
||||
ArrayList<Transference> trans_list = new ArrayList(queue);
|
||||
|
||||
trans_list.sort((Transference o1, Transference o2) -> o1.getFile_name().compareToIgnoreCase(o2.getFile_name()));
|
||||
trans_list.sort((Transference o1, Transference o2) -> MiscTools.naturalCompare(o1.getFile_name(), o2.getFile_name(), true));
|
||||
|
||||
queue.clear();
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 194 KiB After Width: | Height: | Size: 217 KiB |
Loading…
x
Reference in New Issue
Block a user