Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright (C) 2017.
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 pair 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 * @author Gerd Petermann
22 */
23 public class DoubleSortKey<T> implements SortKey<T> {
24 private final SortKey<T> key1;
25 private final SortKey<T> key2;
26
27 public DoubleSortKey(SortKey<T> key1, SortKey<T> key2) {
28 this.key1 = key1;
29 this.key2 = key2;
30 }
31
32 public T getObject() {
33 return key1.getObject();
34 }
35
36 public int compareTo(SortKey<T> o) {
37 DoubleSortKey<T> other = (DoubleSortKey<T>) o;
38 int res = key1.compareTo(other.key1);
39 if (res == 0) {
40 res = key2.compareTo(other.key2);
41 }
42 return res;
43 }
44 }