Here you can find the source of toMillis(String timeUnitString, String timeValue)
Parameter | Description |
---|---|
timeUnitString | the time unit string to convert, such as DAYS or SECONDS |
timeValue | the time value to convert to milliseconds |
public static long toMillis(String timeUnitString, String timeValue)
//package com.java2s; /**/*from ww w . j ava 2 s. c om*/ * Copyright (C) 2014-2015 LinkedIn Corp. (pinot-core@linkedin.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; public class Main { private static final Map<String, TimeUnit> TIME_UNIT_MAP = new HashMap<>(); /** * Converts timeValue in timeUnitString to milliseconds * @param timeUnitString the time unit string to convert, such as DAYS or SECONDS * @param timeValue the time value to convert to milliseconds * @return corresponding value in milliseconds or LONG.MIN_VALUE if timeUnitString is invalid * Returning LONG.MIN_VALUE gives consistent beahvior with the java library */ public static long toMillis(String timeUnitString, String timeValue) { TimeUnit timeUnit = timeUnitFromString(timeUnitString); return (timeUnit == null) ? Long.MIN_VALUE : timeUnit.toMillis(Long.parseLong(timeValue)); } /** * Turns a time unit string into a TimeUnit, ignoring case. * * @param timeUnitString The time unit string to convert, such as DAYS or SECONDS. * @return The corresponding time unit or null if it doesn't exist */ public static TimeUnit timeUnitFromString(String timeUnitString) { if (timeUnitString == null) { return null; } else { return TIME_UNIT_MAP.get(timeUnitString.toUpperCase()); } } }