| 4333 | } |
| 4334 | |
| 4335 | @Override |
| 4336 | public int compare(int index1, int index2) { |
| 4337 | int a = reverse ? order[index2] : order[index1]; |
| 4338 | int b = reverse ? order[index1] : order[index2]; |
| 4339 | |
| 4340 | switch (getColumnType(column)) { |
| 4341 | case INT: |
| 4342 | return getInt(a, column) - getInt(b, column); |
| 4343 | case LONG: |
| 4344 | long diffl = getLong(a, column) - getLong(b, column); |
| 4345 | return diffl == 0 ? 0 : (diffl < 0 ? -1 : 1); |
| 4346 | case FLOAT: |
| 4347 | float difff = getFloat(a, column) - getFloat(b, column); |
| 4348 | return difff == 0 ? 0 : (difff < 0 ? -1 : 1); |
| 4349 | case DOUBLE: |
| 4350 | double diffd = getDouble(a, column) - getDouble(b, column); |
| 4351 | return diffd == 0 ? 0 : (diffd < 0 ? -1 : 1); |
| 4352 | case STRING: |
| 4353 | String string1 = getString(a, column); |
| 4354 | if (string1 == null) { |
| 4355 | string1 = ""; // avoid NPE when cells are left empty |
| 4356 | } |
| 4357 | String string2 = getString(b, column); |
| 4358 | if (string2 == null) { |
| 4359 | string2 = ""; |
| 4360 | } |
| 4361 | return string1.compareToIgnoreCase(string2); |
| 4362 | case CATEGORY: |
| 4363 | return getInt(a, column) - getInt(b, column); |
| 4364 | default: |
| 4365 | throw new IllegalArgumentException("Invalid column type: " + getColumnType(column)); |
| 4366 | } |
| 4367 | } |
| 4368 | |
| 4369 | @Override |
| 4370 | public void swap(int a, int b) { |