Skip to content

Commit

Permalink
Merge pull request #31 from 2023-2-Design-Pattern/lsj/fixOrderBy2
Browse files Browse the repository at this point in the history
fix: order by 숫자 문제 이전 해결책 문제점 해결
  • Loading branch information
keylime7 authored Nov 28, 2023
2 parents 3e8602f + e933edc commit d3cef71
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/com/holub/database/ConcreteTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -673,26 +673,27 @@ private Table orderBy(Table table, List orderByColumns, boolean ascending) {
Comparable<Object> value1 = (Comparable<Object>) o1[index];
Comparable<Object> value2 = (Comparable<Object>) 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;
Expand Down

0 comments on commit d3cef71

Please sign in to comment.