LangOps { public static int parseSize(String size) { return parseSize(size, null); } private  LangOps(); static BinaryOperator<T> throwingMerger(); @SuppressWarnings("unchecked") static Map<K, V> arrayToMap(Object... arrays); @SuppressWarnings("unchecked") static Map<K, V> kvArrayToMap(K[] keys, V[] values); static Map<K, V> toMap(List<V> data, Function<V, K> keyExtractor); static Object[] toArray(Map<?, ?> map); @SuppressWarnings("unchecked") static R[] toArray(List<T> list, Function<? super T, ? extends R> mapper); static Map<Long, R> generateMap(Long count, Function<Long, ? extends R> mapper); static List<R> generateList(int count, Function<Integer, ? extends R> mapper); static List<R> generateList(Long count, Function<Long, ? extends R> mapper); static void splitTaskAndConsume(List<T> taskList, int taskSize, Consumer<List<T>> subTaskDataConsumer, boolean parallel); static void splitTaskAndConsume(List<T> taskList, int taskSize, BiConsumer<List<T>, Integer> subTaskDataConsumer); static void splitTaskAndConsume(List<T> taskList, int taskSize, BiConsumer<List<T>, Integer> subTaskDataConsumer, boolean parallel); static void timeIt(String tag, Integer times, Closure closure); static void ntimesRun(Integer times, Closure closure); static void ntimesRun(Integer times, Consumer<Integer> consumer); static void ntimesRun(String printTimeTag, Integer times, Closure closure); static void ntimesRun(String printTimeTag, Integer times, Consumer<Integer> consumer); static List<R> ntimesMap(Integer times, Function<Integer, R> mapper); static BigDecimal sumBigDecimal(List<T> datas, Function<T, BigDecimal> mapper); @SuppressWarnings("unchecked") static Map<K, List<T>> groupByProperty(List<T> datas, String propName); @SuppressWarnings("unchecked") static Map<K, List<V>> groupByProperty(List<T> datas, String keyProperty, String valueProperty); static Map<K, List<T>> groupBy(List<T> datas, Function<? super T, ? extends K> keyer); static Map<K, List<V>> groupBy(List<T> datas, Function<? super T, ? extends K> keyer, Function<? super T, ? extends V> valuer); static int parseSize(String size); static int parseSize(String size, Integer def); static long timeToSeconds(String time, long def); static long timeToMills(String time, long def); static long timeToMinutes(String time, long def); static long parseTime(String time, long def, BiFunction<Integer, TimeUnit, Long> convert); static Pair<Integer, TimeUnit> parseTimeUnit(String time); static Color parseColor(String color); @SafeVarargs static List<T> asList(T...values);  }
@Test public void testParseSize(){ int size = LangOps.parseSize("1kb"); assertThat(size).isEqualTo(1024); size = LangOps.parseSize("1mb"); assertThat(size).isEqualTo(1024*1024); size = LangOps.parseSize("1GB"); assertThat(size).isEqualTo(1024*1024*1024); size = LangOps.parseSize("1k"); assertThat(size).isEqualTo(1024); size = LangOps.parseSize("1M"); assertThat(size).isEqualTo(1024*1024); size = LangOps.parseSize("1g"); assertThat(size).isEqualTo(1024*1024*1024); }