LangOps { public static Pair<Integer, TimeUnit> parseTimeUnit(String time) { time = Objects.requireNonNull(time).toLowerCase(); TimeUnit timeUnit = null; int unitLength = 1; int times = 1; if (time.endsWith("mis")) { timeUnit = TimeUnit.MILLISECONDS; unitLength = 3; }else if (time.endsWith("mcs")) { timeUnit = TimeUnit.MICROSECONDS; unitLength = 3; }else if (time.endsWith("s")) { timeUnit = TimeUnit.SECONDS; }else if (time.endsWith("m")) { timeUnit = TimeUnit.MINUTES; }else if (time.endsWith("h")) { timeUnit = TimeUnit.HOURS; }else if (time.endsWith("d")) { timeUnit = TimeUnit.DAYS; }else if (time.endsWith("month")) { timeUnit = TimeUnit.DAYS; times = 30; }else if (time.endsWith("y")) { timeUnit = TimeUnit.DAYS; times = 365; }else{ unitLength = 0; timeUnit = TimeUnit.SECONDS; } int duration = Integer.valueOf(time.substring(0, time.length() - unitLength)) * times; return Pair.of(duration, timeUnit); } 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 testParseTimeUnit(){ Pair<Integer, TimeUnit> tu = LangOps.parseTimeUnit("11mis"); assertThat(tu.getLeft()).isEqualTo(11); assertThat(tu.getRight()).isEqualTo(TimeUnit.MILLISECONDS); tu = LangOps.parseTimeUnit("11s"); assertThat(tu.getLeft()).isEqualTo(11); assertThat(tu.getRight()).isEqualTo(TimeUnit.SECONDS); tu = LangOps.parseTimeUnit("11m"); assertThat(tu.getLeft()).isEqualTo(11); assertThat(tu.getRight()).isEqualTo(TimeUnit.MINUTES); tu = LangOps.parseTimeUnit("101h"); assertThat(tu.getLeft()).isEqualTo(101); assertThat(tu.getRight()).isEqualTo(TimeUnit.HOURS); tu = LangOps.parseTimeUnit("11d"); assertThat(tu.getLeft()).isEqualTo(11); assertThat(tu.getRight()).isEqualTo(TimeUnit.DAYS); }