1 | /* This file is part of Aard Dictionary for Android <http://aarddict.org>. |
2 | * |
3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License version 3 |
5 | * as published by the Free Software Foundation. |
6 | * |
7 | * This program is distributed in the hope that it will be useful, |
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | * GNU General Public License <http://www.gnu.org/licenses/gpl-3.0.txt> |
11 | * for more details. |
12 | * |
13 | * Copyright (C) 2010 Igor Tkach |
14 | */ |
15 | |
16 | package aarddict; |
17 | |
18 | import java.util.Comparator; |
19 | import java.util.UUID; |
20 | |
21 | final class PreferredDictionaryComparator implements Comparator<Volume> { |
22 | |
23 | private final UUID preferred; |
24 | |
25 | PreferredDictionaryComparator(UUID preferred) { |
26 | this.preferred = preferred; |
27 | } |
28 | |
29 | public int compare(Volume d1, Volume d2) { |
30 | UUID id1 = d1.getDictionaryId(); |
31 | UUID id2 = d2.getDictionaryId(); |
32 | if (id1.equals(id2)) { |
33 | if (id1.equals(preferred)) { |
34 | return d1.header.volume - d2.header.volume; |
35 | } |
36 | } |
37 | else if (id1.equals(preferred)) { |
38 | return -1; |
39 | } |
40 | if (id2.equals(preferred)) { |
41 | return 1; |
42 | } |
43 | return 0; |
44 | } |
45 | } |