Debian Codegraph @

src/uk/me/parabola/imgfmt/app/srt/CombinedSortKey.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 * Allows you to combine another sort key with further integer comparisons.
17 * Avoids having to cram two integers into one when there is the possibility that
18 * they may not be enough bits to represent all values.
19 *
20 * @author Steve Ratcliffe
21 */
22 public class CombinedSortKey<T> implements SortKey<T> {
23 private final SortKey<T> key;
24 private final int first;
25 private final int second;
26
27 public CombinedSortKey(SortKey<T> obj, int first, int second) {
28 this.key = obj;
29 this.first = first;
30 this.second = second;
31 }
32
33 public T getObject() {
34 return key.getObject();
35 }
36
37 public int compareTo(SortKey<T> o) {
38 CombinedSortKey<T> other = (CombinedSortKey<T>) o;
39 int res = key.compareTo(other.key);
40 if (res == 0) {
41 res = Integer.compare(first, other.first);
42 if (res == 0) {
43 res = Integer.compare(second, other.second);
44 }
45 }
46 return res;
47 }
48 }