WearUtil { public static Set<String> explodeSet(String joined, String separator) { String[] items = joined.split("\\Q"+separator+"\\E"); Set<String> set = new HashSet<>(); for (String item : items) { final String itemToAdd = item.trim(); if (itemToAdd.length() > 0) { set.add(itemToAdd); } } return set; }  static String dateTimeText(long timeInMs); static long timestamp(); static long msSince(long when); static long msTill(long when); static synchronized boolean isBelowRateLimit(String named, int onceForSeconds); static PowerManager.WakeLock getWakeLock(final String name, int millis); static void releaseWakeLock(PowerManager.WakeLock wl); static void startActivity(Class c); static Intent getStartActivityIntent(Class c); static void threadSleep(long millis); static String joinSet(Set<String> set, String separator); static Set<String> explodeSet(String joined, String separator); static DataMap bundleToDataMap(Bundle bundle);  }
@Test public void explodeSetTest() { String serializedSet = "second-elem:element1:3rd"; Set<String> set = WearUtil.explodeSet(serializedSet, ":"); assertThat(set.size(), is(3)); assertTrue(set.contains("element1")); assertTrue(set.contains("second-elem")); assertTrue(set.contains("3rd")); }
@Test public void explodeSetEmptyElemsTest() { String serializedSet = ",,,,real,,,another,,,"; Set<String> set = WearUtil.explodeSet(serializedSet, ","); assertThat(set.size(), is(2)); assertThat(true, is(set.contains("real"))); assertThat(true, is(set.contains("another"))); }