@Test public void testDurationParcer() { String duration = "0:00:25.678"; assertThat(parseDuration(duration)).isEqualTo(25); duration = "0:05:53.645"; assertThat(parseDuration(duration)).isEqualTo(353); duration = "0:05:53.1/2"; assertThat(parseDuration(duration)).isEqualTo(353); duration = "0:05:53"; assertThat(parseDuration(duration)).isEqualTo(353); duration = ":05:53.645"; assertThat(parseDuration(duration)).isEqualTo(353); duration = "2:05:53.645"; assertThat(parseDuration(duration)).isEqualTo(7553); }
public static int parseDuration(String dur) { if (TextUtils.isEmpty(dur)) { return -1; } String[] strings = dur.split(":"); if (strings.length != 3) { return -1; } try { int sec = 0; if (!TextUtils.isEmpty(strings[0])) { sec += TimeUnit.SECONDS.convert(Integer.decode(strings[0]), TimeUnit.HOURS); } sec += TimeUnit.SECONDS.convert(Integer.decode(strings[1]), TimeUnit.MINUTES); sec += TimeUnit.SECONDS.convert(Integer.decode(strings[2].substring(0, 2)), TimeUnit.SECONDS); return sec; } catch (NumberFormatException e) { return -1; } }
ModelUtil { public static int parseDuration(String dur) { if (TextUtils.isEmpty(dur)) { return -1; } String[] strings = dur.split(":"); if (strings.length != 3) { return -1; } try { int sec = 0; if (!TextUtils.isEmpty(strings[0])) { sec += TimeUnit.SECONDS.convert(Integer.decode(strings[0]), TimeUnit.HOURS); } sec += TimeUnit.SECONDS.convert(Integer.decode(strings[1]), TimeUnit.MINUTES); sec += TimeUnit.SECONDS.convert(Integer.decode(strings[2].substring(0, 2)), TimeUnit.SECONDS); return sec; } catch (NumberFormatException e) { return -1; } } }
ModelUtil { public static int parseDuration(String dur) { if (TextUtils.isEmpty(dur)) { return -1; } String[] strings = dur.split(":"); if (strings.length != 3) { return -1; } try { int sec = 0; if (!TextUtils.isEmpty(strings[0])) { sec += TimeUnit.SECONDS.convert(Integer.decode(strings[0]), TimeUnit.HOURS); } sec += TimeUnit.SECONDS.convert(Integer.decode(strings[1]), TimeUnit.MINUTES); sec += TimeUnit.SECONDS.convert(Integer.decode(strings[2].substring(0, 2)), TimeUnit.SECONDS); return sec; } catch (NumberFormatException e) { return -1; } }  }
ModelUtil { public static int parseDuration(String dur) { if (TextUtils.isEmpty(dur)) { return -1; } String[] strings = dur.split(":"); if (strings.length != 3) { return -1; } try { int sec = 0; if (!TextUtils.isEmpty(strings[0])) { sec += TimeUnit.SECONDS.convert(Integer.decode(strings[0]), TimeUnit.HOURS); } sec += TimeUnit.SECONDS.convert(Integer.decode(strings[1]), TimeUnit.MINUTES); sec += TimeUnit.SECONDS.convert(Integer.decode(strings[2].substring(0, 2)), TimeUnit.SECONDS); return sec; } catch (NumberFormatException e) { return -1; } }  static Folder parseDevice(String authority, Device device); static Folder parseFolder(String authority, String device, Container c); static Artist parseArtist(String authority, String device,MusicArtist ma); static Album parseAlbum(String authority, String device,MusicAlbum ma); static Track parseSong(String authority, String device, MusicTrack mt); static int parseDuration(String dur); }
ModelUtil { public static int parseDuration(String dur) { if (TextUtils.isEmpty(dur)) { return -1; } String[] strings = dur.split(":"); if (strings.length != 3) { return -1; } try { int sec = 0; if (!TextUtils.isEmpty(strings[0])) { sec += TimeUnit.SECONDS.convert(Integer.decode(strings[0]), TimeUnit.HOURS); } sec += TimeUnit.SECONDS.convert(Integer.decode(strings[1]), TimeUnit.MINUTES); sec += TimeUnit.SECONDS.convert(Integer.decode(strings[2].substring(0, 2)), TimeUnit.SECONDS); return sec; } catch (NumberFormatException e) { return -1; } }  static Folder parseDevice(String authority, Device device); static Folder parseFolder(String authority, String device, Container c); static Artist parseArtist(String authority, String device,MusicArtist ma); static Album parseAlbum(String authority, String device,MusicAlbum ma); static Track parseSong(String authority, String device, MusicTrack mt); static int parseDuration(String dur);  }