EMMA Coverage Report (generated Thu Mar 09 12:17:56 CET 2017)
[all classes][kdk.android.simplydo]

COVERAGE SUMMARY FOR SOURCE FILE [ListListSorter.java]

nameclass, %method, %block, %line, %
ListListSorter.java100% (3/3)86%  (6/7)57%  (54/95)63%  (12/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ListListSorter$1100% (1/1)50%  (1/2)50%  (6/12)50%  (1/2)
compare (ListDesc, ListDesc): int 0%   (0/1)0%   (0/6)0%   (0/1)
ListListSorter$1 (ListListSorter): void 100% (1/1)100% (6/6)100% (1/1)
     
class ListListSorter100% (1/1)100% (3/3)51%  (36/71)65%  (11/17)
sort (List): void 100% (1/1)32%  (8/25)50%  (3/6)
setSortingMode (String): void 100% (1/1)42%  (13/31)57%  (4/7)
ListListSorter (): void 100% (1/1)100% (15/15)100% (4/4)
     
class ListListSorter$2100% (1/1)100% (2/2)100% (12/12)100% (2/2)
ListListSorter$2 (ListListSorter): void 100% (1/1)100% (6/6)100% (1/1)
compare (ListDesc, ListDesc): int 100% (1/1)100% (6/6)100% (1/1)

1/*
2 * Copyright (C) 2010 Keith Kildare
3 * 
4 * This file is part of SimplyDo.
5 * 
6 * SimplyDo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * 
11 * SimplyDo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 * 
16 * You should have received a copy of the GNU General Public License
17 * along with SimplyDo.  If not, see <http://www.gnu.org/licenses/>.
18 * 
19 */
20package kdk.android.simplydo;
21 
22import java.util.Collections;
23import java.util.Comparator;
24import java.util.List;
25 
26import android.util.Log;
27 
28public class ListListSorter
29{
30    public static final String PREF_NONE = "none";
31    public static final String PREF_ALPHA = "alphabetical";
32    
33    private static final int NONE = 0;
34    private static final int ALPHA = 1;
35    
36    private int sortingMode;
37    
38    private Comparator<ListDesc> idCompare;
39    private Comparator<ListDesc> alphaCompare;
40    
41    
42    public ListListSorter()
43    {
44        idCompare = new Comparator<ListDesc>() {
45            @Override
46            public int compare(ListDesc object1, ListDesc object2)
47            {
48                return object2.getId() - object1.getId();
49            }
50        };
51        alphaCompare = new Comparator<ListDesc>() {
52            @Override
53            public int compare(ListDesc object1, ListDesc object2)
54            {
55                return object1.getLabel().compareToIgnoreCase(object2.getLabel());
56            }
57        };
58    }
59    
60    
61    public void setSortingMode(String mode)
62    {
63        if(PREF_NONE.equals(mode))
64        {
65            sortingMode = NONE;
66        }
67        else if(PREF_ALPHA.equals(mode))
68        {
69            sortingMode = ALPHA;
70        }
71        else
72        {
73            sortingMode = NONE;
74            Log.w(L.TAG, "Unknown list sorting mode " + mode);
75        }
76    }
77    
78    
79    public void sort(List<ListDesc> list)
80    {
81        switch(sortingMode)
82        {
83        default:
84            Log.w(L.TAG, "Unknown list sorting enum " + sortingMode);
85            // fall through
86        case NONE:
87            // actually sorted by db id
88            Collections.sort(list, idCompare);
89            break;
90        case ALPHA:
91            Collections.sort(list, alphaCompare);
92            break;
93        }
94    }
95}

[all classes][kdk.android.simplydo]
EMMA 2.0.5312 (C) Vladimir Roubtsov