Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart6.png 65% of files have more coverage
17   77   8   4,25
8   46   0,47   4
4     2  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  ArtistAdapter       Line # 35 17 8 55,2% 0.55172414
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2010 (C) Sindre Mehus
18    */
19    package net.sourceforge.subsonic.androidapp.util;
20   
21    import net.sourceforge.subsonic.androidapp.domain.Artist;
22    import net.sourceforge.subsonic.androidapp.R;
23    import android.widget.ArrayAdapter;
24    import android.widget.SectionIndexer;
25    import android.content.Context;
26   
27    import java.util.List;
28    import java.util.Set;
29    import java.util.LinkedHashSet;
30    import java.util.ArrayList;
31   
32    /**
33    * @author Sindre Mehus
34    */
 
35    public class ArtistAdapter extends ArrayAdapter<Artist> implements SectionIndexer {
36   
37    // Both arrays are indexed by section ID.
38    private final Object[] sections;
39    private final Integer[] positions;
40   
 
41  4 toggle public ArtistAdapter(Context context, List<Artist> artists) {
42  4 super(context, R.layout.artist_list_item, artists);
43   
44  4 Set<String> sectionSet = new LinkedHashSet<String>(30);
45  4 List<Integer> positionList = new ArrayList<Integer>(30);
46  78 for (int i = 0; i < artists.size(); i++) {
47  74 Artist artist = artists.get(i);
48  74 String index = artist.getIndex();
49  74 if (!sectionSet.contains(index)) {
50  37 sectionSet.add(index);
51  37 positionList.add(i);
52    }
53    }
54  4 sections = sectionSet.toArray(new Object[sectionSet.size()]);
55  4 positions = positionList.toArray(new Integer[positionList.size()]);
56    }
57   
 
58  0 toggle @Override
59    public Object[] getSections() {
60  0 return sections;
61    }
62   
 
63  0 toggle @Override
64    public int getPositionForSection(int section) {
65  0 return positions[section];
66    }
67   
 
68  0 toggle @Override
69    public int getSectionForPosition(int pos) {
70  0 for (int i = 0; i < sections.length - 1; i++) {
71  0 if (pos < positions[i + 1]) {
72  0 return i;
73    }
74    }
75  0 return sections.length - 1;
76    }
77    }