Debian Codegraph @

src/uk/me/parabola/imgfmt/app/srt/MultiSortKey.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
14 package uk.me.parabola.imgfmt.app.srt;
15
16 /**
17 * Combines a number of sort keys into one. The first is the primary sort and contains the
18 * actual object being sorted.
19 *
20 * @author Steve Ratcliffe
21 */
22 public class MultiSortKey<T> implements SortKey<T> {
23 private final SortKey<T> key1;
24 private final SortKey<T> key2;
25 private final SortKey<T> key3;
26
27 public MultiSortKey(SortKey<T> key1, SortKey<T> key2, SortKey<T> key3) {
28 this.key1 = key1;
29 this.key2 = key2;
30 this.key3 = key3;
31 }
32
33 public T getObject() {
34 return key1.getObject();
35 }
36
37 public int compareTo(SortKey<T> o) {
38 MultiSortKey<T> other = (MultiSortKey<T>) o;
39 int res = key1.compareTo(other.key1);
40 if (res == 0) {
41 res = key2.compareTo(other.key2);
42 if (res == 0 && key3 != null) {
43 res = key3.compareTo(other.key3);
44 }
45 }
46 return res;
47 }
48 }