Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
44   104   12   22
20   66   0,27   2
2     6  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  IndexesParser       Line # 37 44 12 95,5% 0.95454544
 
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 2009 (C) Sindre Mehus
18    */
19    package net.sourceforge.subsonic.androidapp.service.parser;
20   
21    import java.io.Reader;
22    import java.util.List;
23    import java.util.ArrayList;
24   
25    import org.xmlpull.v1.XmlPullParser;
26   
27    import android.content.Context;
28    import net.sourceforge.subsonic.androidapp.R;
29    import net.sourceforge.subsonic.androidapp.domain.Artist;
30    import net.sourceforge.subsonic.androidapp.domain.Indexes;
31    import net.sourceforge.subsonic.androidapp.util.ProgressListener;
32    import android.util.Log;
33   
34    /**
35    * @author Sindre Mehus
36    */
 
37    public class IndexesParser extends AbstractParser {
38    private static final String TAG = IndexesParser.class.getSimpleName();
39   
 
40  3 toggle public IndexesParser(Context context) {
41  3 super(context);
42    }
43   
 
44  3 toggle public Indexes parse(Reader reader, ProgressListener progressListener) throws Exception {
45   
46  3 long t0 = System.currentTimeMillis();
47  3 updateProgress(progressListener, R.string.parser_reading);
48  3 init(reader);
49   
50  3 List<Artist> artists = new ArrayList<Artist>();
51  3 List<Artist> shortcuts = new ArrayList<Artist>();
52  3 Long lastModified = null;
53  3 int eventType;
54  3 String index = "#";
55  3 boolean changed = false;
56   
57  3 do {
58  123 eventType = nextParseEvent();
59  123 if (eventType == XmlPullParser.START_TAG) {
60  37 String name = getElementName();
61  37 if ("indexes".equals(name)) {
62  1 changed = true;
63  1 lastModified = getLong("lastModified");
64  36 } else if ("index".equals(name)) {
65  10 index = get("name");
66   
67  26 } else if ("artist".equals(name)) {
68  22 Artist artist = new Artist();
69  22 artist.setId(get("id"));
70  22 artist.setName(get("name"));
71  22 artist.setIndex(index);
72  22 artists.add(artist);
73   
74  22 if (artists.size() % 10 == 0) {
75  2 String msg = getContext().getResources().getString(R.string.parser_artist_count, artists.size());
76  2 updateProgress(progressListener, msg);
77    }
78  4 } else if ("shortcut".equals(name)) {
79  1 Artist shortcut = new Artist();
80  1 shortcut.setId(get("id"));
81  1 shortcut.setName(get("name"));
82  1 shortcut.setIndex("*");
83  1 shortcuts.add(shortcut);
84  3 } else if ("error".equals(name)) {
85  0 handleError();
86    }
87    }
88  123 } while (eventType != XmlPullParser.END_DOCUMENT);
89   
90  3 validate();
91   
92  3 if (!changed) {
93  2 return null;
94    }
95   
96  1 long t1 = System.currentTimeMillis();
97  1 Log.d(TAG, "Got " + artists.size() + " artist(s) in " + (t1 - t0) + "ms.");
98   
99  1 String msg = getContext().getResources().getString(R.string.parser_artist_count, artists.size());
100  1 updateProgress(progressListener, msg);
101   
102  1 return new Indexes(lastModified == null ? 0L : lastModified, shortcuts, artists);
103    }
104    }