From e933edc506c54d06c2656ea4444e9c04963b5a4b Mon Sep 17 00:00:00 2001 From: keylime7 Date: Wed, 29 Nov 2023 00:26:24 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20order=20by=20=EC=88=AB=EC=9E=90=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=9D=B4=EC=A0=84=20=ED=95=B4=EA=B2=B0?= =?UTF-8?q?=EC=B1=85=20=EB=AC=B8=EC=A0=9C=EC=A0=90=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/holub/database/ConcreteTable.java | 39 ++++++++++++----------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/com/holub/database/ConcreteTable.java b/src/com/holub/database/ConcreteTable.java index 383e250..ab85a75 100644 --- a/src/com/holub/database/ConcreteTable.java +++ b/src/com/holub/database/ConcreteTable.java @@ -673,26 +673,27 @@ private Table orderBy(Table table, List orderByColumns, boolean ascending) { Comparable value1 = (Comparable) o1[index]; Comparable value2 = (Comparable) o2[index]; - if (value1 instanceof Number && value2 instanceof Number) { - double num1 = ((Number) value1).doubleValue(); - double num2 = ((Number) value2).doubleValue(); - int result = Double.compare(num1, num2); - - if (!ascending) { - result = -result; - } - - if (result != 0) { - return result; - } + boolean isNumber = o1[index] != null; + try { + double d = Double.parseDouble((String) o1[index]); + } catch (NumberFormatException e) { + isNumber = false; + } + + int result; + if(isNumber) { + double num1 = Double.parseDouble((String) o1[index]); + double num2 = Double.parseDouble((String) o2[index]); + result = Double.compare(num1, num2); } else { - int result = value1.compareTo(value2); - if (!ascending) { - result = -result; - } - if (result != 0) { - return result; - } + result = value1.compareTo(value2); + } + + if (!ascending) { + result = -result; + } + if (result != 0) { + return result; } } return 0;