| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
package uk.me.parabola.imgfmt.app.srt; |
| 15 |
|
| 16 |
import java.util.Arrays; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
class SrtSortKey<T> implements SortKey<T> { |
| 25 |
private final T orig; |
| 26 |
private final byte[] key; |
| 27 |
private int second; |
| 28 |
|
| 29 |
public SrtSortKey(T orig, byte[] key) { |
| 30 |
this.orig = orig; |
| 31 |
this.key = key; |
| 32 |
} |
| 33 |
|
| 34 |
public SrtSortKey(T orig, byte[] key, int second) { |
| 35 |
this.orig = orig; |
| 36 |
this.key = key; |
| 37 |
this.second = second; |
| 38 |
} |
| 39 |
|
| 40 |
public int compareTo(SortKey<T> o) { |
| 41 |
SrtSortKey<T> other = (SrtSortKey<T>) o; |
| 42 |
if (key != other.key) { |
| 43 |
int length = Math.min(this.key.length, other.key.length); |
| 44 |
for (int i = 0; i < length; i++) { |
| 45 |
int k1 = this.key[i] & 0xff; |
| 46 |
int k2 = other.key[i] & 0xff; |
| 47 |
if (k1 < k2) { |
| 48 |
return -1; |
| 49 |
} else if (k1 > k2) { |
| 50 |
return 1; |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
if (second == other.second) |
| 60 |
return 0; |
| 61 |
else if (second < other.second) |
| 62 |
return -1; |
| 63 |
else |
| 64 |
return 1; |
| 65 |
} |
| 66 |
|
| 67 |
public T getObject() { |
| 68 |
return orig; |
| 69 |
} |
| 70 |
|
| 71 |
public String toString() { |
| 72 |
return String.format("%s,%d", Arrays.toString(key), second); |
| 73 |
} |
| 74 |
} |