Debian Codegraph @

src/uk/me/parabola/imgfmt/app/srt/IntegerSortKey.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2011.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13 package uk.me.parabola.imgfmt.app.srt;
14
15 /**
16 * Sort key when you are soring on a simple integer.
17 *
18 * @author Steve Ratcliffe
19 */
20 public class IntegerSortKey<T> implements SortKey<T> {
21 private final T object;
22 private final int val;
23 private final int second;
24
25 public IntegerSortKey(T object, int val, int second) {
26 this.object = object;
27 this.val = val;
28 this.second = second;
29 }
30
31 /**
32 * Get the object associated with this sort key. This will usually be the real object being sorted.
33 */
34 public T getObject() {
35 return object;
36 }
37
38 public int compareTo(SortKey<T> o) {
39 IntegerSortKey<T> other = (IntegerSortKey<T>) o;
40 if (val == other.val) {
41 if (second == other.second)
42 return 0;
43 else if (second < other.second)
44 return -1;
45 else
46 return 1;
47 }
48 else if (val < other.val)
49 return -1;
50 else
51 return 1;
52 }
53 }